From a59b9fff93f708d5a35d2bf61c3b21efee71b7e9 Mon Sep 17 00:00:00 2001 From: Laurenz Date: Fri, 27 Jan 2023 12:20:19 +0100 Subject: Scale shorthand brackets --- src/syntax/ast.rs | 4 ++-- src/syntax/parser.rs | 14 ++++++++++---- 2 files changed, 12 insertions(+), 6 deletions(-) (limited to 'src/syntax') diff --git a/src/syntax/ast.rs b/src/syntax/ast.rs index a24b9fa2..64f54e37 100644 --- a/src/syntax/ast.rs +++ b/src/syntax/ast.rs @@ -716,7 +716,7 @@ node! { impl MathDelimited { /// The opening delimiter. - pub fn open(&self) -> MathAtom { + pub fn open(&self) -> Expr { self.0.cast_first_match().unwrap_or_default() } @@ -726,7 +726,7 @@ impl MathDelimited { } /// The closing delimiter. - pub fn close(&self) -> MathAtom { + pub fn close(&self) -> Expr { self.0.cast_last_match().unwrap_or_default() } } diff --git a/src/syntax/parser.rs b/src/syntax/parser.rs index 7eadf94a..d8eeed24 100644 --- a/src/syntax/parser.rs +++ b/src/syntax/parser.rs @@ -252,7 +252,7 @@ fn math_expr_prec(p: &mut Parser, min_prec: usize, stop: SyntaxKind) { } } - SyntaxKind::MathAtom => { + SyntaxKind::MathAtom | SyntaxKind::Shorthand => { if math_class(p.current_text()) == Some(MathClass::Fence) { math_delimited(p, MathClass::Fence) } else if math_class(p.current_text()) == Some(MathClass::Opening) { @@ -264,7 +264,6 @@ fn math_expr_prec(p: &mut Parser, min_prec: usize, stop: SyntaxKind) { SyntaxKind::Linebreak | SyntaxKind::Escape - | SyntaxKind::Shorthand | SyntaxKind::MathAlignPoint | SyntaxKind::Str => p.eat(), @@ -306,12 +305,12 @@ fn math_expr_prec(p: &mut Parser, min_prec: usize, stop: SyntaxKind) { fn math_delimited(p: &mut Parser, stop: MathClass) { let m = p.marker(); - p.assert(SyntaxKind::MathAtom); + p.eat(); let m2 = p.marker(); while !p.eof() && !p.at(SyntaxKind::Dollar) { if math_class(p.current_text()) == Some(stop) { p.wrap(m2, SyntaxKind::Math); - p.assert(SyntaxKind::MathAtom); + p.eat(); p.wrap(m, SyntaxKind::MathDelimited); return; } @@ -341,6 +340,13 @@ fn math_unparen(p: &mut Parser, m: Marker) { } fn math_class(text: &str) -> Option { + match text { + "[|" => return Some(MathClass::Opening), + "|]" => return Some(MathClass::Closing), + "||" => return Some(MathClass::Fence), + _ => {} + } + let mut chars = text.chars(); chars .next() -- cgit v1.2.3