-
Notifications
You must be signed in to change notification settings - Fork 84
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft: Introduce new %error
handler mode and catch
for resumable parsing
#272
Conversation
God, this was annoying
For context, I proposed bringing this PR into a mergeable state and applying the result to GHC as a GSoC proposal. |
Hi @sgraf812 I went through this issue. https://summer.haskell.org/ideas.html#parse-error-recovery |
Hi Kaustubh, that's great! Perhaps it's good to have a short chat in private to see whether you would actually enjoy working on this project. For example,
|
@sgraf812 It would be great if I could ask a few questions on the scope of this work. Would setting up a chat work for this?And if so, please just let me know how. Thanks. |
I'm a potential gsoc contributor I am interested in this project! I am currently taking a compiler course at my university along with a functional programming course in Haskell. My thesis project revolves around extending the Cool Compiler (a subset of Scala, utilized by Stanford) with LLVM as it's backend and utilizing ANTLR. I have just recently worked with yacc in building a lexer and scala bison (a version of bison) in building a parser for the same language aforementioned. Last year, I was a GSOC contributor for the GNU organization working on adding support for the Hurd OS to the Rust Compiler. Since I am a beginner in both Haskell and have had some experience working with parser generators and defining grammars I think this project would be a good starting point for me. I'd be happy to have a short private chat @sgraf812 to further discuss my background and projects I have worked on to see if this good be a good fit? This is one project I attempted using the E-Graph Library (that might be interesting): |
Hi Alina and Vedant, feel free to reach out to me via mail (Vedant already did so) or via Matrix (@sgraf812:matrix.org). |
Thanks for the update! I wanted to mention that I sent an email with my first rough draft proposal, I was eager to get your feedback if possible on improving the Milestones and Deliverables section, I provided the specifications in the email! |
Superseded by #318.
A drafty PoC serving as motivation for a GSoC proposal; I don't want to see this merged or reviewed for now.
Consider this excerpt from an example (
errormonad-resume.y
):The point of this example is that reporting a parse error (i.e. adding a diagnostic) is independent from aborting a parse (i.e., a fatal error that can't produce a syntax tree). Hence the new
%error
form takes two code blocks: One for the abort handler, the other for the report handler.Additionally, the report handler gets a
resume
continuation that it may call to resume parsing; otherwise it would simply have to abort (TODO: In the current encoding it should perhaps simply beParseM ()
and we call the resumption unconditionally).Where does the parser resume parsing? That is mostly up to the user to specify, through use of the special
catch
terminal. In the example above,catch
occurs before a;
is shifted, so that upon an error during parsing aStmt
, the parser will "unwind" the stack until it finds a situation in whichcatch
can be shifted. After having done that, it will discard input until it finds the next;
so as to resume parsing.The result is that for inputs such as
1++1;1;+
, two errors (and a partial syntax tree) can be reported: One at the second+
and the other at the third.I've already tried to apply this patch to GHC; it seems to work: See https://gitlab.haskell.org/ghc/ghc/-/merge_requests/11990 for a worked example.