From aac3afcba8ee9b3692f784c78626aa0596aaf612 Mon Sep 17 00:00:00 2001 From: Martin Haug Date: Mon, 21 Feb 2022 13:48:21 +0100 Subject: [PATCH] Remove `Parbreak` as a `NodeKind` --- src/parse/incremental.rs | 5 ++--- src/parse/mod.rs | 6 +----- src/parse/parser.rs | 7 ------- src/syntax/ast.rs | 2 +- src/syntax/highlight.rs | 1 - src/syntax/mod.rs | 7 +------ 6 files changed, 5 insertions(+), 23 deletions(-) diff --git a/src/parse/incremental.rs b/src/parse/incremental.rs index 7418dd584..bb5288dc1 100644 --- a/src/parse/incremental.rs +++ b/src/parse/incremental.rs @@ -138,7 +138,7 @@ impl Reparser<'_> { // Similarly to above, the end of the edit must be in the // reconsidered range. However, in markup mode, we need to extend - // the reconsidered range by up to two nodes so that spaceing etc. + // the reconsidered range by up to two nodes so that spacing etc. // results in the same tree. // // Therefore, there are two cases: @@ -400,7 +400,7 @@ fn validate( let mut right_pos = newborn_span.end; for child in &superseded[superseded_range.end ..] { - if child.kind().is_trivia() || child.kind() == &NodeKind::Parbreak { + if child.kind().is_trivia() { right_pos += child.len(); continue; } @@ -451,7 +451,6 @@ impl NodeKind { match self { // These are all replaceable by other tokens. Self::Linebreak - | Self::Parbreak | Self::Text(_) | Self::TextInLine(_) | Self::NonBreakingSpace diff --git a/src/parse/mod.rs b/src/parse/mod.rs index c14c45cf2..bd217c1c1 100644 --- a/src/parse/mod.rs +++ b/src/parse/mod.rs @@ -172,11 +172,7 @@ fn markup_node(p: &mut Parser, at_start: &mut bool) { // Whitespace. NodeKind::Space(newlines) => { *at_start |= *newlines > 0; - if *newlines < 2 { - p.eat(); - } else { - p.convert(NodeKind::Parbreak); - } + p.eat(); return; } diff --git a/src/parse/parser.rs b/src/parse/parser.rs index e495dbd00..545f6fd4e 100644 --- a/src/parse/parser.rs +++ b/src/parse/parser.rs @@ -176,13 +176,6 @@ impl<'s> Parser<'s> { } } - /// Eat the current token, but change its type. - pub fn convert(&mut self, kind: NodeKind) { - let marker = self.marker(); - self.eat(); - marker.convert(self, kind); - } - /// Whether the current token is of the given type. pub fn at(&self, kind: &NodeKind) -> bool { self.peek() == Some(kind) diff --git a/src/syntax/ast.rs b/src/syntax/ast.rs index 9d22121b9..7992f9de9 100644 --- a/src/syntax/ast.rs +++ b/src/syntax/ast.rs @@ -60,9 +60,9 @@ impl Markup { /// The markup nodes. pub fn nodes(&self) -> impl Iterator + '_ { self.0.children().filter_map(|node| match node.kind() { + NodeKind::Space(n) if *n > 1 => Some(MarkupNode::Parbreak), NodeKind::Space(_) => Some(MarkupNode::Space), NodeKind::Linebreak => Some(MarkupNode::Linebreak), - NodeKind::Parbreak => Some(MarkupNode::Parbreak), NodeKind::Text(s) | NodeKind::TextInLine(s) => { Some(MarkupNode::Text(s.clone())) } diff --git a/src/syntax/highlight.rs b/src/syntax/highlight.rs index af6fb0dfb..82f1ea0e8 100644 --- a/src/syntax/highlight.rs +++ b/src/syntax/highlight.rs @@ -198,7 +198,6 @@ impl Category { NodeKind::Underscore => None, NodeKind::Markup(_) => None, NodeKind::Space(_) => None, - NodeKind::Parbreak => None, NodeKind::Text(_) => None, NodeKind::TextInLine(_) => None, NodeKind::List => None, diff --git a/src/syntax/mod.rs b/src/syntax/mod.rs index c702199e6..2211fcb6f 100644 --- a/src/syntax/mod.rs +++ b/src/syntax/mod.rs @@ -589,8 +589,6 @@ pub enum NodeKind { Space(usize), /// A forced line break: `\`. Linebreak, - /// A paragraph break: Two or more newlines. - Parbreak, /// A consecutive non-markup string. Text(EcoString), /// A text node that cannot appear at the beginning of a source line. @@ -760,7 +758,6 @@ impl NodeKind { pub fn is_at_start(&self, prev: bool) -> bool { match self { Self::Space(n) if *n > 0 => true, - Self::Parbreak => true, Self::LineComment | Self::BlockComment => prev, _ => false, } @@ -771,7 +768,6 @@ impl NodeKind { match self { Self::Markup(_) | Self::Linebreak - | Self::Parbreak | Self::Text(_) | Self::TextInLine(_) | Self::NonBreakingSpace @@ -862,9 +858,9 @@ impl NodeKind { Self::Include => "keyword `include`", Self::From => "keyword `from`", Self::Markup(_) => "markup", + Self::Space(n) if *n > 1 => "paragraph break", Self::Space(_) => "space", Self::Linebreak => "forced linebreak", - Self::Parbreak => "paragraph break", Self::Text(_) | Self::TextInLine(_) => "text", Self::NonBreakingSpace => "non-breaking space", Self::EnDash => "en dash", @@ -988,7 +984,6 @@ impl Hash for NodeKind { Self::Markup(c) => c.hash(state), Self::Space(n) => n.hash(state), Self::Linebreak => {} - Self::Parbreak => {} Self::Text(s) => s.hash(state), Self::TextInLine(s) => s.hash(state), Self::NonBreakingSpace => {}