summaryrefslogtreecommitdiff
path: root/src/syntax
diff options
context:
space:
mode:
authorMartin Haug <mhaug@live.de>2021-11-05 12:53:52 +0100
committerMartin Haug <mhaug@live.de>2021-11-05 13:46:41 +0100
commitcf2e527a026e81269ef716b4d6675ae6d981d681 (patch)
tree73d26690ccb3a3d81cf85f285716a52810e853fe /src/syntax
parent5c952d56d0d602a1dbcf85210ae30fa402219fca (diff)
Code Review: No Patrick, question marks are not an instrument
Diffstat (limited to 'src/syntax')
-rw-r--r--src/syntax/ast.rs6
-rw-r--r--src/syntax/mod.rs15
2 files changed, 15 insertions, 6 deletions
diff --git a/src/syntax/ast.rs b/src/syntax/ast.rs
index b6f64c67..1198d6b1 100644
--- a/src/syntax/ast.rs
+++ b/src/syntax/ast.rs
@@ -156,7 +156,11 @@ impl HeadingNode {
/// The section depth (numer of equals signs).
pub fn level(&self) -> u8 {
- self.0.children().filter(|n| n.kind() == &NodeKind::Eq).count() as u8
+ self.0
+ .children()
+ .filter(|n| n.kind() == &NodeKind::Eq)
+ .count()
+ .min(u8::MAX.into()) as u8
}
}
diff --git a/src/syntax/mod.rs b/src/syntax/mod.rs
index db3b0c9a..363cbe6e 100644
--- a/src/syntax/mod.rs
+++ b/src/syntax/mod.rs
@@ -98,15 +98,20 @@ pub struct GreenNode {
impl GreenNode {
/// Creates a new node with the given kind and children.
- pub fn with_children(kind: NodeKind, len: usize, children: Vec<Green>) -> Self {
- let mut data = GreenData::new(kind, len);
- data.erroneous |= children.iter().any(|c| c.erroneous());
+ pub fn with_children(kind: NodeKind, children: Vec<Green>) -> Self {
+ let mut data = GreenData::new(kind, 0);
+ let len = children
+ .iter()
+ .inspect(|c| data.erroneous |= c.erroneous())
+ .map(Green::len)
+ .sum();
+ data.len = len;
Self { data, children }
}
/// Creates a new node with the given kind and a single child.
- pub fn with_child(kind: NodeKind, len: usize, child: impl Into<Green>) -> Self {
- Self::with_children(kind, len, vec![child.into()])
+ pub fn with_child(kind: NodeKind, child: impl Into<Green>) -> Self {
+ Self::with_children(kind, vec![child.into()])
}
/// The node's children.