lexer: produce true and false tokens

This commit is contained in:
Ryan Chandler 2022-07-21 15:09:00 +01:00
parent 83c65a4251
commit e657d27664
No known key found for this signature in database
GPG Key ID: F113BCADDB3B0CCA
2 changed files with 11 additions and 1 deletions

View File

@ -393,6 +393,8 @@ fn identifier_to_keyword(ident: &str) -> Option<TokenKind> {
"return" => TokenKind::Return,
"static" => TokenKind::Static,
"var" => TokenKind::Var,
"true" | "TRUE" => TokenKind::True,
"false" | "FALSE" => TokenKind::False,
_ => return None,
})
}
@ -445,7 +447,7 @@ mod tests {
#[test]
fn keywords() {
assert_tokens("<?php function if else elseif echo return class extends implements public protected private static", &[
assert_tokens("<?php function if else elseif echo return class extends implements public protected private static null NULL true TRUE false FALSE", &[
open!(),
TokenKind::Function,
TokenKind::If,
@ -460,6 +462,12 @@ mod tests {
TokenKind::Protected,
TokenKind::Private,
TokenKind::Static,
TokenKind::Null,
TokenKind::Null,
TokenKind::True,
TokenKind::True,
TokenKind::False,
TokenKind::False,
]);
}

View File

@ -67,6 +67,8 @@ pub enum TokenKind {
Identifier(String),
Dot,
Null,
True,
False,
If,
Implements,
InlineHtml(String),