summaryrefslogtreecommitdiff
path: root/crates/typst-syntax/src/parser.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/typst-syntax/src/parser.rs')
-rw-r--r--crates/typst-syntax/src/parser.rs27
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);