mirror of
https://github.com/danog/parser.git
synced 2024-11-27 04:14:55 +01:00
lexer: produce const tokens
This commit is contained in:
parent
86c74223fa
commit
8070a8dc71
@ -479,6 +479,10 @@ impl Lexer {
|
||||
self.col += 1;
|
||||
TokenKind::RightBracket
|
||||
},
|
||||
':' => {
|
||||
self.col += 1;
|
||||
TokenKind::Colon
|
||||
},
|
||||
_ => unimplemented!("<scripting> char: {}, line: {}, col: {}", char, self.line, self.col),
|
||||
};
|
||||
|
||||
@ -518,6 +522,7 @@ fn identifier_to_keyword(ident: &str) -> Option<TokenKind> {
|
||||
"var" => TokenKind::Var,
|
||||
"true" | "TRUE" => TokenKind::True,
|
||||
"false" | "FALSE" => TokenKind::False,
|
||||
"const" => TokenKind::Const,
|
||||
_ => return None,
|
||||
})
|
||||
}
|
||||
@ -570,7 +575,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn keywords() {
|
||||
assert_tokens("<?php function if else elseif echo return class extends implements public protected private static null NULL true TRUE false FALSE use", &[
|
||||
assert_tokens("<?php function if else elseif echo return class extends implements public protected private static null NULL true TRUE false FALSE use const", &[
|
||||
open!(),
|
||||
TokenKind::Function,
|
||||
TokenKind::If,
|
||||
@ -592,6 +597,7 @@ mod tests {
|
||||
TokenKind::False,
|
||||
TokenKind::False,
|
||||
TokenKind::Use,
|
||||
TokenKind::Const,
|
||||
]);
|
||||
}
|
||||
|
||||
|
@ -101,6 +101,7 @@ pub enum TokenKind {
|
||||
Variable(String),
|
||||
FullyQualifiedIdentifier(String),
|
||||
QualifiedIdentifier(String),
|
||||
Colon,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
|
Loading…
Reference in New Issue
Block a user