osa1 / parsegen

An LR parser generator, implemented as a proc macro
MIT License
15 stars 0 forks source link

Implement associativity attributes #6

Open osa1 opened 2 years ago

osa1 commented 2 years ago

It's tedious to parse expressions without associativity attributes.

Left associative = reduce in a shift/reduce conflict Right associative = shift in a shift/reduce conflict

I don't like ocamlyacc/menhir/happy style associativity lines before non-terminals/productions. I think we should probably use Rust attribute syntax and annotate productions with the associativity attributes. Examples:

#[assoc(left)]
<e1:Expr> "+" <e2:Expr> => ...

#[assoc(right)]
<e1:Expr> "?" <e2:Expr> ":" <e3:Expr> => ...
osa1 commented 2 years ago

LALRPOP PRs that added precedence and associativity annotations:

We should probably just copy the syntax (and maybe implementation too), but I would prefer avoiding lvl and side argument names. Just #[precedence(2)] #[assoc(left)] should be OK. (Do we need string quotes around 2 and left? I hope not)

See also: