aboutsummaryrefslogtreecommitdiff
path: root/cmd
diff options
context:
space:
mode:
authorRyo Nihei <nihei.dev@gmail.com>2021-12-12 18:03:06 +0900
committerRyo Nihei <nihei.dev@gmail.com>2021-12-12 18:03:06 +0900
commita630029b6cd4a1e61025f6c0a40e198b90802946 (patch)
treee95f4d137a68ef44f1893e399c4011682c5f793c /cmd
parentAdd tests of compiler/parser package (diff)
downloadtre-a630029b6cd4a1e61025f6c0a40e198b90802946.tar.gz
tre-a630029b6cd4a1e61025f6c0a40e198b90802946.tar.xz
Remove --lex-spec option from maleeni-compile command
Diffstat (limited to 'cmd')
-rw-r--r--cmd/maleeni/compile.go14
1 files changed, 10 insertions, 4 deletions
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)
}