aboutsummaryrefslogtreecommitdiff
path: root/crates/libsyntax2/src
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2018-09-03 13:10:06 +0100
committerAleksey Kladov <[email protected]>2018-09-03 13:10:06 +0100
commit4798a89a12f40af17174a160f6d6a2f1c53db8d6 (patch)
tree2a97f379f624127739188f35babfa9710b104bf4 /crates/libsyntax2/src
parent58480b9190d8851abf7f634820188e33efed286d (diff)
Complete params
Diffstat (limited to 'crates/libsyntax2/src')
-rw-r--r--crates/libsyntax2/src/ast/generated.rs33
-rw-r--r--crates/libsyntax2/src/ast/mod.rs6
-rw-r--r--crates/libsyntax2/src/grammar.ron11
-rw-r--r--crates/libsyntax2/src/grammar/patterns.rs2
-rw-r--r--crates/libsyntax2/src/grammar/types.rs5
5 files changed, 43 insertions, 14 deletions
diff --git a/crates/libsyntax2/src/ast/generated.rs b/crates/libsyntax2/src/ast/generated.rs
index 11306a835..4a57837df 100644
--- a/crates/libsyntax2/src/ast/generated.rs
+++ b/crates/libsyntax2/src/ast/generated.rs
@@ -682,6 +682,28 @@ impl<'a> AstNode<'a> for IndexExpr<'a> {
682 682
683impl<'a> IndexExpr<'a> {} 683impl<'a> IndexExpr<'a> {}
684 684
685// ItemList
686#[derive(Debug, Clone, Copy)]
687pub struct ItemList<'a> {
688 syntax: SyntaxNodeRef<'a>,
689}
690
691impl<'a> AstNode<'a> for ItemList<'a> {
692 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> {
693 match syntax.kind() {
694 ITEM_LIST => Some(ItemList { syntax }),
695 _ => None,
696 }
697 }
698 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax }
699}
700
701impl<'a> ItemList<'a> {
702 pub fn items(self) -> impl Iterator<Item = ModuleItem<'a>> + 'a {
703 super::children(self)
704 }
705}
706
685// Label 707// Label
686#[derive(Debug, Clone, Copy)] 708#[derive(Debug, Clone, Copy)]
687pub struct Label<'a> { 709pub struct Label<'a> {
@@ -956,9 +978,9 @@ impl<'a> AstNode<'a> for Module<'a> {
956 978
957impl<'a> ast::NameOwner<'a> for Module<'a> {} 979impl<'a> ast::NameOwner<'a> for Module<'a> {}
958impl<'a> ast::AttrsOwner<'a> for Module<'a> {} 980impl<'a> ast::AttrsOwner<'a> for Module<'a> {}
959impl<'a> Module<'a> { 981impl<'a> ast::FnDefOwner<'a> for Module<'a> {}
960 pub fn items(self) -> impl Iterator<Item = ModuleItem<'a>> + 'a { 982impl<'a> Module<'a> {pub fn item_list(self) -> Option<ItemList<'a>> {
961 super::children(self) 983 super::child_opt(self)
962 } 984 }
963} 985}
964 986
@@ -1593,15 +1615,12 @@ impl<'a> AstNode<'a> for Root<'a> {
1593 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } 1615 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax }
1594} 1616}
1595 1617
1618impl<'a> ast::FnDefOwner<'a> for Root<'a> {}
1596impl<'a> Root<'a> { 1619impl<'a> Root<'a> {
1597 pub fn items(self) -> impl Iterator<Item = ModuleItem<'a>> + 'a { 1620 pub fn items(self) -> impl Iterator<Item = ModuleItem<'a>> + 'a {
1598 super::children(self) 1621 super::children(self)
1599 } 1622 }
1600 1623
1601 pub fn functions(self) -> impl Iterator<Item = FnDef<'a>> + 'a {
1602 super::children(self)
1603 }
1604
1605 pub fn modules(self) -> impl Iterator<Item = Module<'a>> + 'a { 1624 pub fn modules(self) -> impl Iterator<Item = Module<'a>> + 'a {
1606 super::children(self) 1625 super::children(self)
1607 } 1626 }
diff --git a/crates/libsyntax2/src/ast/mod.rs b/crates/libsyntax2/src/ast/mod.rs
index 274996171..881f380f3 100644
--- a/crates/libsyntax2/src/ast/mod.rs
+++ b/crates/libsyntax2/src/ast/mod.rs
@@ -32,6 +32,12 @@ pub trait ArgListOwner<'a>: AstNode<'a> {
32 } 32 }
33} 33}
34 34
35pub trait FnDefOwner<'a>: AstNode<'a> {
36 fn functions(self) -> Box<Iterator<Item=FnDef<'a>> + 'a> {
37 Box::new(children(self))
38 }
39}
40
35pub trait TypeParamsOwner<'a>: AstNode<'a> { 41pub trait TypeParamsOwner<'a>: AstNode<'a> {
36 fn type_param_list(self) -> Option<TypeParamList<'a>> { 42 fn type_param_list(self) -> Option<TypeParamList<'a>> {
37 child_opt(self) 43 child_opt(self)
diff --git a/crates/libsyntax2/src/grammar.ron b/crates/libsyntax2/src/grammar.ron
index 683623a5d..8a2b780f0 100644
--- a/crates/libsyntax2/src/grammar.ron
+++ b/crates/libsyntax2/src/grammar.ron
@@ -238,9 +238,9 @@ Grammar(
238 ], 238 ],
239 ast: { 239 ast: {
240 "Root": ( 240 "Root": (
241 traits: [ "FnDefOwner" ],
241 collections: [ 242 collections: [
242 ["items", "ModuleItem"], 243 ["items", "ModuleItem"],
243 ["functions", "FnDef"],
244 ["modules", "Module"], 244 ["modules", "Module"],
245 ] 245 ]
246 ), 246 ),
@@ -271,10 +271,11 @@ Grammar(
271 ] ), 271 ] ),
272 "TraitDef": ( traits: ["NameOwner", "AttrsOwner"] ), 272 "TraitDef": ( traits: ["NameOwner", "AttrsOwner"] ),
273 "Module": ( 273 "Module": (
274 traits: ["NameOwner", "AttrsOwner"], 274 traits: ["NameOwner", "AttrsOwner", "FnDefOwner" ],
275 collections: [ 275 options: [ "ItemList" ]
276 ["items", "ModuleItem"] 276 ),
277 ] 277 "ItemList": (
278 collections: [ ["items", "ModuleItem"] ]
278 ), 279 ),
279 "ConstDef": ( traits: [ 280 "ConstDef": ( traits: [
280 "NameOwner", 281 "NameOwner",
diff --git a/crates/libsyntax2/src/grammar/patterns.rs b/crates/libsyntax2/src/grammar/patterns.rs
index 065570b99..aa20ae8e4 100644
--- a/crates/libsyntax2/src/grammar/patterns.rs
+++ b/crates/libsyntax2/src/grammar/patterns.rs
@@ -23,7 +23,7 @@ pub(super) fn pattern(p: &mut Parser) {
23} 23}
24 24
25const PAT_RECOVERY_SET: TokenSet = 25const PAT_RECOVERY_SET: TokenSet =
26 token_set![LET_KW, IF_KW, WHILE_KW, LOOP_KW, MATCH_KW]; 26 token_set![LET_KW, IF_KW, WHILE_KW, LOOP_KW, MATCH_KW, R_PAREN, COMMA];
27 27
28 28
29fn atom_pat(p: &mut Parser) -> Option<CompletedMarker> { 29fn atom_pat(p: &mut Parser) -> Option<CompletedMarker> {
diff --git a/crates/libsyntax2/src/grammar/types.rs b/crates/libsyntax2/src/grammar/types.rs
index 89030e66c..a52355b50 100644
--- a/crates/libsyntax2/src/grammar/types.rs
+++ b/crates/libsyntax2/src/grammar/types.rs
@@ -8,6 +8,9 @@ pub(super) const TYPE_FIRST: TokenSet =
8 paths::PATH_FIRST, 8 paths::PATH_FIRST,
9 ]; 9 ];
10 10
11const TYPE_RECOVERY_SET: TokenSet =
12 token_set![R_PAREN, COMMA];
13
11pub(super) fn type_(p: &mut Parser) { 14pub(super) fn type_(p: &mut Parser) {
12 match p.current() { 15 match p.current() {
13 L_PAREN => paren_or_tuple_type(p), 16 L_PAREN => paren_or_tuple_type(p),
@@ -23,7 +26,7 @@ pub(super) fn type_(p: &mut Parser) {
23 L_ANGLE => path_type(p), 26 L_ANGLE => path_type(p),
24 _ if paths::is_path_start(p) => path_type(p), 27 _ if paths::is_path_start(p) => path_type(p),
25 _ => { 28 _ => {
26 p.err_and_bump("expected type"); 29 p.err_recover("expected type", TYPE_RECOVERY_SET);
27 } 30 }
28 } 31 }
29} 32}