From a630029b6cd4a1e61025f6c0a40e198b90802946 Mon Sep 17 00:00:00 2001 From: Ryo Nihei Date: Sun, 12 Dec 2021 18:03:06 +0900 Subject: Remove --lex-spec option from maleeni-compile command --- README.md | 2 +- cmd/maleeni/compile.go | 14 ++++++++++---- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 9c9d4df..805e50c 100644 --- a/README.md +++ b/README.md @@ -51,7 +51,7 @@ Save the above specification to a file in UTF-8. In this explanation, the file n Next, generate a DFA from the lexical specification using `maleeni compile` command. ```sh -$ maleeni compile -l statement.json -o statementc.json +$ maleeni compile statement.json -o statementc.json ``` ### 3. Debug (Optional) diff --git a/cmd/maleeni/compile.go b/cmd/maleeni/compile.go index 21e5058..2fcb8ad 100644 --- a/cmd/maleeni/compile.go +++ b/cmd/maleeni/compile.go @@ -15,7 +15,6 @@ import ( var compileFlags = struct { debug *bool - lexSpec *string compLv *int output *string }{} @@ -25,17 +24,24 @@ func init() { Use: "compile", Short: "Compile a lexical specification into a DFA", Long: `compile takes a lexical specification and generates a DFA accepting the tokens described in the specification.`, - Example: ` cat lexspec.json | maleeni compile > clexspec.json`, + Example: ` Read from/Write to the specified file: + maleeni compile lexspec.json -o clexspec.json + Read from stdin and write to stdout: + cat lexspec.json | maleeni compile`, + Args: cobra.MaximumNArgs(1), RunE: runCompile, } - compileFlags.lexSpec = cmd.Flags().StringP("lex-spec", "l", "", "lexical specification file path (default stdin)") compileFlags.compLv = cmd.Flags().Int("compression-level", compiler.CompressionLevelMax, "compression level") compileFlags.output = cmd.Flags().StringP("output", "o", "", "output file path (default stdout)") rootCmd.AddCommand(cmd) } func runCompile(cmd *cobra.Command, args []string) (retErr error) { - lspec, err := readLexSpec(*compileFlags.lexSpec) + var path string + if len(args) > 0 { + path = args[0] + } + lspec, err := readLexSpec(path) if err != nil { return fmt.Errorf("Cannot read a lexical specification: %w", err) } -- cgit v1.2.3