elm-syntax icon indicating copy to clipboard operation
elm-syntax copied to clipboard

Re-implement expression parser using a pratt parser

Open jfmengels opened this issue 2 years ago • 1 comments

Fixes #199.

Reimplements the expression using a Pratt Parser (see explanation https://martin.janiczek.cz/2023/07/03/demystifying-pratt-parsers.html).

This is not completely done, and I imagine the remaining parts will be the trickiest to do. But I'm really happy about the progress (I've been trying for a few weeks but couldn't get it to work until this morning!).

I'm off for a week+ of vacation, so I'll have to pause work on this. If some people have insight about how to do this better, I'd love to hear about. If some want to continue the work, I'd love that too :smile:

TODO

  • [ ] Fix support for negated expressions
  • [ ] Fix support for comments
  • [ ] FIx remaining tests that will identify more broken things
  • [ ] Include LICENSE for dmy/elm-pratt-parser as the project was heavily copied from that.

jfmengels avatar Sep 03 '23 20:09 jfmengels

If you go back one commit from the current state of the branch, i.e this commit https://github.com/stil4m/elm-syntax/pull/207/commits/9126cda3ece73d00512ed46220896bf07bd2b6a5, there is a Test.only on a test around parsing case expressions that doesn't work. IIRC It's because in the following case expression, the - symbols are considered to be the - by the Pratt parser.

case f of
   True -> 1
   False -> 2

I could be wrong about this, but that's what I had figured at some point. I have not been able to find a way to fix it yet.

jfmengels avatar Apr 13 '24 21:04 jfmengels

I usually spread out operators too, and types that are records

jiegillet avatar Jul 08 '24 09:07 jiegillet

BTW: fixes #174

jiegillet avatar Jul 12 '24 12:07 jiegillet