From 37a7afddfaffd44cb9bc013c9506599267e08983 Mon Sep 17 00:00:00 2001 From: Laurenz Date: Thu, 3 Nov 2022 11:44:53 +0100 Subject: Split crates --- src/syntax/ast.rs | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) (limited to 'src/syntax/ast.rs') diff --git a/src/syntax/ast.rs b/src/syntax/ast.rs index ecfa9a5b..06e41fa0 100644 --- a/src/syntax/ast.rs +++ b/src/syntax/ast.rs @@ -55,7 +55,7 @@ node! { impl Markup { /// The children. - pub fn children(&self) -> impl Iterator + '_ { + pub fn children(&self) -> impl DoubleEndedIterator + '_ { self.0.children().filter_map(SyntaxNode::cast) } } @@ -166,7 +166,7 @@ impl Space { } node! { - /// A forced line break. + /// A forced line break: `\`. Linebreak } @@ -414,9 +414,15 @@ node! { impl Math { /// The children. - pub fn children(&self) -> impl Iterator + '_ { + pub fn children(&self) -> impl DoubleEndedIterator + '_ { self.0.children().filter_map(SyntaxNode::cast) } + + /// Whether this is a display-level math formula. + pub fn display(&self) -> bool { + matches!(self.children().next(), Some(MathNode::Space(_))) + && matches!(self.children().last(), Some(MathNode::Space(_))) + } } /// A single piece of a math formula. @@ -424,7 +430,7 @@ impl Math { pub enum MathNode { /// Whitespace. Space(Space), - /// A forced line break. + /// A forced line break: `\`. Linebreak(Linebreak), /// An escape sequence: `\#`, `\u{1F5FA}`. Escape(Escape), @@ -535,7 +541,7 @@ impl Frac { } node! { - /// A math alignment indicator: `&`, `&&`. + /// An alignment indicator in a formula: `&`, `&&`. Align } @@ -736,7 +742,7 @@ node! { impl CodeBlock { /// The list of expressions contained in the block. - pub fn exprs(&self) -> impl Iterator + '_ { + pub fn exprs(&self) -> impl DoubleEndedIterator + '_ { self.0.children().filter_map(SyntaxNode::cast) } } @@ -774,7 +780,7 @@ node! { impl Array { /// The array's items. - pub fn items(&self) -> impl Iterator + '_ { + pub fn items(&self) -> impl DoubleEndedIterator + '_ { self.0.children().filter_map(SyntaxNode::cast) } } @@ -811,7 +817,7 @@ node! { impl Dict { /// The dictionary's items. - pub fn items(&self) -> impl Iterator + '_ { + pub fn items(&self) -> impl DoubleEndedIterator + '_ { self.0.children().filter_map(SyntaxNode::cast) } } @@ -1204,7 +1210,7 @@ node! { impl Args { /// The positional and named arguments. - pub fn items(&self) -> impl Iterator + '_ { + pub fn items(&self) -> impl DoubleEndedIterator + '_ { self.0.children().filter_map(SyntaxNode::cast) } } @@ -1252,7 +1258,7 @@ impl Closure { } /// The parameter bindings. - pub fn params(&self) -> impl Iterator + '_ { + pub fn params(&self) -> impl DoubleEndedIterator + '_ { self.0 .children() .find(|x| x.kind() == &NodeKind::Params) -- cgit v1.2.3