Skip to content

Commit

Permalink
Fix case
Browse files Browse the repository at this point in the history
  • Loading branch information
eatonphil committed Feb 10, 2021
1 parent 64f51c4 commit bfaada0
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 16 deletions.
20 changes: 10 additions & 10 deletions lexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -476,34 +476,34 @@ type lexer func(string, cursor) (*Token, cursor, bool)
// Token slice, update the cursor and restart the process from the new
// cursor location.
func lex(source string) ([]*Token, error) {
var Tokens []*Token
var tokens []*Token
cur := cursor{}

lex:
for cur.pointer < uint(len(source)) {
lexers := []lexer{lexKeyword, lexSymbol, lexString, lexNumeric, lexIdentifier}
for _, l := range lexers {
if Token, newCursor, ok := l(source, cur); ok {
if token, newCursor, ok := l(source, cur); ok {
cur = newCursor

// Omit nil Tokens for valid, but empty syntax like newlines
if Token != nil {
Tokens = append(Tokens, Token)
// Omit nil tokens for valid, but empty syntax like newlines
if token != nil {
tokens = append(tokens, token)
}

continue lex
}
}

hint := ""
if len(Tokens) > 0 {
hint = " after " + Tokens[len(Tokens)-1].Value
if len(tokens) > 0 {
hint = " after " + tokens[len(tokens)-1].Value
}
for _, t := range Tokens {
for _, t := range tokens {
fmt.Println(t.Value)
}
return nil, fmt.Errorf("Unable to lex Token%s, at %d:%d", hint, cur.loc.Line, cur.loc.Col)
return nil, fmt.Errorf("Unable to lex token%s, at %d:%d", hint, cur.loc.Line, cur.loc.Col)
}

return Tokens, nil
return tokens, nil
}
6 changes: 3 additions & 3 deletions lexer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -501,11 +501,11 @@ func TestLex(t *testing.T) {
}

for _, test := range tests {
Tokens, err := lex(test.input)
tokens, err := lex(test.input)
assert.Equal(t, test.err, err, test.input)
assert.Equal(t, len(test.Tokens), len(Tokens), test.input)
assert.Equal(t, len(test.Tokens), len(tokens), test.input)

for i, tok := range Tokens {
for i, tok := range tokens {
assert.Equal(t, &test.Tokens[i], tok, test.input)
}
}
Expand Down
6 changes: 3 additions & 3 deletions parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,13 @@ func TestParseExpression(t *testing.T) {

for _, test := range tests {
fmt.Println("(Parser) Testing: ", test.source)
Tokens, err := lex(test.source)
tokens, err := lex(test.source)
assert.Nil(t, err)

parser := Parser{}
ast, cursor, ok := parser.parseExpression(Tokens, 0, []Token{}, 0)
ast, cursor, ok := parser.parseExpression(tokens, 0, []Token{}, 0)
assert.True(t, ok, err, test.source)
assert.Equal(t, cursor, uint(len(Tokens)))
assert.Equal(t, cursor, uint(len(tokens)))
assert.Equal(t, ast, test.ast, test.source)
}
}
Expand Down

0 comments on commit bfaada0

Please sign in to comment.