Repository navigation
Parse the PHP 8.5 pipe operator and (void) cast in php8 - #37
Merged
Merged
Conversation
$value |> trim(...) and (void) foo(); were syntax errors. The pipe is a new ExprBinaryPipe node at PHP 8.5's precedence - looser than concatenation, tighter than comparison - and left-associative. The (void) cast is a new ExprCastVoid node; as in PHP it is only allowed as a statement or a for expression, not as a value. T_PIPE and T_VOID_CAST are appended to the token list.
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Two PHP 8.5 syntaxes the php8 grammar rejected, found by parsing every rector-src test fixture:
$slug = $title |> trim(...) |> strtolower(...);(void)cast(void) $repository->save($entity);Mirrors
zend_language_parser.y/zend_language_scanner.lof PHP-8.5:Pipe
|>lexes to the newT_PIPEexpr T_PIPE expr,%left T_PIPEbetween comparison and concatenation, as in php-src -$a . $b |> f(...) === 'x'parses as(($a . $b) |> f(...)) === 'x'ast.ExprBinaryPipe{Left, OpTkn, Right}(void)cast(void)(any case, inner whitespace) lexes to the newT_VOID_CASTT_VOID_CAST expr ';'and as aforloop expression, like php-src;$x = (void) f();stays a syntax errorast.ExprCastVoid{CastTkn, Expr}, wrapped in the usualStmtExpressionBoth nodes are wired through the
Visitorinterface,visitor.Null, traverser, printer, formatter and dumper.T_PIPEandT_VOID_CASTare appended topkg/tokenand the%tokenlist, so existing token IDs do not move. The grammar conflict count is unchanged (3 shift/reduce, 7 reduce/reduce).Regenerated with ragel, latest goyacc and stringer; regenerating the unchanged sources the same way reproduces the committed files byte for byte.
Note for implementers of
ast.Visitor: two methods are added (ExprBinaryPipe,ExprCastVoid); visitors embeddingvisitor.Nullneed no change. Verified downstream: reco builds and its full test suite passes against this branch.Tests: parse shape, left-associativity, precedence, void cast in
for, void cast rejected as a value, print-back round trips, printer and formatter.