Allow keywords as fields

This commit is contained in:
Laurenz 2023-03-14 22:31:05 +01:00
parent 2bacbaf2bd
commit e50189cfa7
2 changed files with 14 additions and 8 deletions

View File

@ -479,13 +479,16 @@ impl Lexer<'_> {
fn ident(&mut self, start: usize) -> SyntaxKind {
self.s.eat_while(is_id_continue);
match self.s.from(start) {
"none" => SyntaxKind::None,
"auto" => SyntaxKind::Auto,
"true" => SyntaxKind::Bool,
"false" => SyntaxKind::Bool,
id => keyword(id).unwrap_or(SyntaxKind::Ident),
let ident = self.s.from(start);
let prev = self.s.get(0..start);
if !prev.ends_with(['.', '@']) || prev.ends_with("..") {
if let Some(keyword) = keyword(ident) {
return keyword;
}
}
SyntaxKind::Ident
}
fn number(&mut self, start: usize, c: char) -> SyntaxKind {
@ -556,6 +559,10 @@ impl Lexer<'_> {
/// Try to parse an identifier into a keyword.
fn keyword(ident: &str) -> Option<SyntaxKind> {
Some(match ident {
"none" => SyntaxKind::None,
"auto" => SyntaxKind::Auto,
"true" => SyntaxKind::Bool,
"false" => SyntaxKind::Bool,
"not" => SyntaxKind::Not,
"and" => SyntaxKind::And,
"or" => SyntaxKind::Or,

View File

@ -36,6 +36,5 @@
= A
---
// Error: 9 expected identifier
// Error: 9 expected semicolon or line break
// Error: 9-13 cannot access fields on type boolean
#{false.true}