arrays + builtins

This commit is contained in:
Chuck Smith
2024-01-22 12:47:16 -05:00
parent 6bb06370bb
commit 069b5ba8cf
10 changed files with 364 additions and 5 deletions

View File

@@ -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()

View File

@@ -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, ""},
}