aboutsummaryrefslogtreecommitdiff
path: root/cli/cmd/lex.go
diff options
context:
space:
mode:
authorRyo Nihei <nihei.dev@gmail.com>2021-04-06 00:01:34 +0900
committerRyo Nihei <nihei.dev@gmail.com>2021-04-06 00:01:34 +0900
commit2b5e3239faf7dd14b18c6704da5d6cacc27844fe (patch)
treeb81e7bcc3701c159cf4af9039f2987e88a2554f6 /cli/cmd/lex.go
parentAdd logical inverse expression (diff)
downloadtre-2b5e3239faf7dd14b18c6704da5d6cacc27844fe.tar.gz
tre-2b5e3239faf7dd14b18c6704da5d6cacc27844fe.tar.xz
Print the result of the lex command in JSON format
* Print the result of the lex command in JSON format. * Print the EOF token.
Diffstat (limited to 'cli/cmd/lex.go')
-rw-r--r--cli/cmd/lex.go11
1 files changed, 5 insertions, 6 deletions
diff --git a/cli/cmd/lex.go b/cli/cmd/lex.go
index 7efc814..14fbc01 100644
--- a/cli/cmd/lex.go
+++ b/cli/cmd/lex.go
@@ -74,15 +74,14 @@ Date time: %v
if err != nil {
return err
}
+ data, err := json.Marshal(tok)
+ if err != nil {
+ fmt.Fprintf(os.Stderr, "failed to marshal a token; token: %v, error: %v\n", tok, err)
+ }
+ fmt.Fprintf(os.Stdout, "%v\n", string(data))
if tok.EOF {
break
}
- if tok.Invalid {
- fmt.Fprintf(os.Stdout, "-: -: ")
- } else {
- fmt.Fprintf(os.Stdout, "%v: %v: ", tok.ID, clspec.Kinds[tok.ID])
- }
- fmt.Fprintf(os.Stdout, "\"%v\"\n", string(tok.Match))
}
return nil