-
Notifications
You must be signed in to change notification settings - Fork 4.4k
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
Display parsing errors in grammar compiler #4287
Display parsing errors in grammar compiler #4287
Conversation
tools/grammars/compiler/converter.go
Outdated
@@ -65,6 +65,9 @@ func (conv *Converter) tmpScopes() map[string]bool { | |||
func (conv *Converter) AddGrammar(source string) error { | |||
repo := conv.Load(source) | |||
if len(repo.Files) == 0 { | |||
if len(repo.Errors) > 0 { | |||
return fmt.Errorf("Parsing error in '%s': %s", source, repo.Errors[0]) | |||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This feels a bit odd to me: "We found no grammar files, but hey, here's an error."
I'm mostly AFK this week so don't have time to dig into this deeper myself, but couldn't we check for errors in the first if
, eg:
if len(repo.Files) == 0 && len(repo.Errors) == 0 {
return fmt.Errorf("source '%s' contains no grammar files", source)
}
... and only return if we really don't find any files or errors and leave the error reporting for the check slightly further down if we do?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, right! That should work.
I'll update the pull request tonight.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done. I also updated the error message in the original post.
b78f398
to
b6b6ef2
Compare
@lildude I think this is ready to be merged 😃 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Display parsing errors in grammar compiler. Fixes #4141.
Here's how the error from #4141 would appear:
/cc @wesinator
Removed template as it doesn't apply.