mirror of
https://github.com/typst/typst
synced 2025-05-13 12:36:23 +08:00
Allow keywords as fields
This commit is contained in:
parent
2bacbaf2bd
commit
e50189cfa7
@ -479,13 +479,16 @@ impl Lexer<'_> {
|
|||||||
|
|
||||||
fn ident(&mut self, start: usize) -> SyntaxKind {
|
fn ident(&mut self, start: usize) -> SyntaxKind {
|
||||||
self.s.eat_while(is_id_continue);
|
self.s.eat_while(is_id_continue);
|
||||||
match self.s.from(start) {
|
let ident = self.s.from(start);
|
||||||
"none" => SyntaxKind::None,
|
|
||||||
"auto" => SyntaxKind::Auto,
|
let prev = self.s.get(0..start);
|
||||||
"true" => SyntaxKind::Bool,
|
if !prev.ends_with(['.', '@']) || prev.ends_with("..") {
|
||||||
"false" => SyntaxKind::Bool,
|
if let Some(keyword) = keyword(ident) {
|
||||||
id => keyword(id).unwrap_or(SyntaxKind::Ident),
|
return keyword;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SyntaxKind::Ident
|
||||||
}
|
}
|
||||||
|
|
||||||
fn number(&mut self, start: usize, c: char) -> SyntaxKind {
|
fn number(&mut self, start: usize, c: char) -> SyntaxKind {
|
||||||
@ -556,6 +559,10 @@ impl Lexer<'_> {
|
|||||||
/// Try to parse an identifier into a keyword.
|
/// Try to parse an identifier into a keyword.
|
||||||
fn keyword(ident: &str) -> Option<SyntaxKind> {
|
fn keyword(ident: &str) -> Option<SyntaxKind> {
|
||||||
Some(match ident {
|
Some(match ident {
|
||||||
|
"none" => SyntaxKind::None,
|
||||||
|
"auto" => SyntaxKind::Auto,
|
||||||
|
"true" => SyntaxKind::Bool,
|
||||||
|
"false" => SyntaxKind::Bool,
|
||||||
"not" => SyntaxKind::Not,
|
"not" => SyntaxKind::Not,
|
||||||
"and" => SyntaxKind::And,
|
"and" => SyntaxKind::And,
|
||||||
"or" => SyntaxKind::Or,
|
"or" => SyntaxKind::Or,
|
||||||
|
@ -36,6 +36,5 @@
|
|||||||
= A
|
= A
|
||||||
|
|
||||||
---
|
---
|
||||||
// Error: 9 expected identifier
|
// Error: 9-13 cannot access fields on type boolean
|
||||||
// Error: 9 expected semicolon or line break
|
|
||||||
#{false.true}
|
#{false.true}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user