From 2c22c1e193ce8b3abd6f1436457ff92a40646e45 Mon Sep 17 00:00:00 2001 From: Ryo Nihei Date: Sat, 17 Jul 2021 17:29:31 +0900 Subject: Detect multiple syntax errors in a single parse --- cmd/vartan/compile.go | 27 +++++++++++---------------- 1 file changed, 11 insertions(+), 16 deletions(-) (limited to 'cmd/vartan') 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) } -- cgit v1.2.3