Skip to content

Commit 2973d24

Browse files
authored
Update test badge
split: 39dd7c399e46a9a22490c061a2c91d3ef1579af6
1 parent d03f489 commit 2973d24

3 files changed

Lines changed: 36 additions & 20 deletions

File tree

Lexer/Scanner/AssignmentScanner.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,15 @@ class AssignmentScanner implements ScannerInterface
1414
{
1515
public function scan(State $state)
1616
{
17-
return $state->scanToken(
17+
foreach ($state->scanToken(
1818
AssignmentToken::class,
1919
'&(?<name>[a-zA-Z_][a-zA-Z0-9\-_]*)'
20-
);
20+
) as $token) {
21+
yield $token;
22+
23+
foreach ($state->scan(AttributeScanner::class, ['allow_name' => false]) as $attributeToken) {
24+
yield $attributeToken;
25+
}
26+
}
2127
}
2228
}

Lexer/Scanner/AttributeScanner.php

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -120,13 +120,15 @@ private function getAttributeValue(Reader $reader, array $chars = null)
120120
return $expression;
121121
}
122122

123-
private function readAttributeValue(Reader $reader, AttributeToken $token)
123+
private function readAttributeValue(Reader $reader, AttributeToken $token, $expression = '')
124124
{
125-
$expression = $this->getAttributeValue($reader);
125+
$expression .= $this->getAttributeValue($reader);
126+
126127
while ($this->isTruncatedExpression($reader, $expression)) {
127128
$this->skipComments($reader);
128129
$expression .= $this->getAttributeValue($reader);
129130
}
131+
130132
$token->setValue($expression);
131133

132134
//Ignore a comma if found
@@ -212,17 +214,25 @@ private function getAttributeToken(State $state)
212214
$token->escape();
213215
$token->check();
214216

215-
if ($variadic = $reader->peekString('...')) {
217+
if ($reader->peekString('...')) {
216218
$token->setIsVariadic(true);
217219
$reader->consume();
218220
}
219221

220222
return $token;
221223
}
222224

223-
private function seedAttributeToken(State $state, AttributeToken $token, $expression)
225+
private function seedAttributeToken(State $state, AttributeToken $token, $expression, array $options)
224226
{
225227
$reader = $state->getReader();
228+
$allowName = isset($options['allow_name']) ? $options['allow_name'] : true;
229+
230+
if (!$allowName) {
231+
$this->readAttributeValue($reader, $token, $expression);
232+
$this->skipComments($reader);
233+
234+
return;
235+
}
226236

227237
$token->setName($expression);
228238

@@ -254,7 +264,7 @@ private function seedAttributeToken(State $state, AttributeToken $token, $expres
254264
}
255265
}
256266

257-
private function scanParenthesesContent(State $state)
267+
private function scanParenthesesContent(State $state, array $options)
258268
{
259269
$reader = $state->getReader();
260270

@@ -265,7 +275,7 @@ private function scanParenthesesContent(State $state)
265275
continue;
266276
}
267277

268-
$this->seedAttributeToken($state, $token, $expression);
278+
$this->seedAttributeToken($state, $token, $expression, $options);
269279

270280
yield $token;
271281

@@ -277,15 +287,15 @@ private function scanParenthesesContent(State $state)
277287
}
278288
}
279289

280-
private function scanParentheses(State $state)
290+
private function scanParentheses(State $state, array $options)
281291
{
282292
$reader = $state->getReader();
283293

284294
if ($reader->peekChar(')')) {
285295
return;
286296
}
287297

288-
foreach ($this->scanParenthesesContent($state) as $token) {
298+
foreach ($this->scanParenthesesContent($state, $options) as $token) {
289299
yield $token;
290300
}
291301

@@ -296,7 +306,7 @@ private function scanParentheses(State $state)
296306
}
297307
}
298308

299-
public function scan(State $state)
309+
public function scan(State $state, array $options = [])
300310
{
301311
$reader = $state->getReader();
302312

@@ -309,7 +319,7 @@ public function scan(State $state)
309319
$reader->consume();
310320
yield $state->endToken($start);
311321

312-
foreach ($this->scanParentheses($state) as $token) {
322+
foreach ($this->scanParentheses($state, $options) as $token) {
313323
yield $token;
314324
}
315325

Lexer/State.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -230,20 +230,20 @@ public function indent($level = null)
230230
* use the `loopScan`-method
231231
*
232232
* @param array|string $scanners the scanners to run
233+
* @param array $options options to be passed for the scanner
233234
*
234235
* @throws LexerException
235236
*
236237
* @return iterable the generator yielding all tokens found
237238
*/
238-
public function scan($scanners)
239+
public function scan($scanners, array $options = [])
239240
{
240241
$scanners = $this->filterScanners($scanners);
241242

242-
foreach ($scanners as $key => $scanner) {
243-
243+
foreach ($scanners as $scanner) {
244244
/** @var ScannerInterface $scanner */
245245
$success = false;
246-
foreach ($scanner->scan($this) as $token) {
246+
foreach ($scanner->scan($this, $options) as $token) {
247247
if (!($token instanceof TokenInterface)) {
248248
$this->throwException(
249249
'Scanner '.get_class($scanner).' generated a result that is not a '.TokenInterface::class
@@ -266,7 +266,7 @@ public function scan($scanners)
266266
* If the second argument is true, it will throw an exception if none of the scanners
267267
* produced any valid tokens. The reading also stops when the end of the input as been reached.
268268
*
269-
* @param $scanners
269+
* @param $scanners
270270
* @param bool $required
271271
*
272272
* @throws LexerException
@@ -345,9 +345,9 @@ public function createToken($className)
345345
* in scanners as you can simply return it's value without having to check for it to be null.
346346
*
347347
*
348-
* @param $className
349-
* @param $pattern
350-
* @param null $modifiers
348+
* @param class-string $className
349+
* @param string $pattern
350+
* @param string|null $modifiers
351351
*
352352
* @return iterable
353353
*/

0 commit comments

Comments
 (0)