diff --git a/tests/token.odin b/tests/token.odin index 771a0f1..aabccab 100644 --- a/tests/token.odin +++ b/tests/token.odin @@ -11,16 +11,16 @@ single_token :: proc(t: ^testing.T) { } tests := []Test { - {source = "~", token = {type = .Illegal}}, - {source = "x", token = {type = .Identifier}}, - {source = "=", token = {type = .Assignment}}, - {source = "+", token = {type = .Plus}}, - {source = "(", token = {type = .LeftParenthesis}}, - {source = ")", token = {type = .RightParenthesis}}, - {source = "{", token = {type = .LeftBrace}}, - {source = "}", token = {type = .RightBrace}}, - {source = ",", token = {type = .Comma}}, - {source = ";", token = {type = .Semicolon}}, + {source = "~", token = {type = .Illegal, literal = '~'}}, + {source = "x", token = {type = .Identifier, literal = 'x'}}, + {source = "=", token = {type = .Assignment, literal = '='}}, + {source = "+", token = {type = .Plus, literal = '+'}}, + {source = "(", token = {type = .LeftParenthesis, literal = '('}}, + {source = ")", token = {type = .RightParenthesis, literal = ')'}}, + {source = "{", token = {type = .LeftBrace, literal = '{'}}, + {source = "}", token = {type = .RightBrace, literal = '}'}}, + {source = ",", token = {type = .Comma, literal = ','}}, + {source = ";", token = {type = .Semicolon, literal = ';'}}, } for test in tests { diff --git a/token/parser.odin b/token/parser.odin index a3ee76d..f99112e 100644 --- a/token/parser.odin +++ b/token/parser.odin @@ -45,6 +45,7 @@ next :: proc(p: ^Parser) -> Token { case 'A' ..= 'Z', 'a' ..= 'z', '_': token.type = .Identifier } + token.literal = p.value return token } diff --git a/token/token.odin b/token/token.odin index 1e5549a..c8a08a1 100644 --- a/token/token.odin +++ b/token/token.odin @@ -18,7 +18,10 @@ Type :: enum { } Token :: struct { - type: Type, + type: Type, + literal: union { + u8, + }, } parse :: proc(input: string, allocator := context.allocator) -> [dynamic]Token {