Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot assign from keywords #48

Closed
xsawyerx opened this issue May 24, 2020 · 2 comments · Fixed by #53
Closed

Cannot assign from keywords #48

xsawyerx opened this issue May 24, 2020 · 2 comments · Fixed by #53
Assignees
Labels

Comments

@xsawyerx
Copy link
Owner

chmod 0755, "filename";           # ok
my $foo = chmod 0755, "filename"; # not ok

open my $fh, '<', $filename;           # ok
my $foo = open my $fh, '<', $filename; # not ok
@xsawyerx
Copy link
Owner Author

This is caused because the rule for OpListKeywordExpr (which includes keywords like open, chmod, splice) appears before the ExprAssign so they can't be matched.

I tried different ways of repeating this rule in the table after the ExprAssign. I was able to get these tests to work, but then stuff like while ( my ( $foo, $bar ) = splice @foo, 0, 2 ) {1} would get 3 different types of parsing outputs. :/

@vickenty
Copy link
Collaborator

Right, we need to somehow allow OpListKeywordExpr as an RHS for assignment. This creates a loop in our precedence rules (ExprKwList -> ExprComma -> ExprKwAssign -> ExprAssign -> OpListKeywordExpr -> OpKwList), which creates an ambiguity: ($x = kw $y, $z) can be parsed as either (($x = kw $y), $z) or ($x = (kw ($y, $z))).

I don't know the solution to this yet.

vickenty pushed a commit that referenced this issue May 25, 2020
Parse code like this:
`(sort $a, $b + sort $c, $d)`
`($a, $b = open $b, $c = $d)`

LHS of expressions can not contain named operators (in this case they
bind to the rightmost parameter), but RHS can.

Fixes #48
Fixes #52
xsawyerx pushed a commit that referenced this issue May 27, 2020
Parse code like this:
`(sort $a, $b + sort $c, $d)`
`($a, $b = open $b, $c = $d)`

LHS of expressions can not contain named operators (in this case they
bind to the rightmost parameter), but RHS can.

Fixes #48
Fixes #52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants