Skip to content

Commit

Permalink
fix lexer crash (eatonphil#12)
Browse files Browse the repository at this point in the history
* fix lexer crash

* Add recommended change

* Add testing
  • Loading branch information
krischerven authored Apr 16, 2020
1 parent afd6424 commit bce7dd6
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,8 @@ func longestMatch(source string, ic cursor, options []string) string {

cur := ic

for {
for cur.pointer < uint(len(source)) {

value = append(value, strings.ToLower(string(source[cur.pointer]))...)
cur.pointer++

Expand Down
24 changes: 24 additions & 0 deletions lexer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,10 @@ func TestToken_lexString(t *testing.T) {
string bool
value string
}{
{
string: false,
value: "a",
},
{
string: true,
value: "'abc'",
Expand Down Expand Up @@ -165,6 +169,11 @@ func TestToken_lexIdentifier(t *testing.T) {
input string
value string
}{
{
identifier: true,
input: "a",
value: "a",
},
{
identifier: true,
input: "abc",
Expand Down Expand Up @@ -275,6 +284,21 @@ func TestLex(t *testing.T) {
tokens []token
err error
}{
{
input: "select a",
tokens: []token{
{
loc: location{col: 0, line: 0},
value: string(selectKeyword),
kind: keywordKind,
},
{
loc: location{col: 7, line: 0},
value: "a",
kind: identifierKind,
},
},
},
{
input: "select true",
tokens: []token{
Expand Down

0 comments on commit bce7dd6

Please sign in to comment.