From fe402759c03eb93cefc2879e751b8e732891bd3e Mon Sep 17 00:00:00 2001 From: Laurenz Date: Wed, 6 Sep 2023 12:07:37 +0200 Subject: Don't automatically match fences Fixes #306 --- crates/typst-syntax/src/parser.rs | 27 +++++++++------------------ 1 file changed, 9 insertions(+), 18 deletions(-) (limited to 'crates/typst-syntax') diff --git a/crates/typst-syntax/src/parser.rs b/crates/typst-syntax/src/parser.rs index 306ac798..313d5ea3 100644 --- a/crates/typst-syntax/src/parser.rs +++ b/crates/typst-syntax/src/parser.rs @@ -282,7 +282,7 @@ fn math_expr_prec(p: &mut Parser, min_prec: usize, stop: SyntaxKind) { math_class(p.current_text()), None | Some(MathClass::Alphabetic) ); - if !maybe_delimited(p, true) { + if !maybe_delimited(p) { p.eat(); } } @@ -321,7 +321,7 @@ fn math_expr_prec(p: &mut Parser, min_prec: usize, stop: SyntaxKind) { if continuable && min_prec < 3 && p.prev_end() == p.current_start() - && maybe_delimited(p, false) + && maybe_delimited(p) { p.wrap(m, SyntaxKind::Math); } @@ -397,29 +397,20 @@ fn math_expr_prec(p: &mut Parser, min_prec: usize, stop: SyntaxKind) { } } -fn maybe_delimited(p: &mut Parser, allow_fence: bool) -> bool { - if allow_fence && math_class(p.current_text()) == Some(MathClass::Fence) { - math_delimited(p, MathClass::Fence); - true - } else if math_class(p.current_text()) == Some(MathClass::Opening) { - math_delimited(p, MathClass::Closing); - true - } else { - false +fn maybe_delimited(p: &mut Parser) -> bool { + let open = math_class(p.current_text()) == Some(MathClass::Opening); + if open { + math_delimited(p); } + open } -fn math_delimited(p: &mut Parser, stop: MathClass) { +fn math_delimited(p: &mut Parser) { let m = p.marker(); p.eat(); let m2 = p.marker(); while !p.eof() && !p.at(SyntaxKind::Dollar) { - let class = math_class(p.current_text()); - if stop == MathClass::Fence && class == Some(MathClass::Closing) { - break; - } - - if class == Some(stop) { + if math_class(p.current_text()) == Some(MathClass::Closing) { p.wrap(m2, SyntaxKind::Math); p.eat(); p.wrap(m, SyntaxKind::MathDelimited); -- cgit v1.2.3