diff options
author | Ryo Nihei <nihei.dev@gmail.com> | 2022-04-02 14:57:49 +0900 |
---|---|---|
committer | Ryo Nihei <nihei.dev@gmail.com> | 2022-04-02 14:59:20 +0900 |
commit | 0636432f9051797b22e5c77722541c47edb312a0 (patch) | |
tree | 55db693194f0e6bdaaf6d3f34f2431dcdf476fea | |
parent | Update README (diff) | |
download | urubu-0636432f9051797b22e5c77722541c47edb312a0.tar.gz urubu-0636432f9051797b22e5c77722541c47edb312a0.tar.xz |
Remove --grammar option from vartan-compile command
-rw-r--r-- | README.md | 2 | ||||
-rw-r--r-- | cmd/vartan/compile.go | 16 |
2 files changed, 10 insertions, 8 deletions
@@ -74,7 +74,7 @@ Save the above grammar to a file in UTF-8. In this explanation, the file name is Next, generate a parsing table using `vartan compile` command. ```sh -$ vartan compile -g expr.vr -o expr.json +$ vartan compile expr.vr -o expr.json 16 conflicts ``` diff --git a/cmd/vartan/compile.go b/cmd/vartan/compile.go index 73cc5e5..9c37b91 100644 --- a/cmd/vartan/compile.go +++ b/cmd/vartan/compile.go @@ -16,19 +16,18 @@ import ( ) var compileFlags = struct { - grammar *string - output *string - class *string + output *string + class *string }{} func init() { cmd := &cobra.Command{ Use: "compile", Short: "Compile a grammar into a parsing table", - Example: ` cat grammar | vartan compile -o grammar.json`, + Example: ` vartan compile grammar.vr -o grammar.json`, + Args: cobra.MaximumNArgs(1), RunE: runCompile, } - 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) @@ -43,7 +42,10 @@ func runCompile(cmd *cobra.Command, args []string) (retErr error) { os.RemoveAll(tmpDirPath) }() - grmPath := *compileFlags.grammar + var grmPath string + if len(args) > 0 { + grmPath = args[0] + } defer func() { panicked := false v := recover() @@ -63,7 +65,7 @@ func runCompile(cmd *cobra.Command, args []string) (retErr error) { specErrs, ok := retErr.(verr.SpecErrors) if ok { for _, err := range specErrs { - if *compileFlags.grammar != "" { + if len(args) > 0 { err.FilePath = grmPath err.SourceName = grmPath } else { |