summaryrefslogtreecommitdiff
path: root/crates/typst-syntax
diff options
context:
space:
mode:
authorPgBiel <9021226+PgBiel@users.noreply.github.com>2024-07-15 13:55:05 -0300
committerPgBiel <9021226+PgBiel@users.noreply.github.com>2024-07-15 18:23:36 -0300
commit2b442eae5e1bdedd29ee650e6a367c81a5ed9ce1 (patch)
tree3d187180a6ced061605752a98ef175ab470eff5f /crates/typst-syntax
parent629375a98151f8b053be2e7939a78ea554858c92 (diff)
remove inner node 'capped_newlines' field
Diffstat (limited to 'crates/typst-syntax')
-rw-r--r--crates/typst-syntax/src/node.rs23
1 files changed, 11 insertions, 12 deletions
diff --git a/crates/typst-syntax/src/node.rs b/crates/typst-syntax/src/node.rs
index 2a97124d..488b1084 100644
--- a/crates/typst-syntax/src/node.rs
+++ b/crates/typst-syntax/src/node.rs
@@ -161,7 +161,17 @@ impl SyntaxNode {
Repr::Leaf(_) | Repr::Error(_) => {
crate::lexer::count_capped_newlines(self.text())
}
- Repr::Inner(inner) => inner.capped_newlines,
+ Repr::Inner(inner) => {
+ let mut newlines = 0;
+ for child in &inner.children {
+ newlines += child.capped_newlines();
+ if newlines >= 2 {
+ break;
+ }
+ }
+
+ newlines.min(2)
+ }
}
}
@@ -398,11 +408,6 @@ struct InnerNode {
descendants: usize,
/// Whether this node or any of its children are erroneous.
erroneous: bool,
- /// The (capped) amount of newlines in this node's descendants.
- /// This is solely used to tell whether this node contains 0, 1, 2 or more
- /// newlines. As such, this number is capped at 2, even though there may be
- /// more newlines inside this node.
- capped_newlines: u8,
/// The upper bound of this node's numbering range.
upper: u64,
/// This node's children, losslessly make up this node.
@@ -418,23 +423,17 @@ impl InnerNode {
let mut len = 0;
let mut descendants = 1;
let mut erroneous = false;
- let mut capped_newlines: u8 = 0;
for child in &children {
len += child.len();
descendants += child.descendants();
erroneous |= child.erroneous();
-
- if capped_newlines < 2 {
- capped_newlines = capped_newlines.saturating_add(child.capped_newlines());
- }
}
Self {
kind,
len,
span: Span::detached(),
- capped_newlines: capped_newlines.min(2),
descendants,
erroneous,
upper: 0,