added Some and Not

This commit is contained in:
Tristan 2025-05-08 20:51:07 -04:00
parent 6c61db4b57
commit b5ab9f51ff
4 changed files with 9 additions and 1 deletions

View File

@ -248,6 +248,8 @@ impl Lexer {
"sym" => Token::Sym,
"module" => Token::Module,
"import" => Token::Import,
"some" => Token::Some,
"not" => Token::Not,
_ => Token::Identifier(text),
};

View File

@ -46,6 +46,8 @@ pub enum Token {
Sym,
Module,
Import,
Some,
Not,
// Comments
Comment(String),

View File

@ -24,6 +24,8 @@ pub enum Operator {
// Unary
Minus, // For unary negation e.g. -5
Almost, // For unary ~ e.g. ~5
Some, // For unary ? e.g. ?5
Not, // For unary ! e.g. !true
// Binary
Plus, // For addition e.g. 5 + 5

View File

@ -238,11 +238,13 @@ impl Parser {
let operator_token_snapshot = self.current_token().clone();
match operator_token_snapshot {
Token::Minus | Token::Tilde => {
Token::Minus | Token::Tilde | Token::Some | Token::Not => {
self.advance();
let ast_operator = match operator_token_snapshot {
Token::Minus => Operator::Minus,
Token::Tilde => Operator::Almost,
Token::Some => Operator::Some,
Token::Not => Operator::Not,
_ => unreachable!("Lexer should not produce other tokens here if first match is minus/tilde. Checked by matches! macro."),
};