From b61617f752668d1425133d0bf32d62dd1135c66a Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Mon, 8 Jan 2018 21:57:19 +0300 Subject: G: special-case C++ semicolon --- src/parser/event_parser/grammar/items.rs | 29 ++++++++++++++++++++++++++--- src/parser/event_parser/grammar/mod.rs | 7 +------ 2 files changed, 27 insertions(+), 9 deletions(-) (limited to 'src/parser/event_parser') diff --git a/src/parser/event_parser/grammar/items.rs b/src/parser/event_parser/grammar/items.rs index b9eb1934c..631eb4736 100644 --- a/src/parser/event_parser/grammar/items.rs +++ b/src/parser/event_parser/grammar/items.rs @@ -1,17 +1,40 @@ use super::*; -pub(super) fn item_first(p: &Parser) -> bool { +pub(super) fn mod_items(p: &mut Parser) { + many(p, |p| { + skip_to_first( + p, item_first, mod_item, + "expected item", + ) + }); +} + +fn item_first(p: &Parser) -> bool { match p.current() { STRUCT_KW | FN_KW => true, _ => false, } } -pub(super) fn item(p: &mut Parser) { +fn mod_item(p: &mut Parser) { + if item(p) { + if p.current() == SEMI { + node(p, ERROR, |p| { + p.error() + .message("expected item, found `;`\n\ + consider removing this semicolon") + .emit(); + p.bump(); + }) + } + } +} + +fn item(p: &mut Parser) -> bool { attributes::outer_attributes(p); visibility(p); node_if(p, STRUCT_KW, STRUCT_ITEM, struct_item) - || node_if(p, FN_KW, FN_ITEM, fn_item); + || node_if(p, FN_KW, FN_ITEM, fn_item) } fn struct_item(p: &mut Parser) { diff --git a/src/parser/event_parser/grammar/mod.rs b/src/parser/event_parser/grammar/mod.rs index b67ceeb13..274c2cdb4 100644 --- a/src/parser/event_parser/grammar/mod.rs +++ b/src/parser/event_parser/grammar/mod.rs @@ -11,12 +11,7 @@ pub(crate) fn file(p: &mut Parser) { node(p, FILE, |p| { p.optional(SHEBANG); attributes::inner_attributes(p); - many(p, |p| { - skip_to_first( - p, items::item_first, items::item, - "expected item", - ) - }); + items::mod_items(p); }) } -- cgit v1.2.3