mirror of https://github.com/stelzo/typst.git
Fix a parser bug causing `x.)` to be treated as a field access (#2962)
This commit is contained in:
parent
08225e42d8
commit
754e1788b2
|
|
@ -4,7 +4,7 @@ use std::ops::Range;
|
||||||
use ecow::{eco_format, EcoString};
|
use ecow::{eco_format, EcoString};
|
||||||
use unicode_math_class::MathClass;
|
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.
|
/// Parse a source file.
|
||||||
#[tracing::instrument(skip_all)]
|
#[tracing::instrument(skip_all)]
|
||||||
|
|
@ -258,13 +258,14 @@ fn math_expr_prec(p: &mut Parser, min_prec: usize, stop: SyntaxKind) {
|
||||||
SyntaxKind::MathIdent => {
|
SyntaxKind::MathIdent => {
|
||||||
continuable = true;
|
continuable = true;
|
||||||
p.eat();
|
p.eat();
|
||||||
while p.directly_at(SyntaxKind::Text)
|
while p.directly_at(SyntaxKind::Text) && p.current_text() == "." && {
|
||||||
&& p.current_text() == "."
|
let mut copy = p.lexer.clone();
|
||||||
&& matches!(
|
let start = copy.cursor();
|
||||||
p.lexer.clone().next(),
|
let next = copy.next();
|
||||||
SyntaxKind::MathIdent | SyntaxKind::Text
|
let end = copy.cursor();
|
||||||
)
|
matches!(next, SyntaxKind::MathIdent | SyntaxKind::Text)
|
||||||
{
|
&& is_ident(&p.text[start..end])
|
||||||
|
} {
|
||||||
p.convert(SyntaxKind::Dot);
|
p.convert(SyntaxKind::Dot);
|
||||||
p.convert(SyntaxKind::Ident);
|
p.convert(SyntaxKind::Ident);
|
||||||
p.wrap(m, SyntaxKind::FieldAccess);
|
p.wrap(m, SyntaxKind::FieldAccess);
|
||||||
|
|
|
||||||
Binary file not shown.
|
After Width: | Height: | Size: 603 B |
|
|
@ -0,0 +1,6 @@
|
||||||
|
// In this bug, the dot at the end was causing the right parenthesis to be
|
||||||
|
// parsed as an identifier instead of the closing right parenthesis.
|
||||||
|
// Issue: https://github.com/typst/typst/issues/2044
|
||||||
|
|
||||||
|
$floor(phi.alt.)$
|
||||||
|
$floor(phi.alt. )$
|
||||||
Loading…
Reference in New Issue