diff options
Diffstat (limited to 'src/syntax')
| -rw-r--r-- | src/syntax/expr.rs | 2 | ||||
| -rw-r--r-- | src/syntax/ident.rs | 14 | ||||
| -rw-r--r-- | src/syntax/mod.rs | 2 | ||||
| -rw-r--r-- | src/syntax/node.rs | 4 |
4 files changed, 14 insertions, 8 deletions
diff --git a/src/syntax/expr.rs b/src/syntax/expr.rs index 368fe41f..21df47c8 100644 --- a/src/syntax/expr.rs +++ b/src/syntax/expr.rs @@ -28,7 +28,7 @@ pub enum Expr { /// A fraction unit literal: `1fr`. Fractional(Span, f64), /// A string literal: `"hello!"`. - Str(Span, String), + Str(Span, EcoString), /// An identifier: `left`. Ident(Ident), /// An array expression: `(1, "hi", 12cm)`. diff --git a/src/syntax/ident.rs b/src/syntax/ident.rs index a46ad232..b1328bbe 100644 --- a/src/syntax/ident.rs +++ b/src/syntax/ident.rs @@ -3,6 +3,7 @@ use std::ops::Deref; use unicode_xid::UnicodeXID; use super::Span; +use crate::eco::EcoString; /// An unicode identifier with a few extra permissible characters. /// @@ -16,7 +17,7 @@ pub struct Ident { /// The source code location. pub span: Span, /// The identifier string. - pub string: String, + pub string: EcoString, } impl Ident { @@ -26,7 +27,10 @@ impl Ident { span: impl Into<Span>, ) -> Option<Self> { if is_ident(string.as_ref()) { - Some(Self { span: span.into(), string: string.into() }) + Some(Self { + span: span.into(), + string: EcoString::from_str(string), + }) } else { None } @@ -34,13 +38,13 @@ impl Ident { /// Return a reference to the underlying string. pub fn as_str(&self) -> &str { - self.string.as_str() + self } } impl AsRef<str> for Ident { fn as_ref(&self) -> &str { - self.as_str() + self } } @@ -48,7 +52,7 @@ impl Deref for Ident { type Target = str; fn deref(&self) -> &Self::Target { - self.as_str() + self.string.as_str() } } diff --git a/src/syntax/mod.rs b/src/syntax/mod.rs index 6673fda6..1de5c1dd 100644 --- a/src/syntax/mod.rs +++ b/src/syntax/mod.rs @@ -13,6 +13,8 @@ pub use node::*; pub use span::*; pub use token::*; +use crate::eco::EcoString; + /// The abstract syntax tree. /// /// This type can represent a full parsed document. diff --git a/src/syntax/node.rs b/src/syntax/node.rs index 1fbdb3d8..bb9ff098 100644 --- a/src/syntax/node.rs +++ b/src/syntax/node.rs @@ -6,7 +6,7 @@ use super::*; #[derive(Debug, Clone, PartialEq)] pub enum Node { /// Plain text. - Text(String), + Text(EcoString), /// Whitespace containing less than two newlines. Space, /// A forced line break: `\`. @@ -38,7 +38,7 @@ pub struct RawNode { pub lang: Option<Ident>, /// The raw text, determined as the raw string between the backticks trimmed /// according to the above rules. - pub text: String, + pub text: EcoString, /// Whether the element is block-level, that is, it has 3+ backticks /// and contains at least one newline. pub block: bool, |
