-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement stof's feedback for TypesTokenParser and its test
- Loading branch information
Showing
3 changed files
with
86 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,7 +12,6 @@ | |
* Represents a types node. | ||
* | ||
* @author Jeroen Versteeg <[email protected]> | ||
* @see https://github.com/twigphp/Twig/issues/4165 | ||
*/ | ||
#[YieldReady] | ||
class TypesNode extends Node implements NodeCaptureInterface | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,7 +28,6 @@ | |
* {% types {foo: 'int', bar: 'string'} %} | ||
* | ||
* @author Jeroen Versteeg <[email protected]> | ||
* @see https://github.com/twigphp/Twig/issues/4165 | ||
* @internal | ||
*/ | ||
final class TypesTokenParser extends AbstractTokenParser | ||
|
@@ -57,7 +56,7 @@ private function parseSimpleMappingExpression(TokenStream $stream): ArrayExpress | |
$first = true; | ||
while (!$stream->test(Token::PUNCTUATION_TYPE, '}')) { | ||
if (!$first) { | ||
$stream->expect(Token::PUNCTUATION_TYPE, ',', 'A mapping value must be followed by a comma'); | ||
$stream->expect(Token::PUNCTUATION_TYPE, ',', 'A type string must be followed by a comma'); | ||
|
||
// trailing ,? | ||
if ($stream->test(Token::PUNCTUATION_TYPE, '}')) { | ||
|
@@ -69,7 +68,10 @@ private function parseSimpleMappingExpression(TokenStream $stream): ArrayExpress | |
$nameToken = $stream->expect(Token::NAME_TYPE); | ||
$nameExpression = new NameExpression($nameToken->getValue(), $nameToken->getLine()); | ||
|
||
$stream->expect(Token::PUNCTUATION_TYPE, ':', 'A mapping key must be followed by a colon (:)'); | ||
$isOptional = $stream->nextIf(Token::PUNCTUATION_TYPE, '?') !== null; | ||
$nameExpression->setAttribute('is_optional', $isOptional); | ||
|
||
$stream->expect(Token::PUNCTUATION_TYPE, ':', 'A name must be followed by a colon (:)'); | ||
|
||
$valueToken = $stream->expect(Token::STRING_TYPE); | ||
$valueExpression = new ConstantExpression($valueToken->getValue(), $valueToken->getLine()); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters