summaryrefslogtreecommitdiff
path: root/src/syntax/mod.rs
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/mod.rs
parent5c952d56d0d602a1dbcf85210ae30fa402219fca (diff)
Code Review: No Patrick, question marks are not an instrument
Diffstat (limited to 'src/syntax/mod.rs')
-rw-r--r--src/syntax/mod.rs15
1 files changed, 10 insertions, 5 deletions
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.