summaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
authorCarson McManus <dyc3@users.noreply.github.com>2023-12-18 06:33:29 -0500
committerGitHub <noreply@github.com>2023-12-18 12:33:29 +0100
commit754e1788b2c690a5520d34b967cae31fb44726b9 (patch)
treee1a90393e081811d8168404ad4bbdfd8c63ec5e9 /crates
parent08225e42d8748802b11b056964cb7763e7da8135 (diff)
Fix a parser bug causing `x.)` to be treated as a field access (#2962)
Diffstat (limited to 'crates')
-rw-r--r--crates/typst-syntax/src/parser.rs17
1 files changed, 9 insertions, 8 deletions
diff --git a/crates/typst-syntax/src/parser.rs b/crates/typst-syntax/src/parser.rs
index 11bb4e8d..1d8875dd 100644
--- a/crates/typst-syntax/src/parser.rs
+++ b/crates/typst-syntax/src/parser.rs
@@ -4,7 +4,7 @@ use std::ops::Range;
use ecow::{eco_format, EcoString};
use unicode_math_class::MathClass;
-use crate::{ast, is_newline, LexMode, Lexer, SyntaxKind, SyntaxNode};
+use crate::{ast, is_ident, is_newline, LexMode, Lexer, SyntaxKind, SyntaxNode};
/// Parse a source file.
#[tracing::instrument(skip_all)]
@@ -258,13 +258,14 @@ fn math_expr_prec(p: &mut Parser, min_prec: usize, stop: SyntaxKind) {
SyntaxKind::MathIdent => {
continuable = true;
p.eat();
- while p.directly_at(SyntaxKind::Text)
- && p.current_text() == "."
- && matches!(
- p.lexer.clone().next(),
- SyntaxKind::MathIdent | SyntaxKind::Text
- )
- {
+ while p.directly_at(SyntaxKind::Text) && p.current_text() == "." && {
+ let mut copy = p.lexer.clone();
+ let start = copy.cursor();
+ let next = copy.next();
+ let end = copy.cursor();
+ matches!(next, SyntaxKind::MathIdent | SyntaxKind::Text)
+ && is_ident(&p.text[start..end])
+ } {
p.convert(SyntaxKind::Dot);
p.convert(SyntaxKind::Ident);
p.wrap(m, SyntaxKind::FieldAccess);