diff --git a/tests/token.odin b/tests/token.odin index b8fa11d..8b8d645 100644 --- a/tests/token.odin +++ b/tests/token.odin @@ -88,6 +88,60 @@ plus_token :: proc(t: ^testing.T) { testing.expect_value(t, tokens[0], token.Token{type = .Plus}) } +@(test) +minus_token :: proc(t: ^testing.T) { + tokens := token.lex("-", context.allocator) + defer free_all(context.allocator) + + testing.expect_value(t, len(tokens), 1) + testing.expect_value(t, tokens[0], token.Token{type = .Minus}) +} + +@(test) +bang_token :: proc(t: ^testing.T) { + tokens := token.lex("!", context.allocator) + defer free_all(context.allocator) + + testing.expect_value(t, len(tokens), 1) + testing.expect_value(t, tokens[0], token.Token{type = .Bang}) +} + +@(test) +asterisk_token :: proc(t: ^testing.T) { + tokens := token.lex("*", context.allocator) + defer free_all(context.allocator) + + testing.expect_value(t, len(tokens), 1) + testing.expect_value(t, tokens[0], token.Token{type = .Asterisk}) +} + +@(test) +slash_token :: proc(t: ^testing.T) { + tokens := token.lex("/", context.allocator) + defer free_all(context.allocator) + + testing.expect_value(t, len(tokens), 1) + testing.expect_value(t, tokens[0], token.Token{type = .Slash}) +} + +@(test) +less_than_token :: proc(t: ^testing.T) { + tokens := token.lex("<", context.allocator) + defer free_all(context.allocator) + + testing.expect_value(t, len(tokens), 1) + testing.expect_value(t, tokens[0], token.Token{type = .LessThan}) +} + +@(test) +greater_than_token :: proc(t: ^testing.T) { + tokens := token.lex(">", context.allocator) + defer free_all(context.allocator) + + testing.expect_value(t, len(tokens), 1) + testing.expect_value(t, tokens[0], token.Token{type = .GreaterThan}) +} + @(test) left_parenthesis_token :: proc(t: ^testing.T) { tokens := token.lex("(", context.allocator) diff --git a/token/lexer.odin b/token/lexer.odin index fb67694..5376eec 100644 --- a/token/lexer.odin +++ b/token/lexer.odin @@ -94,6 +94,18 @@ next :: proc(l: ^Lexer, allocator := context.allocator) -> (token: Token, ok: bo case '+': token.type = .Plus ok = true + case '-': + token.type = .Minus + ok = true + case '!': + token.type = .Bang + ok = true + case '*': + token.type = .Asterisk + ok = true + case '/': + token.type = .Slash + ok = true case '(': token.type = .LeftParenthesis ok = true @@ -106,6 +118,12 @@ next :: proc(l: ^Lexer, allocator := context.allocator) -> (token: Token, ok: bo case '}': token.type = .RightBrace ok = true + case '<': + token.type = .LessThan + ok = true + case '>': + token.type = .GreaterThan + ok = true case ',': token.type = .Comma ok = true diff --git a/token/token.odin b/token/token.odin index 5750ca2..eb44adc 100644 --- a/token/token.odin +++ b/token/token.odin @@ -6,8 +6,14 @@ Type :: enum { Assignment, Integer, Plus, + Minus, + Bang, + Asterisk, + Slash, Comma, Semicolon, + LessThan, + GreaterThan, LeftParenthesis, RightParenthesis, LeftBrace,