scala/scala-parser-combinators

Does it bother anybody else that `<~` is lower precedence than `~` and `~>`?

toddobryan opened this issue · 1 comments

This has been freaking me out recently. Given,

a: Parser[A]
b: Parser[B]
c: Parser[C]
d: Parser[D]
a ~ b ~ c ~ d // => Parser[A ~ B ~ C ~ D]
a ~ b ~> c ~ d // => Parser[A ~ C ~ D] (edit: should be Parser[C ~ D])
a ~ b <~ c ~ d // => Parser[A ~ B]

because <~ is lower precedence than ~ and ~>. So you have to add parentheses if you want things to work as you might expect in a left-to-right fashion, i.e.

a ~ (b <~ c) ~ d // => Parser[A ~ B ~ D]

What would people think of adding an alias of ~< for <~, which would have the same precedence as the other two, so

a ~ b ~< c ~ d // => Parser[A ~ B ~ D]

Or maybe I'm the only one who is freaked out/annoyed by this?

Actually, I just realized that the a ~ b ~> c ~ d case would produce Parser[C ~ D], so I guess the fact that <~ is lower precedence but defers to the left makes them work the same way.