Skip to content

Commit bb9ea5d

Browse files
committed
Merge #30
30: Skip over balanced parens r=matklad a=matklad
2 parents 4adf0c2 + 5004320 commit bb9ea5d

File tree

4 files changed

+98
-0
lines changed

4 files changed

+98
-0
lines changed

src/parser/event_parser/grammar/items.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ fn item(p: &mut Parser) {
3636
fn_item(p);
3737
FN_ITEM
3838
}
39+
L_CURLY => {
40+
item.abandon(p);
41+
error_block(p, "expected item");
42+
return;
43+
}
3944
err_token => {
4045
item.abandon(p);
4146
let message = if err_token == SEMI {

src/parser/event_parser/grammar/mod.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,25 @@ fn alias(p: &mut Parser) -> bool {
4949
true //FIXME: return false if three are errors
5050
}
5151

52+
fn error_block(p: &mut Parser, message: &str) {
53+
assert!(p.at(L_CURLY));
54+
let err = p.start();
55+
p.error()
56+
.message(message)
57+
.emit();
58+
p.bump();
59+
let mut level: u32 = 1;
60+
while level > 0 && !p.at(EOF) {
61+
match p.current() {
62+
L_CURLY => level += 1,
63+
R_CURLY => level -= 1,
64+
_ => (),
65+
}
66+
p.bump();
67+
}
68+
err.complete(p, ERROR);
69+
}
70+
5271
impl<'p> Parser<'p> {
5372
fn at<L: Lookahead>(&self, l: L) -> bool {
5473
l.is_ahead(self)
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
fn foo() {
2+
}
3+
4+
bar() {
5+
if true {
6+
1
7+
} else {
8+
2 + 3
9+
}
10+
}
11+
12+
fn baz() {
13+
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
FILE@[0; 95)
2+
FN_ITEM@[0; 14)
3+
FN_KW@[0; 2)
4+
WHITESPACE@[2; 3)
5+
IDENT@[3; 6)
6+
L_PAREN@[6; 7)
7+
R_PAREN@[7; 8)
8+
WHITESPACE@[8; 9)
9+
L_CURLY@[9; 10)
10+
WHITESPACE@[10; 11)
11+
R_CURLY@[11; 12)
12+
WHITESPACE@[12; 14)
13+
ERROR@[14; 17)
14+
err: `expected item`
15+
IDENT@[14; 17)
16+
ERROR@[17; 18)
17+
err: `expected item`
18+
L_PAREN@[17; 18)
19+
ERROR@[18; 20)
20+
err: `expected item`
21+
R_PAREN@[18; 19)
22+
WHITESPACE@[19; 20)
23+
ERROR@[20; 82)
24+
err: `expected item`
25+
L_CURLY@[20; 21)
26+
WHITESPACE@[21; 26)
27+
IDENT@[26; 28)
28+
WHITESPACE@[28; 29)
29+
TRUE_KW@[29; 33)
30+
WHITESPACE@[33; 34)
31+
L_CURLY@[34; 35)
32+
WHITESPACE@[35; 44)
33+
INT_NUMBER@[44; 45)
34+
WHITESPACE@[45; 50)
35+
R_CURLY@[50; 51)
36+
WHITESPACE@[51; 52)
37+
IDENT@[52; 56)
38+
WHITESPACE@[56; 57)
39+
L_CURLY@[57; 58)
40+
WHITESPACE@[58; 67)
41+
INT_NUMBER@[67; 68)
42+
WHITESPACE@[68; 69)
43+
PLUS@[69; 70)
44+
WHITESPACE@[70; 71)
45+
INT_NUMBER@[71; 72)
46+
WHITESPACE@[72; 77)
47+
R_CURLY@[77; 78)
48+
WHITESPACE@[78; 79)
49+
R_CURLY@[79; 80)
50+
WHITESPACE@[80; 82)
51+
FN_ITEM@[82; 95)
52+
FN_KW@[82; 84)
53+
WHITESPACE@[84; 85)
54+
IDENT@[85; 88)
55+
L_PAREN@[88; 89)
56+
R_PAREN@[89; 90)
57+
WHITESPACE@[90; 91)
58+
L_CURLY@[91; 92)
59+
WHITESPACE@[92; 93)
60+
R_CURLY@[93; 94)
61+
WHITESPACE@[94; 95)

0 commit comments

Comments
 (0)