From 0636432f9051797b22e5c77722541c47edb312a0 Mon Sep 17 00:00:00 2001 From: Ryo Nihei Date: Sat, 2 Apr 2022 14:57:49 +0900 Subject: Remove --grammar option from vartan-compile command --- README.md | 2 +- cmd/vartan/compile.go | 16 +++++++++------- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index bdd6a39..0ce4b94 100644 --- a/README.md +++ b/README.md @@ -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 { -- cgit v1.2.3