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

Binary not (!) requires parenthesis #64

Closed xsawyerx closed 4 years ago

xsawyerx commented 4 years ago
! defined $foo    # not ok
!( defined $foo ) # ok
not defined $foo  # ok
xsawyerx commented 4 years ago

The ! is defined as UnaryOp, which means it can only accept one value.

! $foo         # ok
! defined      # ok
! defined $foo # not ok

But it cannot parse more than one argument, even if the second element is an argument to the first element like ! defined $foo where $foo is an argument to defined, rather than an argument to !.

I tried changing it to OpNameNot alternative, but that would mess up the precedence.

!   defined $x && $y == 2 # ( defined($x) or ( $y == 2 ) )
not defined $x && $y == 2 # not ( ( defined($x) && ( $y == 2 ) ) )

When using it as not, it will run everything, then call not on it.

Not sure how to solve it.