summaryrefslogtreecommitdiff
path: root/src/syntax/ident.rs
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2021-02-09 19:46:57 +0100
committerLaurenz <laurmaedje@gmail.com>2021-02-09 19:46:57 +0100
commit06ca740d01b428f12f6bd327257cd05dce737b03 (patch)
tree995bf8ff3a606aedecf296c9e805e11e9cd0ae8e /src/syntax/ident.rs
parente35bbfffcb1f84b2fb0679759152ca0a5eabfad4 (diff)
Split evaluation and execution 🔪
Diffstat (limited to 'src/syntax/ident.rs')
-rw-r--r--src/syntax/ident.rs35
1 files changed, 22 insertions, 13 deletions
diff --git a/src/syntax/ident.rs b/src/syntax/ident.rs
index c4cc19bc..731a2789 100644
--- a/src/syntax/ident.rs
+++ b/src/syntax/ident.rs
@@ -2,6 +2,7 @@ use std::ops::Deref;
use unicode_xid::UnicodeXID;
+use super::Span;
use crate::pretty::{Pretty, Printer};
/// An Unicode identifier with a few extra permissible characters.
@@ -12,13 +13,21 @@ use crate::pretty::{Pretty, Printer};
///
/// [uax31]: http://www.unicode.org/reports/tr31/
#[derive(Debug, Clone, Eq, PartialEq, Ord, PartialOrd)]
-pub struct Ident(pub String);
+pub struct Ident {
+ /// The source code location.
+ pub span: Span,
+ /// The identifier string.
+ pub string: String,
+}
impl Ident {
/// Create a new identifier from a string checking that it is a valid.
- pub fn new(ident: impl AsRef<str> + Into<String>) -> Option<Self> {
- if is_ident(ident.as_ref()) {
- Some(Self(ident.into()))
+ pub fn new(
+ string: impl AsRef<str> + Into<String>,
+ span: impl Into<Span>,
+ ) -> Option<Self> {
+ if is_ident(string.as_ref()) {
+ Some(Self { span: span.into(), string: string.into() })
} else {
None
}
@@ -26,19 +35,13 @@ impl Ident {
/// Return a reference to the underlying string.
pub fn as_str(&self) -> &str {
- self
- }
-}
-
-impl Pretty for Ident {
- fn pretty(&self, p: &mut Printer) {
- p.push_str(self.as_str());
+ self.string.as_str()
}
}
impl AsRef<str> for Ident {
fn as_ref(&self) -> &str {
- self
+ self.as_str()
}
}
@@ -46,7 +49,13 @@ impl Deref for Ident {
type Target = str;
fn deref(&self) -> &Self::Target {
- self.0.as_str()
+ self.as_str()
+ }
+}
+
+impl Pretty for Ident {
+ fn pretty(&self, p: &mut Printer) {
+ p.push_str(self.as_str());
}
}