From 1544e89c49c67df00fc72d841f3e39be792cbe2b Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 9 Jan 2018 22:35:55 +0300 Subject: G: mod item --- src/parser/event_parser/grammar/items.rs | 21 ++++++++++++++++----- src/parser/event_parser/grammar/mod.rs | 3 +-- 2 files changed, 17 insertions(+), 7 deletions(-) (limited to 'src/parser/event_parser/grammar') diff --git a/src/parser/event_parser/grammar/items.rs b/src/parser/event_parser/grammar/items.rs index 9b174679c..e775db14b 100644 --- a/src/parser/event_parser/grammar/items.rs +++ b/src/parser/event_parser/grammar/items.rs @@ -1,9 +1,10 @@ use super::*; -pub(super) fn mod_items(p: &mut Parser) { +pub(super) fn mod_contents(p: &mut Parser) { + attributes::inner_attributes(p); many(p, |p| { skip_to_first( - p, item_first, mod_item, + p, item_first, mod_contents_item, "expected item", ) }); @@ -11,12 +12,12 @@ pub(super) fn mod_items(p: &mut Parser) { fn item_first(p: &Parser) -> bool { match p.current() { - STRUCT_KW | FN_KW | EXTERN_KW => true, + STRUCT_KW | FN_KW | EXTERN_KW | MOD_KW => true, _ => false, } } -fn mod_item(p: &mut Parser) { +fn mod_contents_item(p: &mut Parser) { if item(p) { if p.current() == SEMI { node(p, ERROR, |p| { @@ -39,9 +40,9 @@ fn item(p: &mut Parser) -> bool { // || node_if(p, CONST_KW, CONST_ITEM, const_item) or const FN! // || unsafe trait, impl // || node_if(p, FN_KW, FN_ITEM, fn_item) - // || node_if(p, MOD_KW, MOD_ITEM, mod_item) // || node_if(p, TYPE_KW, TYPE_ITEM, type_item) node_if(p, [EXTERN_KW, CRATE_KW], EXTERN_CRATE_ITEM, extern_crate_item) + || node_if(p, MOD_KW, MOD_ITEM, mod_item) || node_if(p, STRUCT_KW, STRUCT_ITEM, struct_item) || node_if(p, FN_KW, FN_ITEM, fn_item) } @@ -55,6 +56,16 @@ fn extern_crate_item(p: &mut Parser) { p.expect(IDENT) && alias(p) && p.expect(SEMI); } +fn mod_item(p: &mut Parser) { + if !p.expect(IDENT) { + return; + } + if p.eat(SEMI) { + return; + } + p.curly_block(mod_contents); +} + fn struct_field(p: &mut Parser) -> bool { node_if(p, IDENT, STRUCT_FIELD, |p| { p.expect(COLON) && p.expect(IDENT); diff --git a/src/parser/event_parser/grammar/mod.rs b/src/parser/event_parser/grammar/mod.rs index dd1270eae..6d1cd7ec3 100644 --- a/src/parser/event_parser/grammar/mod.rs +++ b/src/parser/event_parser/grammar/mod.rs @@ -10,8 +10,7 @@ mod expressions; pub(crate) fn file(p: &mut Parser) { node(p, FILE, |p| { p.optional(SHEBANG); - attributes::inner_attributes(p); - items::mod_items(p); + items::mod_contents(p); }) } -- cgit v1.2.3