diff options
author | Ryo Nihei <nihei.dev@gmail.com> | 2021-07-17 17:29:31 +0900 |
---|---|---|
committer | Ryo Nihei <nihei.dev@gmail.com> | 2021-07-17 17:29:31 +0900 |
commit | 2c22c1e193ce8b3abd6f1436457ff92a40646e45 (patch) | |
tree | 2979b4d644e038ae2ec84a201c2557d3db5e1570 /cmd/vartan/compile.go | |
parent | Improve syntax error messages (diff) | |
download | cotia-2c22c1e193ce8b3abd6f1436457ff92a40646e45.tar.gz cotia-2c22c1e193ce8b3abd6f1436457ff92a40646e45.tar.xz |
Detect multiple syntax errors in a single parse
Diffstat (limited to 'cmd/vartan/compile.go')
-rw-r--r-- | cmd/vartan/compile.go | 27 |
1 files changed, 11 insertions, 16 deletions
diff --git a/cmd/vartan/compile.go b/cmd/vartan/compile.go index 3601f00..804bd4f 100644 --- a/cmd/vartan/compile.go +++ b/cmd/vartan/compile.go @@ -54,14 +54,16 @@ func runCompile(cmd *cobra.Command, args []string) (retErr error) { } if retErr != nil { - specErr, ok := retErr.(*verr.SpecError) + specErrs, ok := retErr.(verr.SpecErrors) if ok { - if *compileFlags.grammar != "" { - specErr.FilePath = grmPath - specErr.SourceName = grmPath - } else { - specErr.FilePath = grmPath - specErr.SourceName = "stdin" + for _, err := range specErrs { + if *compileFlags.grammar != "" { + err.FilePath = grmPath + err.SourceName = grmPath + } else { + err.FilePath = grmPath + err.SourceName = "stdin" + } } } fmt.Fprintln(os.Stderr, retErr) @@ -106,24 +108,17 @@ func runCompile(cmd *cobra.Command, args []string) (retErr error) { } func readGrammar(path string) (grm *grammar.Grammar, retErr error) { - defer func() { - err := recover() - specErr, ok := err.(*verr.SpecError) - if ok { - specErr.FilePath = path - retErr = specErr - } - }() - f, err := os.Open(path) if err != nil { return nil, fmt.Errorf("Cannot open the grammar file %s: %w", path, err) } defer f.Close() + ast, err := spec.Parse(f) if err != nil { return nil, err } + return grammar.NewGrammar(ast) } |