Turn and and or into keywords

This commit is contained in:
Sofia 2026-03-21 15:58:45 +02:00
parent 8a50965f2e
commit d717718a9c
2 changed files with 9 additions and 5 deletions

View File

@ -652,11 +652,6 @@ impl Parse for BinaryOperator {
fn parse(mut stream: TokenStream) -> Result<Self, TokenStreamError> { fn parse(mut stream: TokenStream) -> Result<Self, TokenStreamError> {
if let Some(token) = stream.next() { if let Some(token) = stream.next() {
match (token, stream.peek()) { 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('='))) => { (Token::Symbol('<'), Some(Token::Symbol('='))) => {
stream.next(); stream.next();
Ok(BinaryOperator::LessThanOrEqual) Ok(BinaryOperator::LessThanOrEqual)
@ -692,6 +687,9 @@ impl Parse for BinaryOperator {
Ok(BinaryOperator::IDiv) 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::LessThan),
(Token::Symbol('>'), _) => Ok(BinaryOperator::GreaterThan), (Token::Symbol('>'), _) => Ok(BinaryOperator::GreaterThan),

View File

@ -30,6 +30,8 @@ pub enum Keyword {
Do, Do,
Break, Break,
GoTo, GoTo,
And,
Or,
} }
impl Keyword { impl Keyword {
@ -56,6 +58,8 @@ impl Keyword {
"while" => Keyword::While, "while" => Keyword::While,
"repeat" => Keyword::Repeat, "repeat" => Keyword::Repeat,
"until" => Keyword::Until, "until" => Keyword::Until,
"and" => Keyword::And,
"or" => Keyword::Or,
_ => None?, _ => None?,
}) })
} }
@ -85,6 +89,8 @@ impl ToString for Keyword {
Keyword::Do => "do", Keyword::Do => "do",
Keyword::Break => "break", Keyword::Break => "break",
Keyword::GoTo => "goto", Keyword::GoTo => "goto",
Keyword::And => "and",
Keyword::Or => "or",
} }
.to_string() .to_string()
} }