From 4798a89a12f40af17174a160f6d6a2f1c53db8d6 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Mon, 3 Sep 2018 15:10:06 +0300 Subject: Complete params --- crates/libsyntax2/src/ast/generated.rs | 33 ++++++++++++++++++++++++------- crates/libsyntax2/src/ast/mod.rs | 6 ++++++ crates/libsyntax2/src/grammar.ron | 11 ++++++----- crates/libsyntax2/src/grammar/patterns.rs | 2 +- crates/libsyntax2/src/grammar/types.rs | 5 ++++- 5 files changed, 43 insertions(+), 14 deletions(-) (limited to 'crates/libsyntax2/src') 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> { impl<'a> IndexExpr<'a> {} +// ItemList +#[derive(Debug, Clone, Copy)] +pub struct ItemList<'a> { + syntax: SyntaxNodeRef<'a>, +} + +impl<'a> AstNode<'a> for ItemList<'a> { + fn cast(syntax: SyntaxNodeRef<'a>) -> Option { + match syntax.kind() { + ITEM_LIST => Some(ItemList { syntax }), + _ => None, + } + } + fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } +} + +impl<'a> ItemList<'a> { + pub fn items(self) -> impl Iterator> + 'a { + super::children(self) + } +} + // Label #[derive(Debug, Clone, Copy)] pub struct Label<'a> { @@ -956,9 +978,9 @@ impl<'a> AstNode<'a> for Module<'a> { impl<'a> ast::NameOwner<'a> for Module<'a> {} impl<'a> ast::AttrsOwner<'a> for Module<'a> {} -impl<'a> Module<'a> { - pub fn items(self) -> impl Iterator> + 'a { - super::children(self) +impl<'a> ast::FnDefOwner<'a> for Module<'a> {} +impl<'a> Module<'a> {pub fn item_list(self) -> Option> { + super::child_opt(self) } } @@ -1593,15 +1615,12 @@ impl<'a> AstNode<'a> for Root<'a> { fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } } +impl<'a> ast::FnDefOwner<'a> for Root<'a> {} impl<'a> Root<'a> { pub fn items(self) -> impl Iterator> + 'a { super::children(self) } - pub fn functions(self) -> impl Iterator> + 'a { - super::children(self) - } - pub fn modules(self) -> impl Iterator> + 'a { super::children(self) } 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> { } } +pub trait FnDefOwner<'a>: AstNode<'a> { + fn functions(self) -> Box> + 'a> { + Box::new(children(self)) + } +} + pub trait TypeParamsOwner<'a>: AstNode<'a> { fn type_param_list(self) -> Option> { 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( ], ast: { "Root": ( + traits: [ "FnDefOwner" ], collections: [ ["items", "ModuleItem"], - ["functions", "FnDef"], ["modules", "Module"], ] ), @@ -271,10 +271,11 @@ Grammar( ] ), "TraitDef": ( traits: ["NameOwner", "AttrsOwner"] ), "Module": ( - traits: ["NameOwner", "AttrsOwner"], - collections: [ - ["items", "ModuleItem"] - ] + traits: ["NameOwner", "AttrsOwner", "FnDefOwner" ], + options: [ "ItemList" ] + ), + "ItemList": ( + collections: [ ["items", "ModuleItem"] ] ), "ConstDef": ( traits: [ "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) { } const PAT_RECOVERY_SET: TokenSet = - token_set![LET_KW, IF_KW, WHILE_KW, LOOP_KW, MATCH_KW]; + token_set![LET_KW, IF_KW, WHILE_KW, LOOP_KW, MATCH_KW, R_PAREN, COMMA]; fn atom_pat(p: &mut Parser) -> Option { 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 = paths::PATH_FIRST, ]; +const TYPE_RECOVERY_SET: TokenSet = + token_set![R_PAREN, COMMA]; + pub(super) fn type_(p: &mut Parser) { match p.current() { L_PAREN => paren_or_tuple_type(p), @@ -23,7 +26,7 @@ pub(super) fn type_(p: &mut Parser) { L_ANGLE => path_type(p), _ if paths::is_path_start(p) => path_type(p), _ => { - p.err_and_bump("expected type"); + p.err_recover("expected type", TYPE_RECOVERY_SET); } } } -- cgit v1.2.3