commit 620e9910e6807c8bf8ab9fcf0a9a982f7cf491c9
parent ecaa14631543e0cca86c1fa7ed0de6babae3c390
Author: bsandro <email@bsandro.tech>
Date: Fri, 1 Jul 2022 00:23:31 +0300
numbers and _ symbol support in identifiers names
Diffstat:
2 files changed, 9 insertions(+), 1 deletion(-)
diff --git a/lexer/lexer.go b/lexer/lexer.go
@@ -111,7 +111,7 @@ func newToken(tokenType token.TokenType, ch byte) token.Token {
func (l *Lexer) readIdentifier() string {
position := l.position
- for isLetter(l.ch) {
+ for isLetter(l.ch) || isDigit(l.ch) || l.ch == '_' {
l.readChar()
}
return l.input[position:l.position]
diff --git a/lexer/lexer_test.go b/lexer/lexer_test.go
@@ -29,6 +29,8 @@ if (5 < 10) {
[1, 2];
{"foo":"bar"};
+
+let myvar_1 = 1;
`
tests := []struct {
@@ -131,6 +133,12 @@ if (5 < 10) {
{token.RCURLY, "}"},
{token.SEMICOLON, ";"},
+ {token.LET, "let"},
+ {token.IDENT, "myvar_1"},
+ {token.ASSIGN, "="},
+ {token.INT, "1"},
+ {token.SEMICOLON, ";"},
+
{token.EOF, ""},
}