alex / rply

An attempt to port David Beazley's PLY to RPython, and give it a cooler API.
BSD 3-Clause "New" or "Revised" License
381 stars 60 forks source link

precedence on productions #39

Closed sn6uv closed 9 years ago

sn6uv commented 9 years ago

Is it possible to add precedence directly on productions?

I'm writing a parser for a language that reuses the ! symbol for both factorial (postfix) and negation (prefix). I'd like to be able to resolve the conflict with precedence but it seems like it's only possible to add precedence to tokens.

Example

I want 2 ! 3 to parse as Times[Factorial[2], 3] not Times[2, Not[3]]

refi64 commented 9 years ago

Try using the precedence argument to pg.production. PLY own docs have a good explanation: www.dabeaz.com/ply/ply.html#ply_nn27. Jump to the part about %prec part. It does the same thing as the precedence arg to pg.production.

sn6uv commented 9 years ago

Thanks @kirbyfan64. I've opened #40 to document this feature