From 83aa6f0899fa3d8de87389d789d0e330739d0117 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sun, 28 Jan 2018 12:57:03 +0300 Subject: [PATCH 1/2] Simplify item parsing --- src/parser/event_parser/grammar/items.rs | 9 ++++++--- src/parser/event_parser/grammar/mod.rs | 2 +- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/parser/event_parser/grammar/items.rs b/src/parser/event_parser/grammar/items.rs index e569e5047935..0638e3093f27 100644 --- a/src/parser/event_parser/grammar/items.rs +++ b/src/parser/event_parser/grammar/items.rs @@ -1,8 +1,8 @@ use super::*; -pub(super) fn mod_contents(p: &mut Parser) { +pub(super) fn mod_contents(p: &mut Parser, stop_on_r_curly: bool) { attributes::inner_attributes(p); - while !p.at(EOF) { + while !p.at(EOF) && !(stop_on_r_curly && p.at(R_CURLY)) { item(p); } } @@ -152,7 +152,10 @@ fn mod_item(p: &mut Parser) { p.bump(); if p.expect(IDENT) && !p.eat(SEMI) { - p.curly_block(mod_contents); + if p.expect(L_CURLY) { + mod_contents(p, true); + p.expect(R_CURLY); + } } } diff --git a/src/parser/event_parser/grammar/mod.rs b/src/parser/event_parser/grammar/mod.rs index 82f8b7f3e77c..b87f3ca8af5f 100644 --- a/src/parser/event_parser/grammar/mod.rs +++ b/src/parser/event_parser/grammar/mod.rs @@ -11,7 +11,7 @@ mod paths; pub(crate) fn file(p: &mut Parser) { let file = p.start(); p.eat(SHEBANG); - items::mod_contents(p); + items::mod_contents(p, false); file.complete(p, FILE); } From 0663c24222ebb2da10c26f690ad508e7b1fae8f9 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sun, 28 Jan 2018 13:01:39 +0300 Subject: [PATCH 2/2] Add recovery test --- .../parser/err/0007_stray_curly_in_file.rs | 9 ++++++ .../parser/err/0007_stray_curly_in_file.txt | 28 +++++++++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 tests/data/parser/err/0007_stray_curly_in_file.rs create mode 100644 tests/data/parser/err/0007_stray_curly_in_file.txt diff --git a/tests/data/parser/err/0007_stray_curly_in_file.rs b/tests/data/parser/err/0007_stray_curly_in_file.rs new file mode 100644 index 000000000000..dc869fb785ef --- /dev/null +++ b/tests/data/parser/err/0007_stray_curly_in_file.rs @@ -0,0 +1,9 @@ +} + +struct S; + +} + +fn foo(){} + +} diff --git a/tests/data/parser/err/0007_stray_curly_in_file.txt b/tests/data/parser/err/0007_stray_curly_in_file.txt new file mode 100644 index 000000000000..04bf17bc77e1 --- /dev/null +++ b/tests/data/parser/err/0007_stray_curly_in_file.txt @@ -0,0 +1,28 @@ +FILE@[0; 31) + ERROR@[0; 3) + err: `expected item` + R_CURLY@[0; 1) + WHITESPACE@[1; 3) + STRUCT_ITEM@[3; 14) + STRUCT_KW@[3; 9) + WHITESPACE@[9; 10) + IDENT@[10; 11) + SEMI@[11; 12) + WHITESPACE@[12; 14) + ERROR@[14; 17) + err: `expected item` + R_CURLY@[14; 15) + WHITESPACE@[15; 17) + FN_ITEM@[17; 29) + FN_KW@[17; 19) + WHITESPACE@[19; 20) + IDENT@[20; 23) + L_PAREN@[23; 24) + R_PAREN@[24; 25) + L_CURLY@[25; 26) + R_CURLY@[26; 27) + WHITESPACE@[27; 29) + ERROR@[29; 31) + err: `expected item` + R_CURLY@[29; 30) + WHITESPACE@[30; 31)