diff options
author | Ryo Nihei <nihei.dev@gmail.com> | 2021-08-09 01:51:41 +0900 |
---|---|---|
committer | Ryo Nihei <nihei.dev@gmail.com> | 2021-08-15 20:43:02 +0900 |
commit | 00f8b091a9f1eb3ed0348900784be07c326c0dc1 (patch) | |
tree | 5bec55d7fd4c49f01e06a76c50c9949f7f11ca32 /cmd/vartan/compile.go | |
parent | Update CHANGELOG (diff) | |
download | urubu-00f8b091a9f1eb3ed0348900784be07c326c0dc1.tar.gz urubu-00f8b091a9f1eb3ed0348900784be07c326c0dc1.tar.xz |
Support LALR(1) class
Diffstat (limited to 'cmd/vartan/compile.go')
-rw-r--r-- | cmd/vartan/compile.go | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/cmd/vartan/compile.go b/cmd/vartan/compile.go index f29e972..6fdc6a9 100644 --- a/cmd/vartan/compile.go +++ b/cmd/vartan/compile.go @@ -18,6 +18,7 @@ import ( var compileFlags = struct { grammar *string output *string + class *string }{} func init() { @@ -29,6 +30,7 @@ func init() { } compileFlags.grammar = cmd.Flags().StringP("grammar", "g", "", "grammar file path (default stdin)") compileFlags.output = cmd.Flags().StringP("output", "o", "", "output file path (default stdout)") + compileFlags.class = cmd.Flags().StringP("class", "", "lalr", "LALR or SLR") rootCmd.AddCommand(cmd) } @@ -103,7 +105,19 @@ func runCompile(cmd *cobra.Command, args []string) (retErr error) { descFileName = fmt.Sprintf("%v.desc", strings.TrimSuffix(grmFileName, ".vr")) } - cgram, err := grammar.Compile(gram, grammar.EnableDescription(descFileName)) + opts := []grammar.CompileOption{ + grammar.EnableDescription(descFileName), + } + switch strings.ToLower(*compileFlags.class) { + case "slr": + opts = append(opts, grammar.SpecifyClass(grammar.ClassSLR)) + case "lalr": + opts = append(opts, grammar.SpecifyClass(grammar.ClassLALR)) + default: + return fmt.Errorf("invalid class: %v", *compileFlags.class) + } + + cgram, err := grammar.Compile(gram, opts...) if err != nil { return err } |