summaryrefslogtreecommitdiff
path: root/src/syntax
diff options
context:
space:
mode:
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.