Skip to content

Commit

Permalink
Digits should be allowed in variables, closes #233
Browse files Browse the repository at this point in the history
An identifier can start with a unicode letter or an underscore,
and can contain a unicode letter, an underscore or digits.
  • Loading branch information
odino committed Jun 6, 2019
1 parent aefc172 commit bc7d9d1
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lexer/lexer.go
Expand Up @@ -341,7 +341,7 @@ func (l *Lexer) prevChar(steps int) rune {

func (l *Lexer) readIdentifier() string {
position := l.position
for isLetter(l.ch) {
for isLetter(l.ch) || unicode.IsDigit(l.ch) {
l.readChar()
}
return string(l.input[position:l.position])
Expand Down
6 changes: 6 additions & 0 deletions lexer/lexer_test.go
Expand Up @@ -87,6 +87,9 @@ $111
1_2e1
小明
hello_w0rld
hello1
hello_
`

tests := []struct {
Expand Down Expand Up @@ -308,6 +311,9 @@ $111
{token.NUMBER, "12e1"},
{token.IDENT, "小明"},
{token.ILLEGAL, "❤"},
{token.IDENT, "hello_w0rld"},
{token.IDENT, "hello1"},
{token.IDENT, "hello_"},
{token.EOF, ""},
}

Expand Down

0 comments on commit bc7d9d1

Please sign in to comment.