From d717718a9c36b4a96c3b60310b5b943e03692ef2 Mon Sep 17 00:00:00 2001 From: Sofia Date: Sat, 21 Mar 2026 15:58:45 +0200 Subject: [PATCH] Turn and and or into keywords --- src/ast.rs | 8 +++----- src/token_stream/lexer.rs | 6 ++++++ 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/ast.rs b/src/ast.rs index 26f2648..348df1b 100644 --- a/src/ast.rs +++ b/src/ast.rs @@ -652,11 +652,6 @@ impl Parse for BinaryOperator { fn parse(mut stream: TokenStream) -> Result { if let Some(token) = stream.next() { match (token, stream.peek()) { - (Token::Word(word), _) => match word.as_str() { - "and" => Ok(BinaryOperator::And), - "or" => Ok(BinaryOperator::Or), - _ => Err(stream.expected_err("binop")), - }, (Token::Symbol('<'), Some(Token::Symbol('='))) => { stream.next(); Ok(BinaryOperator::LessThanOrEqual) @@ -692,6 +687,9 @@ impl Parse for BinaryOperator { Ok(BinaryOperator::IDiv) } + (Token::Keyword(Keyword::And), _) => Ok(BinaryOperator::And), + (Token::Keyword(Keyword::Or), _) => Ok(BinaryOperator::Or), + (Token::Symbol('<'), _) => Ok(BinaryOperator::LessThan), (Token::Symbol('>'), _) => Ok(BinaryOperator::GreaterThan), diff --git a/src/token_stream/lexer.rs b/src/token_stream/lexer.rs index 1e383e1..69503b9 100644 --- a/src/token_stream/lexer.rs +++ b/src/token_stream/lexer.rs @@ -30,6 +30,8 @@ pub enum Keyword { Do, Break, GoTo, + And, + Or, } impl Keyword { @@ -56,6 +58,8 @@ impl Keyword { "while" => Keyword::While, "repeat" => Keyword::Repeat, "until" => Keyword::Until, + "and" => Keyword::And, + "or" => Keyword::Or, _ => None?, }) } @@ -85,6 +89,8 @@ impl ToString for Keyword { Keyword::Do => "do", Keyword::Break => "break", Keyword::GoTo => "goto", + Keyword::And => "and", + Keyword::Or => "or", } .to_string() }