summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2023-03-14 22:31:05 +0100
committerLaurenz <laurmaedje@gmail.com>2023-03-14 22:31:05 +0100
commite50189cfa75d83ea1b74b1dc2cf1fc9c01f8c825 (patch)
treeb2ed11ec419dfb33e4e93556f11db9ae3c430522
parent2bacbaf2bdf93f5537040bdeecf8d73ec06f7eae (diff)
Allow keywords as fields
-rw-r--r--src/syntax/lexer.rs19
-rw-r--r--tests/typ/compiler/field.typ3
2 files changed, 14 insertions, 8 deletions
diff --git a/src/syntax/lexer.rs b/src/syntax/lexer.rs
index 2d555917..919cce69 100644
--- a/src/syntax/lexer.rs
+++ b/src/syntax/lexer.rs
@@ -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,
diff --git a/tests/typ/compiler/field.typ b/tests/typ/compiler/field.typ
index 342ae75b..49ffca04 100644
--- a/tests/typ/compiler/field.typ
+++ b/tests/typ/compiler/field.typ
@@ -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}