summaryrefslogtreecommitdiff
path: root/src/syntax/ident.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/syntax/ident.rs')
-rw-r--r--src/syntax/ident.rs12
1 files changed, 11 insertions, 1 deletions
diff --git a/src/syntax/ident.rs b/src/syntax/ident.rs
index 398e2ff9..2c61329d 100644
--- a/src/syntax/ident.rs
+++ b/src/syntax/ident.rs
@@ -3,7 +3,7 @@ use std::ops::Deref;
use unicode_xid::UnicodeXID;
-use super::Span;
+use super::{NodeKind, RedTicket, Span, TypedNode};
use crate::util::EcoString;
/// An unicode identifier with a few extra permissible characters.
@@ -66,6 +66,16 @@ impl From<&Ident> for EcoString {
}
}
+impl TypedNode for Ident {
+ fn cast_from(node: RedTicket) -> Option<Self> {
+ if let NodeKind::Ident(i) = node.kind() {
+ Some(Ident::new(i, node.own().span()).unwrap())
+ } else {
+ None
+ }
+ }
+}
+
/// Whether a string is a valid identifier.
pub fn is_ident(string: &str) -> bool {
let mut chars = string.chars();