From 6a4823461f491aef63451f097ddfe5602e0b2157 Mon Sep 17 00:00:00 2001 From: Laurenz Date: Sat, 10 Jul 2021 20:01:18 +0200 Subject: Reference-count complex values Rename some nodes types --- src/syntax/mod.rs | 2 +- src/syntax/node.rs | 2 +- src/syntax/span.rs | 50 +++++++++++++++++++++++++------------------------- src/syntax/visit.rs | 24 ++++++++++++------------ 4 files changed, 39 insertions(+), 39 deletions(-) (limited to 'src/syntax') 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; +pub type SyntaxTree = Vec; 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 From for Span where T: Into + 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 Add for Pos -where - T: Into, -{ - type Output = Self; - - fn add(self, rhs: T) -> Self { - Pos(self.0 + rhs.into().0) - } -} - impl From for Pos { fn from(index: u32) -> Self { Self(index) @@ -207,6 +196,17 @@ impl Debug for Pos { } } +impl Add for Pos +where + T: Into, +{ + 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), } } -- cgit v1.2.3