Skip to content

Commit

Permalink
fixup! feat: add lexer
Browse files Browse the repository at this point in the history
  • Loading branch information
jimlambrt committed Aug 8, 2023
1 parent a05e7c5 commit 6a7d7a7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 16 deletions.
30 changes: 15 additions & 15 deletions token.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,22 +33,22 @@ const (
)

var tokenTypeToString = map[tokenType]string{
unknownToken: "Unknown",
errToken: "Error",
eofToken: "Eof",
whitespaceToken: "Whitespace",
stringToken: "String",
unknownToken: "unknown",
errToken: "err",
eofToken: "eof",
whitespaceToken: "ws",
stringToken: "str",
startLogicalExprToken: "(",
endLogicalExprToken: ")",
greaterThanToken: "Greater Than",
greaterThanOrEqualToken: "Greater Than Or Equal",
lessThanToken: "Less Than",
lessThanOrEqualToken: "Less Than or Equal",
equalToken: "Equal",
notEqualToken: "Not Equal",
containsToken: "Contains",
andToken: "And",
orToken: "Or",
greaterThanToken: "gt",
greaterThanOrEqualToken: "gte",
lessThanToken: "lt",
lessThanOrEqualToken: "lte",
equalToken: "eq",
notEqualToken: "neq",
containsToken: "contains",
andToken: "and",
orToken: "or",
}

// String returns a string of the tokenType and will return "Unknown" for
Expand All @@ -59,6 +59,6 @@ func (t tokenType) String() string {
case true:
return s
default:
return "Unknown"
return tokenTypeToString[unknownToken]
}
}
2 changes: 1 addition & 1 deletion token_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ func Test_lexerString(t *testing.T) {
}
t.Run("unknown-tokenType", func(t *testing.T) {
typ := tokenType(-1)
assert.Equal(t, "Unknown", typ.String())
assert.Equal(t, tokenTypeToString[unknownToken], typ.String())
})
}

0 comments on commit 6a7d7a7

Please sign in to comment.