Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/influxdata/flux
Browse files Browse the repository at this point in the history
  • Loading branch information
benbjohnson committed Nov 19, 2018
2 parents 787a598 + 6f08d62 commit 2cedded
Show file tree
Hide file tree
Showing 2 changed files with 115 additions and 0 deletions.
54 changes: 54 additions & 0 deletions internal/token/token.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,58 @@ const (
PIPE_RECEIVE
)

func (t Token) String() string {
if t < 0 || int(t) >= len(tokenStrings) {
return "UNKNOWN"
}
return tokenStrings[int(t)]
}

var tokenStrings = []string{
"ILLEGAL",
"EOF",
"COMMENT",
"AND",
"OR",
"NOT",
"EMPTY",
"IN",
"IMPORT",
"PACKAGE",
"RETURN",
"IDENT",
"INT",
"FLOAT",
"STRING",
"REGEX",
"TIME",
"DURATION",
"ADD",
"SUB",
"MUL",
"DIV",
"MOD",
"EQ",
"LT",
"GT",
"LTE",
"GTE",
"NEQ",
"REGEXEQ",
"REGEXNEQ",
"ASSIGN",
"ARROW",
"LPAREN",
"RPAREN",
"LBRACK",
"RBRACK",
"LBRACE",
"RBRACE",
"COMMA",
"DOT",
"COLON",
"PIPE_FORWARD",
"PIPE_RECEIVE",
}

type Pos int
61 changes: 61 additions & 0 deletions internal/token/token_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package token_test

import (
"testing"

"github.com/influxdata/flux/internal/token"
)

func TestToken_String(t *testing.T) {
tokenStrings := map[token.Token]string{
token.ILLEGAL: "ILLEGAL",
token.EOF: "EOF",
token.COMMENT: "COMMENT",
token.AND: "AND",
token.OR: "OR",
token.NOT: "NOT",
token.EMPTY: "EMPTY",
token.IN: "IN",
token.IMPORT: "IMPORT",
token.PACKAGE: "PACKAGE",
token.RETURN: "RETURN",
token.IDENT: "IDENT",
token.INT: "INT",
token.FLOAT: "FLOAT",
token.STRING: "STRING",
token.REGEX: "REGEX",
token.TIME: "TIME",
token.DURATION: "DURATION",
token.ADD: "ADD",
token.SUB: "SUB",
token.MUL: "MUL",
token.DIV: "DIV",
token.MOD: "MOD",
token.EQ: "EQ",
token.LT: "LT",
token.GT: "GT",
token.LTE: "LTE",
token.GTE: "GTE",
token.NEQ: "NEQ",
token.REGEXEQ: "REGEXEQ",
token.REGEXNEQ: "REGEXNEQ",
token.ASSIGN: "ASSIGN",
token.ARROW: "ARROW",
token.LPAREN: "LPAREN",
token.RPAREN: "RPAREN",
token.LBRACK: "LBRACK",
token.RBRACK: "RBRACK",
token.LBRACE: "LBRACE",
token.RBRACE: "RBRACE",
token.COMMA: "COMMA",
token.DOT: "DOT",
token.COLON: "COLON",
token.PIPE_FORWARD: "PIPE_FORWARD",
token.PIPE_RECEIVE: "PIPE_RECEIVE",
}
for tok, s := range tokenStrings {
if got, want := tok.String(), s; got != want {
t.Errorf("unexpected token string got %q want %q", got, want)
}
}
}

0 comments on commit 2cedded

Please sign in to comment.