aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_syntax/src/ast.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_syntax/src/ast.rs')
-rw-r--r--crates/ra_syntax/src/ast.rs69
1 files changed, 69 insertions, 0 deletions
diff --git a/crates/ra_syntax/src/ast.rs b/crates/ra_syntax/src/ast.rs
index 000cfb981..3df23b16f 100644
--- a/crates/ra_syntax/src/ast.rs
+++ b/crates/ra_syntax/src/ast.rs
@@ -664,6 +664,75 @@ impl LiteralExpr {
664 } 664 }
665} 665}
666 666
667// STRUCT_PAT@[20; 42)
668// PATH@[20; 26)
669// PATH_SEGMENT@[20; 26)
670// NAME_REF@[20; 26)
671// IDENT@[20; 26) "Strukt"
672// WHITESPACE@[26; 27)
673// FIELD_PAT_LIST@[27; 42)
674// L_CURLY@[27; 28)
675// WHITESPACE@[28; 29)
676// IDENT@[29; 30) "x"
677// COLON@[30; 31)
678// WHITESPACE@[31; 32)
679// BIND_PAT@[32; 33)
680// NAME@[32; 33)
681// IDENT@[32; 33) "x"
682// COMMA@[33; 34)
683// WHITESPACE@[34; 35)
684// BIND_PAT@[35; 36)
685// NAME@[35; 36)
686// IDENT@[35; 36) "y"
687// COMMA@[36; 37)
688// WHITESPACE@[37; 38)
689// DOTDOT@[38; 40)
690// WHITESPACE@[40; 41)
691// R_CURLY@[41; 42)
692
693#[derive(Clone, Debug, PartialEq, Eq, Hash)]
694pub struct FieldPat {
695 pub ident: SmolStr,
696 pub pat: Option<TreeArc<Pat>>,
697}
698
699impl FieldPatList {
700 // TODO: try returning an iterator?
701 // FIXME: shouldnt the parser do this? :o
702 pub fn field_pats(&self) -> Vec<FieldPat> {
703 let mut child_iter = self.syntax().children();
704 let mut pats = Vec::new();
705
706 while let Some(node) = child_iter.next() {
707 if node.kind() != IDENT {
708 continue;
709 }
710
711 let ident = node.leaf_text().unwrap().clone();
712 let mut pat = None;
713
714 // get pat
715 while let Some(node) = child_iter.next() {
716 if node.kind() == COMMA {
717 break;
718 }
719
720 if let Some(p) = Pat::cast(node) {
721 pat = Some(p.to_owned());
722 }
723 }
724
725 let field_pat = FieldPat {
726 ident: ident,
727 pat: pat,
728 };
729 pats.push(field_pat);
730 }
731
732 pats
733 }
734}
735
667#[test] 736#[test]
668fn test_doc_comment_of_items() { 737fn test_doc_comment_of_items() {
669 let file = SourceFile::parse( 738 let file = SourceFile::parse(