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> {
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),

View File

@ -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()
}