aboutsummaryrefslogtreecommitdiff
path: root/cmd
diff options
context:
space:
mode:
authorRyo Nihei <nihei.dev@gmail.com>2021-05-11 23:24:11 +0900
committerRyo Nihei <nihei.dev@gmail.com>2021-05-11 23:24:11 +0900
commit6979b9b13409dd56869cc881292a544bd8eea7ba (patch)
tree150438027aaf93e75a4e5d3edb51ea257e7977f5 /cmd
parentFix a text representation of an error token (diff)
downloadtre-6979b9b13409dd56869cc881292a544bd8eea7ba.tar.gz
tre-6979b9b13409dd56869cc881292a544bd8eea7ba.tar.xz
Add --compression-level option to compile command
--compression-level specifies a compression level. The default value is 2.
Diffstat (limited to 'cmd')
-rw-r--r--cmd/maleeni/compile.go10
-rw-r--r--cmd/maleeni/lex.go4
2 files changed, 9 insertions, 5 deletions
diff --git a/cmd/maleeni/compile.go b/cmd/maleeni/compile.go
index 6a5e303..fd24afe 100644
--- a/cmd/maleeni/compile.go
+++ b/cmd/maleeni/compile.go
@@ -15,6 +15,7 @@ import (
var compileFlags = struct {
debug *bool
lexSpec *string
+ compLv *int
output *string
}{}
@@ -27,8 +28,9 @@ func init() {
RunE: runCompile,
}
compileFlags.debug = cmd.Flags().BoolP("debug", "d", false, "enable logging")
- compileFlags.lexSpec = cmd.Flags().StringP("lex-spec", "l", "", "lexical specification file path (default: stdin)")
- compileFlags.output = cmd.Flags().StringP("output", "o", "", "output file path (default: stdout)")
+ compileFlags.lexSpec = cmd.Flags().StringP("lex-spec", "l", "", "lexical specification file path (default stdin)")
+ compileFlags.compLv = cmd.Flags().IntP("compression-level", "c", compiler.CompressionLevelMax, "compression level")
+ compileFlags.output = cmd.Flags().StringP("output", "o", "", "output file path (default stdout)")
rootCmd.AddCommand(cmd)
}
@@ -38,7 +40,9 @@ func runCompile(cmd *cobra.Command, args []string) (retErr error) {
return fmt.Errorf("Cannot read a lexical specification: %w", err)
}
- var opts []compiler.CompilerOption
+ opts := []compiler.CompilerOption{
+ compiler.CompressionLevel(*compileFlags.compLv),
+ }
if *compileFlags.debug {
fileName := "maleeni-compile.log"
f, err := os.OpenFile(fileName, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0644)
diff --git a/cmd/maleeni/lex.go b/cmd/maleeni/lex.go
index c111370..e6eab18 100644
--- a/cmd/maleeni/lex.go
+++ b/cmd/maleeni/lex.go
@@ -30,8 +30,8 @@ As use ` + "`maleeni compile`" + `, you can generate the specification.`,
RunE: runLex,
}
lexFlags.debug = cmd.Flags().BoolP("debug", "d", false, "enable logging")
- lexFlags.source = cmd.Flags().StringP("source", "s", "", "source file path (default: stdin)")
- lexFlags.output = cmd.Flags().StringP("output", "o", "", "output file path (default: stdout)")
+ lexFlags.source = cmd.Flags().StringP("source", "s", "", "source file path (default stdin)")
+ lexFlags.output = cmd.Flags().StringP("output", "o", "", "output file path (default stdout)")
lexFlags.breakOnError = cmd.Flags().BoolP("break-on-error", "b", false, "break lexical analysis with exit status 1 immediately when an error token appears.")
rootCmd.AddCommand(cmd)
}