diff options
| author | Laurenz <laurmaedje@gmail.com> | 2023-09-06 12:07:37 +0200 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2023-09-06 12:07:37 +0200 |
| commit | fe402759c03eb93cefc2879e751b8e732891bd3e (patch) | |
| tree | 8e98256cf4f839e72e53836d00a0ecdc7ad4854b /crates | |
| parent | b76e8d5db9bea8fb63e65fe7a54db6bbae1cf842 (diff) | |
Don't automatically match fences
Fixes #306
Diffstat (limited to 'crates')
| -rw-r--r-- | crates/typst-syntax/src/parser.rs | 27 |
1 files changed, 9 insertions, 18 deletions
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); |
