From 2b5e3239faf7dd14b18c6704da5d6cacc27844fe Mon Sep 17 00:00:00 2001 From: Ryo Nihei Date: Tue, 6 Apr 2021 00:01:34 +0900 Subject: Print the result of the lex command in JSON format * Print the result of the lex command in JSON format. * Print the EOF token. --- cli/cmd/lex.go | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'cli/cmd') 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 -- cgit v1.2.3