aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_syntax
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2018-10-24 16:37:25 +0100
committerAleksey Kladov <[email protected]>2018-10-24 16:37:25 +0100
commit69d07df201307fb7c539cdb20b8f1c1c12840386 (patch)
tree08cccd64582510ce2c82ceec729504a80e33f5b1 /crates/ra_syntax
parent9a7db8fa009c612168ef16f6ed72315b5406ed09 (diff)
Complete crate:: paths
Diffstat (limited to 'crates/ra_syntax')
-rw-r--r--crates/ra_syntax/src/ast/generated.rs4
-rw-r--r--crates/ra_syntax/src/ast/mod.rs30
-rw-r--r--crates/ra_syntax/src/grammar.ron3
3 files changed, 36 insertions, 1 deletions
diff --git a/crates/ra_syntax/src/ast/generated.rs b/crates/ra_syntax/src/ast/generated.rs
index 98c7de361..096405a38 100644
--- a/crates/ra_syntax/src/ast/generated.rs
+++ b/crates/ra_syntax/src/ast/generated.rs
@@ -1371,6 +1371,10 @@ impl<'a> Path<'a> {
1371 pub fn segment(self) -> Option<PathSegment<'a>> { 1371 pub fn segment(self) -> Option<PathSegment<'a>> {
1372 super::child_opt(self) 1372 super::child_opt(self)
1373 } 1373 }
1374
1375 pub fn qualifier(self) -> Option<Path<'a>> {
1376 super::child_opt(self)
1377 }
1374} 1378}
1375 1379
1376// PathExpr 1380// PathExpr
diff --git a/crates/ra_syntax/src/ast/mod.rs b/crates/ra_syntax/src/ast/mod.rs
index 900426a8a..c033263a1 100644
--- a/crates/ra_syntax/src/ast/mod.rs
+++ b/crates/ra_syntax/src/ast/mod.rs
@@ -232,6 +232,36 @@ impl<'a> IfExpr<'a> {
232 } 232 }
233} 233}
234 234
235
236#[derive(Debug, Clone, Copy)]
237pub enum PathSegmentKind<'a> {
238 Name(NameRef<'a>),
239 SelfKw,
240 SuperKw,
241 CrateKw,
242}
243
244impl<'a> PathSegment<'a> {
245 pub fn parent_path(self) -> Path<'a> {
246 self.syntax().parent().and_then(Path::cast)
247 .expect("segments are always nested in paths")
248 }
249
250 pub fn kind(self) -> Option<PathSegmentKind<'a>> {
251 let res = if let Some(name_ref) = self.name_ref() {
252 PathSegmentKind::Name(name_ref)
253 } else {
254 match self.syntax().first_child()?.kind() {
255 SELF_KW => PathSegmentKind::SelfKw,
256 SUPER_KW => PathSegmentKind::SuperKw,
257 CRATE_KW => PathSegmentKind::CrateKw,
258 _ => return None,
259 }
260 };
261 Some(res)
262 }
263}
264
235fn child_opt<'a, P: AstNode<'a>, C: AstNode<'a>>(parent: P) -> Option<C> { 265fn child_opt<'a, P: AstNode<'a>, C: AstNode<'a>>(parent: P) -> Option<C> {
236 children(parent).next() 266 children(parent).next()
237} 267}
diff --git a/crates/ra_syntax/src/grammar.ron b/crates/ra_syntax/src/grammar.ron
index 0830e02f2..c1c215e0d 100644
--- a/crates/ra_syntax/src/grammar.ron
+++ b/crates/ra_syntax/src/grammar.ron
@@ -531,7 +531,8 @@ Grammar(
531 ), 531 ),
532 "Path": ( 532 "Path": (
533 options: [ 533 options: [
534 ["segment", "PathSegment"] 534 ["segment", "PathSegment"],
535 ["qualifier", "Path"],
535 ] 536 ]
536 ), 537 ),
537 "PathSegment": ( 538 "PathSegment": (