xsawyerx / guacamole

Guacamole is a parser toolkit for Standard Perl. It provides fully static BNF-based parsing capability to a reasonable subset of Perl.
https://metacpan.org/pod/Guacamole
20 stars 8 forks source link

Cannot assign from keywords #48

Closed xsawyerx closed 4 years ago

xsawyerx commented 4 years ago
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 commented 4 years ago

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 commented 4 years ago

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.