This commit is contained in:
Chuck Smith
2024-01-22 20:41:05 -05:00
parent 069b5ba8cf
commit 5536dbeaaa
10 changed files with 394 additions and 0 deletions

View File

@@ -98,6 +98,8 @@ func (l *Lexer) NextToken() token.Token {
tok = newToken(token.LBRACKET, l.ch)
case ']':
tok = newToken(token.RBRACKET, l.ch)
case ':':
tok = newToken(token.COLON, l.ch)
default:
if isLetter(l.ch) {
tok.Literal = l.readIdentifier()

View File

@@ -28,6 +28,7 @@ func TestNextToken(t *testing.T) {
"foobar"
"foo bar"
[1, 2];
{"foo": "bar"}
`
tests := []struct {
@@ -126,6 +127,12 @@ func TestNextToken(t *testing.T) {
{token.RBRACKET, "]"},
{token.SEMICOLON, ";"},
{token.LBRACE, "{"},
{token.STRING, "foo"},
{token.COLON, ":"},
{token.STRING, "bar"},
{token.RBRACE, "}"},
{token.EOF, ""},
}