aboutsummaryrefslogtreecommitdiff
path: root/cli/cmd/lex.go
diff options
context:
space:
mode:
authorRyo Nihei <nihei.dev@gmail.com>2021-05-08 17:32:12 +0900
committerRyo Nihei <nihei.dev@gmail.com>2021-05-08 17:39:18 +0900
commit3ab9be08993009f8a2d90b15c3458a97f4152bd9 (patch)
treec67371d87d3c4ea55ada23b5f83a0e3bcb4fc459 /cli/cmd/lex.go
parentAdd CLI options (diff)
downloadtre-3ab9be08993009f8a2d90b15c3458a97f4152bd9.tar.gz
tre-3ab9be08993009f8a2d90b15c3458a97f4152bd9.tar.xz
Add --break-on-error option to lex command
As you use --break-on-error option, break lexical analysis with exit status 1 immediately when an error token appears.
Diffstat (limited to 'cli/cmd/lex.go')
-rw-r--r--cli/cmd/lex.go11
1 files changed, 8 insertions, 3 deletions
diff --git a/cli/cmd/lex.go b/cli/cmd/lex.go
index f47f503..3a9059f 100644
--- a/cli/cmd/lex.go
+++ b/cli/cmd/lex.go
@@ -13,9 +13,10 @@ import (
)
var lexFlags = struct {
- debug *bool
- source *string
- output *string
+ debug *bool
+ source *string
+ output *string
+ breakOnError *bool
}{}
func init() {
@@ -31,6 +32,7 @@ As use ` + "`maleeni compile`" + `, you can generate the specification.`,
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.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)
}
@@ -98,6 +100,9 @@ Date time: %v
if err != nil {
return fmt.Errorf("failed to marshal a token; token: %v, error: %v\n", tok, err)
}
+ if tok.Invalid && *lexFlags.breakOnError {
+ return fmt.Errorf("detected an error token: %v", string(data))
+ }
fmt.Fprintf(w, "%v\n", string(data))
if tok.EOF {
break