File tree Expand file tree Collapse file tree 4 files changed +100
-0
lines changed
src/parser/event_parser/grammar Expand file tree Collapse file tree 4 files changed +100
-0
lines changed Original file line number Diff line number Diff line change @@ -36,8 +36,15 @@ fn item(p: &mut Parser) {
36
36
fn_item ( p) ;
37
37
FN_ITEM
38
38
}
39
+ L_CURLY => {
40
+ item. abandon ( p) ;
41
+ error_block ( p, "expected item" ) ;
42
+ return ;
43
+ }
39
44
err_token => {
40
45
item. abandon ( p) ;
46
+
47
+
41
48
let message = if err_token == SEMI {
42
49
//TODO: if the item is incomplete, this message is misleading
43
50
"expected item, found `;`\n \
Original file line number Diff line number Diff line change @@ -49,6 +49,25 @@ fn alias(p: &mut Parser) -> bool {
49
49
true //FIXME: return false if three are errors
50
50
}
51
51
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
+
52
71
impl < ' p > Parser < ' p > {
53
72
fn at < L : Lookahead > ( & self , l : L ) -> bool {
54
73
l. is_ahead ( self )
Original file line number Diff line number Diff line change
1
+ fn foo ( ) {
2
+ }
3
+
4
+ bar ( ) {
5
+ if true {
6
+ 1
7
+ } else {
8
+ 2 + 3
9
+ }
10
+ }
11
+
12
+ fn baz ( ) {
13
+ }
Original file line number Diff line number Diff line change
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)
You can’t perform that action at this time.
0 commit comments