Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions src/parser/event_parser/grammar/items.rs
Original file line number Diff line number Diff line change
@@ -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);
}
}
Expand Down Expand Up @@ -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);
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/parser/event_parser/grammar/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
9 changes: 9 additions & 0 deletions tests/data/parser/err/0007_stray_curly_in_file.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
}

struct S;

}

fn foo(){}

}
28 changes: 28 additions & 0 deletions tests/data/parser/err/0007_stray_curly_in_file.txt
Original file line number Diff line number Diff line change
@@ -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)