diff options
| author | Laurenz <laurmaedje@gmail.com> | 2021-07-10 20:01:18 +0200 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2021-07-10 23:10:17 +0200 |
| commit | 6a4823461f491aef63451f097ddfe5602e0b2157 (patch) | |
| tree | ad11b0ad169d030942d950573c729d50f7b3291b /src/syntax | |
| parent | 36b3067c19c8743032a44f888ee48702b88d135b (diff) | |
Reference-count complex values
Rename some nodes types
Diffstat (limited to 'src/syntax')
| -rw-r--r-- | src/syntax/mod.rs | 2 | ||||
| -rw-r--r-- | src/syntax/node.rs | 2 | ||||
| -rw-r--r-- | src/syntax/span.rs | 50 | ||||
| -rw-r--r-- | src/syntax/visit.rs | 24 |
4 files changed, 39 insertions, 39 deletions
diff --git a/src/syntax/mod.rs b/src/syntax/mod.rs index 1de5c1dd..895a5bc5 100644 --- a/src/syntax/mod.rs +++ b/src/syntax/mod.rs @@ -18,4 +18,4 @@ use crate::eco::EcoString; /// The abstract syntax tree. /// /// This type can represent a full parsed document. -pub type SyntaxTree = Vec<Node>; +pub type SyntaxTree = Vec<SyntaxNode>; diff --git a/src/syntax/node.rs b/src/syntax/node.rs index bb9ff098..9294fecd 100644 --- a/src/syntax/node.rs +++ b/src/syntax/node.rs @@ -4,7 +4,7 @@ use super::*; /// A syntax node, encompassing a single logical entity of parsed source code. #[derive(Debug, Clone, PartialEq)] -pub enum Node { +pub enum SyntaxNode { /// Plain text. Text(EcoString), /// Whitespace containing less than two newlines. diff --git a/src/syntax/span.rs b/src/syntax/span.rs index f9b1d312..8a630faa 100644 --- a/src/syntax/span.rs +++ b/src/syntax/span.rs @@ -120,20 +120,6 @@ impl Span { } } -impl Eq for Span {} - -impl PartialEq for Span { - fn eq(&self, other: &Self) -> bool { - !Self::cmp() || (self.start == other.start && self.end == other.end) - } -} - -impl Default for Span { - fn default() -> Self { - Span::ZERO - } -} - impl<T> From<T> for Span where T: Into<Pos> + Copy, @@ -152,12 +138,26 @@ where } } +impl Default for Span { + fn default() -> Self { + Span::ZERO + } +} + impl Debug for Span { fn fmt(&self, f: &mut Formatter) -> fmt::Result { write!(f, "<{:?}-{:?}>", self.start, self.end) } } +impl Eq for Span {} + +impl PartialEq for Span { + fn eq(&self, other: &Self) -> bool { + !Self::cmp() || (self.start == other.start && self.end == other.end) + } +} + /// A byte position in source code. #[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Serialize, Deserialize)] pub struct Pos(pub u32); @@ -172,17 +172,6 @@ impl Pos { } } -impl<T> Add<T> for Pos -where - T: Into<Pos>, -{ - type Output = Self; - - fn add(self, rhs: T) -> Self { - Pos(self.0 + rhs.into().0) - } -} - impl From<u32> for Pos { fn from(index: u32) -> Self { Self(index) @@ -207,6 +196,17 @@ impl Debug for Pos { } } +impl<T> Add<T> for Pos +where + T: Into<Pos>, +{ + type Output = Self; + + fn add(self, rhs: T) -> Self { + Pos(self.0 + rhs.into().0) + } +} + /// A one-indexed line-column position in source code. #[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Serialize, Deserialize)] pub struct Location { diff --git a/src/syntax/visit.rs b/src/syntax/visit.rs index 1184010b..b6ee657a 100644 --- a/src/syntax/visit.rs +++ b/src/syntax/visit.rs @@ -85,19 +85,19 @@ impl_visitors! { } } - visit_node(v, node: Node) { + visit_node(v, node: SyntaxNode) { match node { - Node::Text(_) => {} - Node::Space => {} - Node::Linebreak(_) => {} - Node::Parbreak(_) => {} - Node::Strong(_) => {} - Node::Emph(_) => {} - Node::Raw(_) => {} - Node::Heading(n) => v.visit_heading(n), - Node::List(n) => v.visit_list(n), - Node::Enum(n) => v.visit_enum(n), - Node::Expr(n) => v.visit_expr(n), + SyntaxNode::Text(_) => {} + SyntaxNode::Space => {} + SyntaxNode::Linebreak(_) => {} + SyntaxNode::Parbreak(_) => {} + SyntaxNode::Strong(_) => {} + SyntaxNode::Emph(_) => {} + SyntaxNode::Raw(_) => {} + SyntaxNode::Heading(n) => v.visit_heading(n), + SyntaxNode::List(n) => v.visit_list(n), + SyntaxNode::Enum(n) => v.visit_enum(n), + SyntaxNode::Expr(n) => v.visit_expr(n), } } |
