Skip to content

Commit b2d295a

Browse files
committed
fix #61: identifiers beginning with numbers
1 parent 2cc1855 commit b2d295a

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

lexer/lexer.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// This will convert the sequence of characters into a sequence of tokens
2+
13
package lexer
24

35
import (
@@ -13,7 +15,7 @@ type Lexer struct {
1315
}
1416

1517
func New(input string) *Lexer {
16-
l := &Lexer{input: []rune(input)}
18+
l := &Lexer{input: []rune(input), line: 1}
1719
l.readChar()
1820
return l
1921
}
@@ -176,6 +178,11 @@ func (l *Lexer) NextToken() token.Token {
176178
tok.Type = token.LookupIdent(tok.Literal)
177179
tok.Line = l.line
178180
return tok
181+
} else if isDigit(l.ch) && isLetter(l.peekChar()) {
182+
tok.Literal = l.readIdentifier()
183+
tok.Type = token.LookupIdent(tok.Literal)
184+
tok.Line = l.line
185+
return tok
179186
} else if isDigit(l.ch) {
180187
tok = l.readDecimal()
181188
return tok

0 commit comments

Comments
 (0)