diff options
| author | Martin Haug <mhaug@live.de> | 2022-01-02 00:46:19 +0100 |
|---|---|---|
| committer | Martin Haug <mhaug@live.de> | 2022-01-02 00:46:19 +0100 |
| commit | 5f114e18eb76a1937941b2ea64842b908c9ad89e (patch) | |
| tree | 0541aa560b19e5805603fc06b3440f40db3d5fd1 /src/syntax | |
| parent | 289122e83c085668e56e52225c2dcfd9417d6262 (diff) | |
Added a test framework for incremental parsing
Fix several errors:
- Indented markup is now reparsed right
- All end group errors will now fail a reparse
- Rightmost errors will always fail a reparse
Diffstat (limited to 'src/syntax')
| -rw-r--r-- | src/syntax/ast.rs | 2 | ||||
| -rw-r--r-- | src/syntax/highlight.rs | 2 | ||||
| -rw-r--r-- | src/syntax/mod.rs | 29 |
3 files changed, 27 insertions, 6 deletions
diff --git a/src/syntax/ast.rs b/src/syntax/ast.rs index ed74dfe5..bea4ef00 100644 --- a/src/syntax/ast.rs +++ b/src/syntax/ast.rs @@ -53,7 +53,7 @@ macro_rules! node { node! { /// The syntactical root capable of representing a full parsed document. - Markup + Markup: NodeKind::Markup(_) } impl Markup { diff --git a/src/syntax/highlight.rs b/src/syntax/highlight.rs index 21af060f..9f7365a8 100644 --- a/src/syntax/highlight.rs +++ b/src/syntax/highlight.rs @@ -154,7 +154,7 @@ impl Category { NodeKind::Str(_) => Some(Category::String), NodeKind::Error(_, _) => Some(Category::Invalid), NodeKind::Unknown(_) => Some(Category::Invalid), - NodeKind::Markup => None, + NodeKind::Markup(_) => None, NodeKind::Space(_) => None, NodeKind::Parbreak => None, NodeKind::Text(_) => None, diff --git a/src/syntax/mod.rs b/src/syntax/mod.rs index b72e5843..388d0bb0 100644 --- a/src/syntax/mod.rs +++ b/src/syntax/mod.rs @@ -64,6 +64,14 @@ impl Green { } } + /// Whether the node is a leaf node in the green tree. + pub fn is_leaf(&self) -> bool { + match self { + Green::Node(n) => n.children().is_empty(), + Green::Token(_) => true, + } + } + /// Change the type of the node. pub fn convert(&mut self, kind: NodeKind) { match self { @@ -361,6 +369,11 @@ impl<'a> RedRef<'a> { Span::new(self.id, self.offset, self.offset + self.green.len()) } + /// Whether the node is a leaf node. + pub fn is_leaf(self) -> bool { + self.green.is_leaf() + } + /// The error messages for this node and its descendants. pub fn errors(self) -> Vec<Error> { if !self.green.erroneous() { @@ -385,6 +398,14 @@ impl<'a> RedRef<'a> { } } + /// Perform a depth-first search starting at this node. + pub fn all_children(&self) -> Vec<Self> { + let mut res = vec![self.clone()]; + res.extend(self.children().flat_map(|child| child.all_children().into_iter())); + + res + } + /// Convert the node to a typed AST node. pub fn cast<T>(self) -> Option<T> where @@ -562,8 +583,8 @@ pub enum NodeKind { Include, /// The `from` keyword. From, - /// Template markup. - Markup, + /// Template markup of which all lines must start in some column. + Markup(usize), /// One or more whitespace characters. Space(usize), /// A forced line break: `\`. @@ -738,7 +759,7 @@ impl NodeKind { /// Whether this token appears in Markup. pub fn mode(&self) -> Option<TokenMode> { match self { - Self::Markup + Self::Markup(_) | Self::Linebreak | Self::Parbreak | Self::Text(_) @@ -823,7 +844,7 @@ impl NodeKind { Self::Import => "keyword `import`", Self::Include => "keyword `include`", Self::From => "keyword `from`", - Self::Markup => "markup", + Self::Markup(_) => "markup", Self::Space(_) => "space", Self::Linebreak => "forced linebreak", Self::Parbreak => "paragraph break", |
