diff options
Diffstat (limited to 'crates/libsyntax2')
-rw-r--r-- | crates/libsyntax2/src/ast/generated.rs | 18 | ||||
-rw-r--r-- | crates/libsyntax2/src/ast/mod.rs | 8 | ||||
-rw-r--r-- | crates/libsyntax2/src/grammar.ron | 1 |
3 files changed, 27 insertions, 0 deletions
diff --git a/crates/libsyntax2/src/ast/generated.rs b/crates/libsyntax2/src/ast/generated.rs index 31f5ecc44..b1fd0a8ad 100644 --- a/crates/libsyntax2/src/ast/generated.rs +++ b/crates/libsyntax2/src/ast/generated.rs | |||
@@ -123,6 +123,24 @@ impl<R: TreeRoot> AstNode<R> for Name<R> { | |||
123 | 123 | ||
124 | impl<R: TreeRoot> Name<R> {} | 124 | impl<R: TreeRoot> Name<R> {} |
125 | 125 | ||
126 | // NameRef | ||
127 | #[derive(Debug, Clone, Copy)] | ||
128 | pub struct NameRef<R: TreeRoot = Arc<SyntaxRoot>> { | ||
129 | syntax: SyntaxNode<R>, | ||
130 | } | ||
131 | |||
132 | impl<R: TreeRoot> AstNode<R> for NameRef<R> { | ||
133 | fn cast(syntax: SyntaxNode<R>) -> Option<Self> { | ||
134 | match syntax.kind() { | ||
135 | NAME_REF => Some(NameRef { syntax }), | ||
136 | _ => None, | ||
137 | } | ||
138 | } | ||
139 | fn syntax(&self) -> &SyntaxNode<R> { &self.syntax } | ||
140 | } | ||
141 | |||
142 | impl<R: TreeRoot> NameRef<R> {} | ||
143 | |||
126 | // StaticItem | 144 | // StaticItem |
127 | #[derive(Debug, Clone, Copy)] | 145 | #[derive(Debug, Clone, Copy)] |
128 | pub struct StaticItem<R: TreeRoot = Arc<SyntaxRoot>> { | 146 | pub struct StaticItem<R: TreeRoot = Arc<SyntaxRoot>> { |
diff --git a/crates/libsyntax2/src/ast/mod.rs b/crates/libsyntax2/src/ast/mod.rs index e9362d048..2e1fb2d1c 100644 --- a/crates/libsyntax2/src/ast/mod.rs +++ b/crates/libsyntax2/src/ast/mod.rs | |||
@@ -73,3 +73,11 @@ impl<R: TreeRoot> Name<R> { | |||
73 | ident.leaf_text().unwrap() | 73 | ident.leaf_text().unwrap() |
74 | } | 74 | } |
75 | } | 75 | } |
76 | |||
77 | impl<R: TreeRoot> NameRef<R> { | ||
78 | pub fn text(&self) -> SmolStr { | ||
79 | let ident = self.syntax().first_child() | ||
80 | .unwrap(); | ||
81 | ident.leaf_text().unwrap() | ||
82 | } | ||
83 | } | ||
diff --git a/crates/libsyntax2/src/grammar.ron b/crates/libsyntax2/src/grammar.ron index d4e8c53d3..ee231931e 100644 --- a/crates/libsyntax2/src/grammar.ron +++ b/crates/libsyntax2/src/grammar.ron | |||
@@ -228,5 +228,6 @@ Grammar( | |||
228 | "StaticItem": ( traits: ["NameOwner"] ), | 228 | "StaticItem": ( traits: ["NameOwner"] ), |
229 | "TypeItem": ( traits: ["NameOwner"] ), | 229 | "TypeItem": ( traits: ["NameOwner"] ), |
230 | "Name": (), | 230 | "Name": (), |
231 | "NameRef": (), | ||
231 | }, | 232 | }, |
232 | ) | 233 | ) |