TheMatten / hask

Funny little Haskell impl
GNU General Public License v3.0
18 stars 0 forks source link

Implement source parser #5

Open TheMatten opened 3 years ago

TheMatten commented 3 years ago

Once #4 is finished, we want to parse it - let's track related problems here:

Boarders commented 3 years ago

I'm quite keen generally on separating lexing from parsing and so wondered if we could do alex + megaparsec. The main difficulty is I'm not sure how you lex Haskell style layout in a pleasing fashion (mostly because I have never tried it, I don't think there is a fundamental limitation). Maybe looking at how GHC does it would help.

TheMatten commented 3 years ago

I'm quite keen generally on separating lexing from parsing and so wondered if we could do alex + megaparsec.

When it comes to lexing, I'm worried about whitespace sensitivity - it doesn't really appear in Haskell98, but does a lot with extensions. It's not a fundamental limitation, but it will make things less nice.

The main difficulty is I'm not sure how you lex Haskell style layout in a pleasing fashion (mostly because I have never tried it, I don't think there is a fundamental limitation)

Looking at GHC's parser to see how they handle indentation vs braces, they seem to manually recognize both cases. https://gitlab.haskell.org/ghc/ghc/-/blob/master/compiler/GHC/Parser.y#L95 sounds horrifying BTW :sweat_smile: Wouldn't we avoid equivalent of shift/reduce conflicts when using combinators? (You just have to replace recursion with fold on list from time to time)

TheMatten commented 3 years ago

I wonder what to do about operator parsing - would there be any issues with parsing source that uses them as list of tokens and using separate phase to turn those into trees? It sounds more efficient and elegant than reordering left-associative tree as done in GHC.

solomon-b commented 3 years ago

What is the advantage of doing a separate lexing step if using parser combinators?

TheMatten commented 3 years ago

Possibly less space for mistakes and no need to handle whitespace in parser I guess - but Haskell is space-sensitive, so I wonder whether it won't be more convenient to do together.

solomon-b commented 3 years ago

Is there anything I can do to get the ball rolling on the parser?

TheMatten commented 3 years ago

Feel free to start - I'm slightly busy ATM, so I didn't really start anything myself. BTW, I'm sort of inclined to try multiple approaches (megaparsec/megaparsec+alex/happy+alex), so I guess you can just pick one and we can later sort it out. Nice thing about doing toy project is that there's no reason to hurry :smile: