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

No backtracking error, extend the choice operator with `\`. #30

Open
ptal opened this Issue Jul 31, 2014 · 1 comment

Comments

Projects
None yet
1 participant
@ptal
Owner

ptal commented Jul 31, 2014

We are sometimes sure that if a rule fails, the program can't be correct. It often happens after a specific keyword has been encountered. For example in Rust, a let must be followed by a declaration:

let-decl = "let" decl ";"

If we parse the "let" but that decl fail, it's useless to backtrack and can put a context-sensitive message here:

let-decl = 
    "let" decl ";"
  \ "let" decl !";" { "A let declaration must be terminated by a semi-colon." } 
  \ "let" .* { "A let must be followed by a declaration." }

We use the \ character because it's a bit like the dual of the choice: if the rule succeed it will fail (instead of succeed).

@ptal ptal added the grammar label Jul 31, 2014

@ptal ptal modified the milestone: Static analysis and misc. Jul 28, 2016

ptal referenced this issue Jul 30, 2016

@ptal

This comment has been minimized.

Show comment
Hide comment
@ptal

ptal Aug 1, 2016

Owner

This approach is different from existing error reporting mechanism, it leaves the user to report himself the error (which is often desirable in compiler—for better error messages) instead of trying to generate automatically all the errors. Note that we still generate errors if the user didn't specify anything so it lets the user free to improve the grammar later.

Owner

ptal commented Aug 1, 2016

This approach is different from existing error reporting mechanism, it leaves the user to report himself the error (which is often desirable in compiler—for better error messages) instead of trying to generate automatically all the errors. Note that we still generate errors if the user didn't specify anything so it lets the user free to improve the grammar later.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment