From cdfff5210b0f2951f94f4f18650616f9f3fa17e2 Mon Sep 17 00:00:00 2001 From: Ryan Chandler Date: Sat, 16 Jul 2022 14:29:21 +0100 Subject: [PATCH] lexer: punctuation and math ops --- trunk_lexer/src/lexer.rs | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/trunk_lexer/src/lexer.rs b/trunk_lexer/src/lexer.rs index 8e5a075..57caad6 100644 --- a/trunk_lexer/src/lexer.rs +++ b/trunk_lexer/src/lexer.rs @@ -166,6 +166,14 @@ impl Lexer { identifier_to_keyword(&buffer).unwrap_or(TokenKind::Identifier(buffer)) }, + '{' => TokenKind::LeftBrace, + '}' => TokenKind::RightBrace, + '(' => TokenKind::LeftParen, + ')' => TokenKind::RightParen, + ';' => TokenKind::SemiColon, + '+' => TokenKind::Plus, + '-' => TokenKind::Minus, + '<' => TokenKind::LessThan, _ => unimplemented!(" char: {}", char), }; @@ -180,6 +188,7 @@ impl Lexer { } } +#[allow(dead_code)] fn identifier_to_keyword(ident: &str) -> Option { Some(match ident { "function" => TokenKind::Function, @@ -234,6 +243,28 @@ mod tests { ]); } + #[test] + fn punct() { + assert_tokens("