diff options
Diffstat (limited to 'cmd/vartan')
-rw-r--r-- | cmd/vartan/compile.go | 20 | ||||
-rw-r--r-- | cmd/vartan/parse.go | 4 | ||||
-rw-r--r-- | cmd/vartan/test.go | 9 |
3 files changed, 12 insertions, 21 deletions
diff --git a/cmd/vartan/compile.go b/cmd/vartan/compile.go index 49e383d..e645366 100644 --- a/cmd/vartan/compile.go +++ b/cmd/vartan/compile.go @@ -10,6 +10,7 @@ import ( verr "github.com/nihei9/vartan/error" "github.com/nihei9/vartan/grammar" spec "github.com/nihei9/vartan/spec/grammar" + "github.com/nihei9/vartan/spec/grammar/parser" "github.com/spf13/cobra" ) @@ -78,17 +79,12 @@ func runCompile(cmd *cobra.Command, args []string) (retErr error) { } } - gram, err := readGrammar(grmPath) + gram, report, err := readGrammar(grmPath) if err != nil { return err } - cgram, report, err := grammar.Compile(gram, grammar.EnableReporting()) - if err != nil { - return err - } - - err = writeCompiledGrammarAndReport(cgram, report, *compileFlags.output) + err = writeCompiledGrammarAndReport(gram, report, *compileFlags.output) if err != nil { return fmt.Errorf("Cannot write an output files: %w", err) } @@ -113,22 +109,22 @@ func runCompile(cmd *cobra.Command, args []string) (retErr error) { return nil } -func readGrammar(path string) (grm *grammar.Grammar, retErr error) { +func readGrammar(path string) (*spec.CompiledGrammar, *spec.Report, error) { f, err := os.Open(path) if err != nil { - return nil, fmt.Errorf("Cannot open the grammar file %s: %w", path, err) + return nil, nil, fmt.Errorf("Cannot open the grammar file %s: %w", path, err) } defer f.Close() - ast, err := spec.Parse(f) + ast, err := parser.Parse(f) if err != nil { - return nil, err + return nil, nil, err } b := grammar.GrammarBuilder{ AST: ast, } - return b.Build() + return b.Build(grammar.EnableReporting()) } // writeCompiledGrammarAndReport writes a compiled grammar and a report to a files located at a specified path. diff --git a/cmd/vartan/parse.go b/cmd/vartan/parse.go index ed35a60..f21a03b 100644 --- a/cmd/vartan/parse.go +++ b/cmd/vartan/parse.go @@ -7,7 +7,7 @@ import ( "os" "strings" - "github.com/nihei9/vartan/driver" + driver "github.com/nihei9/vartan/driver/parser" spec "github.com/nihei9/vartan/spec/grammar" "github.com/nihei9/vartan/tester" "github.com/spf13/cobra" @@ -172,7 +172,7 @@ func writeSyntaxErrorMessage(b *strings.Builder, cgram *spec.CompiledGrammar, sy case tok.Invalid(): fmt.Fprintf(b, "'%v' (<invalid>)", string(tok.Lexeme())) default: - if kind := cgram.ParsingTable.Terminals[tok.TerminalID()]; kind != "" { + if kind := cgram.Syntactic.Terminals[tok.TerminalID()]; kind != "" { fmt.Fprintf(b, "'%v' (%v)", string(tok.Lexeme()), kind) } else { fmt.Fprintf(b, "'%v'", string(tok.Lexeme())) diff --git a/cmd/vartan/test.go b/cmd/vartan/test.go index 50ba8ca..9bd88ff 100644 --- a/cmd/vartan/test.go +++ b/cmd/vartan/test.go @@ -5,7 +5,6 @@ import ( "fmt" "os" - "github.com/nihei9/vartan/grammar" "github.com/nihei9/vartan/tester" "github.com/spf13/cobra" ) @@ -22,14 +21,10 @@ func init() { } func runTest(cmd *cobra.Command, args []string) error { - g, err := readGrammar(args[0]) + gram, _, err := readGrammar(args[0]) if err != nil { return fmt.Errorf("Cannot read a grammar: %w", err) } - cg, _, err := grammar.Compile(g) - if err != nil { - return fmt.Errorf("Cannot read a compiled grammar: %w", err) - } var cs []*tester.TestCaseWithMetadata { @@ -47,7 +42,7 @@ func runTest(cmd *cobra.Command, args []string) error { } t := &tester.Tester{ - Grammar: cg, + Grammar: gram, Cases: cs, } rs := t.Run() |