Add support for the 'while' keyword

This commit is contained in:
2025-11-25 00:49:12 -07:00
parent dd433e1746
commit 31ca798e55
6 changed files with 202 additions and 8 deletions

View File

@@ -409,6 +409,7 @@ impl Tokenizer {
"device" if next_ws!() => keyword!(Device),
"loop" if next_ws!() => keyword!(Loop),
"break" if next_ws!() => keyword!(Break),
"while" if next_ws!() => keyword!(While),
// boolean literals
"true" if next_ws!() => {
@@ -886,4 +887,39 @@ mod tests {
Ok(())
}
#[test]
fn test_compact_syntax() -> Result<()> {
let mut tokenizer = Tokenizer::from(String::from("if(true) while(false)"));
// if(true)
assert_eq!(
tokenizer.next_token()?.unwrap().token_type,
TokenType::Keyword(Keyword::If)
);
assert_eq!(
tokenizer.next_token()?.unwrap().token_type,
TokenType::Symbol(Symbol::LParen)
);
assert_eq!(
tokenizer.next_token()?.unwrap().token_type,
TokenType::Boolean(true)
);
assert_eq!(
tokenizer.next_token()?.unwrap().token_type,
TokenType::Symbol(Symbol::RParen)
);
// while(false)
assert_eq!(
tokenizer.next_token()?.unwrap().token_type,
TokenType::Keyword(Keyword::While)
);
assert_eq!(
tokenizer.next_token()?.unwrap().token_type,
TokenType::Symbol(Symbol::LParen)
);
Ok(())
}
}

View File

@@ -228,4 +228,6 @@ pub enum Keyword {
Loop,
/// Represents the `break` keyword
Break,
/// Represents the `while` keyword
While,
}