Changing Alex/Happy parser to a megaparsec-based one#401
Conversation
rodrigogribeiro
commented
May 21, 2026
- Added test cases for the parser
- Changing the syntax of ternary expression to usual C syntax, since megaparsec allows backtracking parsers.
de5ff71 to
a686e64
Compare
|
Forgotten semicolon in a class declaration leads to slightly misleading error message: |
|
This parses in a weird way (it's a parse error on main): yields |
It's weird because the same code piece returned: |
I've fixed it by improving the error message locally for signatures in class definitions. Now, it returns: |
a686e64 to
6e54d0b
Compare
|
I think I understand the weird The semicolon is optional so Perhaps we should change the syntax to |
| "lam", | ||
| "type", | ||
| "pragma" | ||
| ] |
There was a problem hiding this comment.
Might be easier to read if they are sorted alphabetically
| [ do | ||
| _ <- symbol "." | ||
| entries <- braces (itemEntryP `sepBy` comma) | ||
| hids <- option [] hidingP | ||
| _ <- semicolon | ||
| return (ImportOnly path (SelectItems entries hids)), |
There was a problem hiding this comment.
This should be abstracted out and named to avoid repetitions and improve readability. Ditto for subsequent 'do's in importP
| _ <- symbol "@" | ||
| lib <- identifier | ||
| _ <- char '.' | ||
| sc |
There was a problem hiding this comment.
why is this needed? doesn't lexeme, hence also identifier consume space?
mbenke
left a comment
There was a problem hiding this comment.
Well done, the suggestions are mostly code golf, feel free to ignore the ones you do not like and keep the ones you do.
The 42() corner case is probably not worth the effort now, but worth keeping in mind when we redesign the syntax.
Once #415 is merged, it will need to be reflected in the new parser.
Exactly!
We could discuss when deciding the language syntax. |
5b1228d to
e21bb99
Compare
merging update cabal Fixing the .gitignore removing unnecessary comments
* Improving error messages in class def parsing * Adding test cases.
Co-authored-by: Marcin Benke <marcin.benke@argot.org>
Co-authored-by: Marcin Benke <marcin.benke@argot.org>
Co-authored-by: Marcin Benke <marcin.benke@argot.org>
Co-authored-by: Marcin Benke <marcin.benke@argot.org>
Co-authored-by: Marcin Benke <marcin.benke@argot.org>
Co-authored-by: Marcin Benke <marcin.benke@argot.org>
Co-authored-by: Marcin Benke <marcin.benke@argot.org>
Co-authored-by: Marcin Benke <marcin.benke@argot.org>
Co-authored-by: Marcin Benke <marcin.benke@argot.org>
Co-authored-by: Marcin Benke <marcin.benke@argot.org>
Co-authored-by: Marcin Benke <marcin.benke@argot.org>
Co-authored-by: Marcin Benke <marcin.benke@argot.org>
Co-authored-by: Marcin Benke <marcin.benke@argot.org>
dc0110d to
b467374
Compare