Scale shorthand brackets

This commit is contained in:
Laurenz 2023-01-27 12:20:19 +01:00
parent 9d962c5c40
commit a59b9fff93
3 changed files with 14 additions and 8 deletions

View File

@ -584,9 +584,9 @@ impl Eval for ast::MathDelimited {
type Output = Content; type Output = Content;
fn eval(&self, vm: &mut Vm) -> SourceResult<Self::Output> { fn eval(&self, vm: &mut Vm) -> SourceResult<Self::Output> {
let open = self.open().eval(vm)?; let open = self.open().eval(vm)?.display_in_math();
let body = self.body().eval(vm)?; let body = self.body().eval(vm)?;
let close = self.close().eval(vm)?; let close = self.close().eval(vm)?.display_in_math();
Ok((vm.items.math_delimited)(open, body, close)) Ok((vm.items.math_delimited)(open, body, close))
} }
} }

View File

@ -716,7 +716,7 @@ node! {
impl MathDelimited { impl MathDelimited {
/// The opening delimiter. /// The opening delimiter.
pub fn open(&self) -> MathAtom { pub fn open(&self) -> Expr {
self.0.cast_first_match().unwrap_or_default() self.0.cast_first_match().unwrap_or_default()
} }
@ -726,7 +726,7 @@ impl MathDelimited {
} }
/// The closing delimiter. /// The closing delimiter.
pub fn close(&self) -> MathAtom { pub fn close(&self) -> Expr {
self.0.cast_last_match().unwrap_or_default() self.0.cast_last_match().unwrap_or_default()
} }
} }

View File

@ -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) { if math_class(p.current_text()) == Some(MathClass::Fence) {
math_delimited(p, MathClass::Fence) math_delimited(p, MathClass::Fence)
} else if math_class(p.current_text()) == Some(MathClass::Opening) { } 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::Linebreak
| SyntaxKind::Escape | SyntaxKind::Escape
| SyntaxKind::Shorthand
| SyntaxKind::MathAlignPoint | SyntaxKind::MathAlignPoint
| SyntaxKind::Str => p.eat(), | 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) { fn math_delimited(p: &mut Parser, stop: MathClass) {
let m = p.marker(); let m = p.marker();
p.assert(SyntaxKind::MathAtom); p.eat();
let m2 = p.marker(); let m2 = p.marker();
while !p.eof() && !p.at(SyntaxKind::Dollar) { while !p.eof() && !p.at(SyntaxKind::Dollar) {
if math_class(p.current_text()) == Some(stop) { if math_class(p.current_text()) == Some(stop) {
p.wrap(m2, SyntaxKind::Math); p.wrap(m2, SyntaxKind::Math);
p.assert(SyntaxKind::MathAtom); p.eat();
p.wrap(m, SyntaxKind::MathDelimited); p.wrap(m, SyntaxKind::MathDelimited);
return; return;
} }
@ -341,6 +340,13 @@ fn math_unparen(p: &mut Parser, m: Marker) {
} }
fn math_class(text: &str) -> Option<MathClass> { fn math_class(text: &str) -> Option<MathClass> {
match text {
"[|" => return Some(MathClass::Opening),
"|]" => return Some(MathClass::Closing),
"||" => return Some(MathClass::Fence),
_ => {}
}
let mut chars = text.chars(); let mut chars = text.chars();
chars chars
.next() .next()