From 42cea3ead12d4f64c03aca2892c37e0f6c8c4c90 Mon Sep 17 00:00:00 2001 From: Ryo Nihei Date: Thu, 22 Jul 2021 02:19:11 +0900 Subject: Write a description file The description file describes a LR(0) item set and conflicts (if any). --- cmd/vartan/compile.go | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'cmd/vartan') diff --git a/cmd/vartan/compile.go b/cmd/vartan/compile.go index 354637b..3753cd0 100644 --- a/cmd/vartan/compile.go +++ b/cmd/vartan/compile.go @@ -6,6 +6,7 @@ import ( "io/ioutil" "os" "path/filepath" + "strings" verr "github.com/nihei9/vartan/error" "github.com/nihei9/vartan/grammar" @@ -94,7 +95,13 @@ func runCompile(cmd *cobra.Command, args []string) (retErr error) { return err } - cgram, err := grammar.Compile(gram) + var descFileName string + { + _, grmFileName := filepath.Split(grmPath) + descFileName = fmt.Sprintf("%v.desc", strings.TrimSuffix(grmFileName, ".vr")) + } + + cgram, err := grammar.Compile(gram, grammar.EnableDescription(descFileName)) if err != nil { return err } @@ -119,8 +126,10 @@ func readGrammar(path string) (grm *grammar.Grammar, retErr error) { return nil, err } - var b grammar.GrammarBuilder - return b.Build(ast) + b := grammar.GrammarBuilder{ + AST: ast, + } + return b.Build() } func writeCompiledGrammar(cgram *spec.CompiledGrammar, path string) error { -- cgit v1.2.3