Skip to content
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

Switch to Menhir's simplified error handling strategy #10095

Merged
merged 3 commits into from
Jan 6, 2021

Commits on Jan 6, 2021

  1. Switch to Menhir's simplified error handling strategy.

    This involves removing the custom parsing loop in parsing/parse.ml
    and instead using the parsing loop provided by MenhirLib. We use
    Menhir's so-called "simplified" error-handling strategy (which is
    new as of 20201216). This strategy differs from the "legacy"
    strategy in two ways:
    
    * It does not read one token too far (so the custom code in
      parsing/parse.ml can be removed).
    
    * If the current state cannot shift or reduce the error token,
      then it just dies, whereas the legacy strategy would pop an
      item off the stack and continue.
    
    The second point impacts some of the syntax error messages produced
    by the parser. Popping items off the stack meant forgetting part of
    the input that had just been read, and would lead the parser to
    produce messages that did not make sense to the user, because there
    was no way for the user to tell that the message was relative to an
    earlier point in the input. Here is an example:
    
    ```
    $ more foo.ml
    (2 + )
    $ ocamlc -c foo.ml
    File "foo.ml", line 1, characters 5-6:
    1 | (2 + )
             ^
    Error: Syntax error: ')' expected
    File "foo.ml", line 1, characters 0-1:
    1 | (2 + )
        ^
      This '(' might be unmatched
    ```
    
    With the simplified parsing strategy, a simple "Syntax error" message
    is printed. This is arguably better: it may seem less informative,
    but it is actually less wrong and less confusing. It is a better basis
    for producing better syntax error messages in the future.
    fpottier authored and gasche committed Jan 6, 2021
    Configuration menu
    Copy the full SHA
    970dd4e View commit details
    Browse the repository at this point in the history
  2. Pass [--strategy simplified] to Menhir.

    This does not change the behavior of the parser in any way.
    
    This allows us to stop using the incremental API and revert
    to using the traditional (monolithic) API.
    
    Thus, we save a few lines of uninteresting code and are able
    to remove the function [wrap_menhir].
    
    This change could make it easier to switch between Menhir's
    code back-end and table back-end, since they both support
    the monolithic API. (However, at the time of writing, the
    code back-end does not yet support [--strategy simplified].)
    fpottier authored and gasche committed Jan 6, 2021
    Configuration menu
    Copy the full SHA
    d6464e6 View commit details
    Browse the repository at this point in the history
  3. Add a Changes entry.

    fpottier authored and gasche committed Jan 6, 2021
    Configuration menu
    Copy the full SHA
    f3cf6be View commit details
    Browse the repository at this point in the history