23: Simplify item parsing r=matklad a=matklad
This commit is contained in:
bors[bot] 2018-01-28 10:02:15 +00:00
commit 37ee4c4c2a
4 changed files with 44 additions and 4 deletions

View File

@ -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);
}
}
}

View File

@ -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);
}

View File

@ -0,0 +1,9 @@
}
struct S;
}
fn foo(){}
}

View File

@ -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)