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

Better error handling in grammar #78

Merged
merged 4 commits into from
Mar 23, 2022
Merged

Conversation

tirix
Copy link
Collaborator

@tirix tirix commented Mar 22, 2022

No description provided.

src/diag.rs Outdated
"This token was not declared in any $v or $c statement".into(),
stmt,
*span,
)]),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this not just UnknownToken? It should be an error condition (even though you won't get it unless you try to parse the grammar).

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

UnknownToken already exists with a TokenIndex as parameter, while this version of the diagnostic has a Span.

UnknownCommandToken is currently only used within the commands, because we have no token index there, but just a span. I'm not sure if it might be used elsewhere.

Do you have a better naming (which does not collide with UnknownToken)?

Copy link
Member

@digama0 digama0 Mar 22, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel like something similar would have come up in typesetting comment parsing... EDIT: I'm thinking of UndefinedToken, which comes with a span and the literal token text. The error is used in verify_markup.rs when checking typesetting comments.

Copy link
Collaborator Author

@tirix tirix Mar 22, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good, I think I can refactor to use UndefinedToken instead.
Note/Edit: UndefinedToken is a warning, anyway for $j comments I think maybe warning is actually better suited, since the database and proofs are actually correct.

src/grammar.rs Outdated
@@ -859,8 +866,9 @@ impl Grammar {
stype,
&next_node.with_reduce_vec(reduce_vec),
)
.expect("Double conflict!");
.map_err(|_| Diagnostic::GrammarCantBuild)?; // Double conflict
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
.map_err(|_| Diagnostic::GrammarCantBuild)?; // Double conflict
.map_err(|_| Diagnostic::GrammarCantBuild("Double conflict"))?;

It's a shame to lose these comments in the output. If it stores a &'static str or Cow<'static, str> then you don't have to go to the trouble of creating an enum for these messages but you can still display them

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, good suggestion. I'll do that.

@tirix tirix merged commit 94db7a9 into metamath:main Mar 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants