diff options
| author | Laurenz <laurmaedje@gmail.com> | 2022-12-09 10:21:11 +0100 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2022-12-09 10:21:11 +0100 |
| commit | cd089b6194c57b2e8dff70efaa7cbd53035f7327 (patch) | |
| tree | f5466a0e2f8633aa609276c0c2794911c7e9252a /src | |
| parent | 495b525694aa5901385f3acad043b4a9f3ebb911 (diff) | |
Align set rule
Diffstat (limited to 'src')
| -rw-r--r-- | src/geom/corners.rs | 15 | ||||
| -rw-r--r-- | src/geom/sides.rs | 15 | ||||
| -rw-r--r-- | src/model/eval.rs | 6 | ||||
| -rw-r--r-- | src/model/library.rs | 6 | ||||
| -rw-r--r-- | src/model/styles.rs | 18 | ||||
| -rw-r--r-- | src/syntax/ast.rs | 14 | ||||
| -rw-r--r-- | src/syntax/highlight.rs | 2 | ||||
| -rw-r--r-- | src/syntax/kind.rs | 8 | ||||
| -rw-r--r-- | src/syntax/parsing.rs | 2 |
9 files changed, 44 insertions, 42 deletions
diff --git a/src/geom/corners.rs b/src/geom/corners.rs index d84160cc..386acbfb 100644 --- a/src/geom/corners.rs +++ b/src/geom/corners.rs @@ -45,16 +45,13 @@ impl<T> Corners<T> { } } - /// Zip two instances into an instance. - pub fn zip<F, V, W>(self, other: Corners<V>, mut f: F) -> Corners<W> - where - F: FnMut(T, V) -> W, - { + /// Zip two instances into one. + pub fn zip<U>(self, other: Corners<U>) -> Corners<(T, U)> { Corners { - top_left: f(self.top_left, other.top_left), - top_right: f(self.top_right, other.top_right), - bottom_right: f(self.bottom_right, other.bottom_right), - bottom_left: f(self.bottom_left, other.bottom_left), + top_left: (self.top_left, other.top_left), + top_right: (self.top_right, other.top_right), + bottom_right: (self.bottom_right, other.bottom_right), + bottom_left: (self.bottom_left, other.bottom_left), } } diff --git a/src/geom/sides.rs b/src/geom/sides.rs index 9b8d9a6b..40327a42 100644 --- a/src/geom/sides.rs +++ b/src/geom/sides.rs @@ -45,16 +45,13 @@ impl<T> Sides<T> { } } - /// Zip two instances into an instance. - pub fn zip<F, V, W>(self, other: Sides<V>, mut f: F) -> Sides<W> - where - F: FnMut(T, V) -> W, - { + /// Zip two instances into one. + pub fn zip<U>(self, other: Sides<U>) -> Sides<(T, U)> { Sides { - left: f(self.left, other.left), - top: f(self.top, other.top), - right: f(self.right, other.right), - bottom: f(self.bottom, other.bottom), + left: (self.left, other.left), + top: (self.top, other.top), + right: (self.right, other.right), + bottom: (self.bottom, other.bottom), } } diff --git a/src/model/eval.rs b/src/model/eval.rs index 0ae8a0b1..53a393c3 100644 --- a/src/model/eval.rs +++ b/src/model/eval.rs @@ -429,7 +429,7 @@ impl Eval for ast::MathNode { Self::Symbol(v) => (vm.items.symbol)(v.get().clone() + ":op".into()), Self::Script(v) => v.eval(vm)?, Self::Frac(v) => v.eval(vm)?, - Self::Align(v) => v.eval(vm)?, + Self::AlignPoint(v) => v.eval(vm)?, Self::Group(v) => v.eval(vm)?, Self::Expr(v) => { if let ast::Expr::Ident(ident) = v { @@ -480,11 +480,11 @@ impl Eval for ast::Frac { } } -impl Eval for ast::Align { +impl Eval for ast::AlignPoint { type Output = Content; fn eval(&self, vm: &mut Vm) -> SourceResult<Self::Output> { - Ok((vm.items.math_align)(self.count())) + Ok((vm.items.math_align_point)(self.count())) } } diff --git a/src/model/library.rs b/src/model/library.rs index 63bd5839..02eb9179 100644 --- a/src/model/library.rs +++ b/src/model/library.rs @@ -74,8 +74,8 @@ pub struct LangItems { fn(base: Content, sub: Option<Content>, sup: Option<Content>) -> Content, /// A fraction in a formula: `x/2`. pub math_frac: fn(num: Content, denom: Content) -> Content, - /// An alignment indicator in a formula: `&`, `&&`. - pub math_align: fn(count: usize) -> Content, + /// An alignment point in a formula: `&`, `&&`. + pub math_align_point: fn(count: usize) -> Content, } impl Debug for LangItems { @@ -107,7 +107,7 @@ impl Hash for LangItems { self.math_atom.hash(state); self.math_script.hash(state); self.math_frac.hash(state); - self.math_align.hash(state); + self.math_align_point.hash(state); } } diff --git a/src/model/styles.rs b/src/model/styles.rs index 37596b8d..b2c328fa 100644 --- a/src/model/styles.rs +++ b/src/model/styles.rs @@ -913,6 +913,14 @@ where } } +impl Fold for Axes<Option<GenAlign>> { + type Output = Axes<GenAlign>; + + fn fold(self, outer: Self::Output) -> Self::Output { + self.zip(outer).map(|(inner, outer)| inner.unwrap_or(outer)) + } +} + impl<T> Fold for Sides<T> where T: Fold, @@ -920,7 +928,7 @@ where type Output = Sides<T::Output>; fn fold(self, outer: Self::Output) -> Self::Output { - self.zip(outer, |inner, outer| inner.fold(outer)) + self.zip(outer).map(|(inner, outer)| inner.fold(outer)) } } @@ -928,7 +936,7 @@ impl Fold for Sides<Option<Rel<Abs>>> { type Output = Sides<Rel<Abs>>; fn fold(self, outer: Self::Output) -> Self::Output { - self.zip(outer, |inner, outer| inner.unwrap_or(outer)) + self.zip(outer).map(|(inner, outer)| inner.unwrap_or(outer)) } } @@ -936,7 +944,7 @@ impl Fold for Sides<Option<Smart<Rel<Length>>>> { type Output = Sides<Smart<Rel<Length>>>; fn fold(self, outer: Self::Output) -> Self::Output { - self.zip(outer, |inner, outer| inner.unwrap_or(outer)) + self.zip(outer).map(|(inner, outer)| inner.unwrap_or(outer)) } } @@ -947,7 +955,7 @@ where type Output = Corners<T::Output>; fn fold(self, outer: Self::Output) -> Self::Output { - self.zip(outer, |inner, outer| inner.fold(outer)) + self.zip(outer).map(|(inner, outer)| inner.fold(outer)) } } @@ -955,7 +963,7 @@ impl Fold for Corners<Option<Rel<Abs>>> { type Output = Corners<Rel<Abs>>; fn fold(self, outer: Self::Output) -> Self::Output { - self.zip(outer, |inner, outer| inner.unwrap_or(outer)) + self.zip(outer).map(|(inner, outer)| inner.unwrap_or(outer)) } } diff --git a/src/syntax/ast.rs b/src/syntax/ast.rs index 3661c156..4db00593 100644 --- a/src/syntax/ast.rs +++ b/src/syntax/ast.rs @@ -453,8 +453,8 @@ pub enum MathNode { Script(Script), /// A fraction: `x/2`. Frac(Frac), - /// An alignment indicator: `&`, `&&`. - Align(Align), + /// An alignment point: `&`, `&&`. + AlignPoint(AlignPoint), /// Grouped mathematical material. Group(Math), /// An expression. @@ -472,7 +472,7 @@ impl AstNode for MathNode { SyntaxKind::Symbol(_) => node.cast().map(Self::Symbol), SyntaxKind::Script => node.cast().map(Self::Script), SyntaxKind::Frac => node.cast().map(Self::Frac), - SyntaxKind::Align => node.cast().map(Self::Align), + SyntaxKind::AlignPoint => node.cast().map(Self::AlignPoint), SyntaxKind::Math => node.cast().map(Self::Group), _ => node.cast().map(Self::Expr), } @@ -488,7 +488,7 @@ impl AstNode for MathNode { Self::Symbol(v) => v.as_untyped(), Self::Script(v) => v.as_untyped(), Self::Frac(v) => v.as_untyped(), - Self::Align(v) => v.as_untyped(), + Self::AlignPoint(v) => v.as_untyped(), Self::Group(v) => v.as_untyped(), Self::Expr(v) => v.as_untyped(), } @@ -558,11 +558,11 @@ impl Frac { } node! { - /// An alignment indicator in a formula: `&`, `&&`. - Align + /// An alignment point in a formula: `&`, `&&`. + AlignPoint } -impl Align { +impl AlignPoint { /// The number of ampersands. pub fn count(&self) -> usize { self.0.children().filter(|n| n.kind() == &SyntaxKind::Amp).count() diff --git a/src/syntax/highlight.rs b/src/syntax/highlight.rs index 3fed905f..f9f35944 100644 --- a/src/syntax/highlight.rs +++ b/src/syntax/highlight.rs @@ -302,7 +302,7 @@ impl Category { SyntaxKind::Atom(_) => None, SyntaxKind::Script => None, SyntaxKind::Frac => None, - SyntaxKind::Align => None, + SyntaxKind::AlignPoint => None, SyntaxKind::Ident(_) => match parent.kind() { SyntaxKind::Markup { .. } diff --git a/src/syntax/kind.rs b/src/syntax/kind.rs index a4eb317b..d5fda7f8 100644 --- a/src/syntax/kind.rs +++ b/src/syntax/kind.rs @@ -179,8 +179,8 @@ pub enum SyntaxKind { Script, /// A fraction in a formula: `x/2`. Frac, - /// An alignment indicator in a formula: `&`, `&&`. - Align, + /// An alignment point in a formula: `&`, `&&`. + AlignPoint, /// An identifier: `it`. Ident(EcoString), @@ -408,7 +408,7 @@ impl SyntaxKind { Self::Atom(_) => "math atom", Self::Script => "script", Self::Frac => "fraction", - Self::Align => "alignment indicator", + Self::AlignPoint => "alignment point", Self::Ident(_) => "identifier", Self::Bool(_) => "boolean", Self::Int(_) => "integer", @@ -528,7 +528,7 @@ impl Hash for SyntaxKind { Self::Atom(c) => c.hash(state), Self::Script => {} Self::Frac => {} - Self::Align => {} + Self::AlignPoint => {} Self::Ident(v) => v.hash(state), Self::Bool(v) => v.hash(state), Self::Int(v) => v.hash(state), diff --git a/src/syntax/parsing.rs b/src/syntax/parsing.rs index 97570950..d751b6aa 100644 --- a/src/syntax/parsing.rs +++ b/src/syntax/parsing.rs @@ -499,7 +499,7 @@ fn math_group(p: &mut Parser, group: Group) { } fn math_align(p: &mut Parser) { - p.perform(SyntaxKind::Align, |p| { + p.perform(SyntaxKind::AlignPoint, |p| { p.assert(SyntaxKind::Amp); while p.eat_if(SyntaxKind::Amp) {} }) |
