arrays + builtins
This commit is contained in:
@@ -94,6 +94,10 @@ func (l *Lexer) NextToken() token.Token {
|
||||
case '"':
|
||||
tok.Type = token.STRING
|
||||
tok.Literal = l.readString()
|
||||
case '[':
|
||||
tok = newToken(token.LBRACKET, l.ch)
|
||||
case ']':
|
||||
tok = newToken(token.RBRACKET, l.ch)
|
||||
default:
|
||||
if isLetter(l.ch) {
|
||||
tok.Literal = l.readIdentifier()
|
||||
|
||||
@@ -27,6 +27,7 @@ func TestNextToken(t *testing.T) {
|
||||
10 != 9;
|
||||
"foobar"
|
||||
"foo bar"
|
||||
[1, 2];
|
||||
`
|
||||
|
||||
tests := []struct {
|
||||
@@ -117,6 +118,14 @@ func TestNextToken(t *testing.T) {
|
||||
|
||||
{token.STRING, "foobar"},
|
||||
{token.STRING, "foo bar"},
|
||||
|
||||
{token.LBRACKET, "["},
|
||||
{token.INT, "1"},
|
||||
{token.COMMA, ","},
|
||||
{token.INT, "2"},
|
||||
{token.RBRACKET, "]"},
|
||||
{token.SEMICOLON, ";"},
|
||||
|
||||
{token.EOF, ""},
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user