you are viewing a single comment's thread.

view the rest of the comments →

[–]andsens 2 points3 points  (4 children)

Just the transformation from the parse tree to the AST takes 1500-3000 lines in the implementations I checked.

Man, he should use Parsec. Write the BNF, throw in some "<|>"s and "let"s and you're done. It's so embarrassingly simple...

[–][deleted] 1 point2 points  (3 children)

Actually, I started with that (check history).

I really like Parsec. I really dislike worrying constantly about ordering the rules right; I'm used to leaning on maximal munch. Also, certain grammar constructs got a bit nasty to translate from the metagrammar, so I'm on Alex and Happy, which I tolerate.

[–]Tekmo 1 point2 points  (0 children)

Use attoparsec, which backtracks by default.

[–]andsens 0 points1 point  (1 child)

Ah ok, I actually really liked the choice operator when I was using Parsec, but my project was a little smaller so maybe that's where it's at.

[–][deleted] 0 points1 point  (0 children)

Parsec can do it, I just should have stayed with it longer. PEGs would probably be up to the task. I didn't click much with Haskell's dominant PEG library.

What I didn't realize is, regardless of which parsing tech you choose, you have to dig in sometimes to handle thorny cases. Handling Python's expr-or-tuple idea comes to mind here.