diff options
author | Aleksey Kladov <[email protected]> | 2018-08-13 16:23:14 +0100 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2018-08-13 16:24:17 +0100 |
commit | 9149fd2c0ca3d23719082852a2cddd8ba5804ce6 (patch) | |
tree | f15d90dc80b6fd4d8e1bb966a171cb06a64cf9c0 /crates/libsyntax2 | |
parent | d1eceefeb8b683da3f64b89446f04f01803962e1 (diff) |
Fix some parser bugs
Diffstat (limited to 'crates/libsyntax2')
9 files changed, 213 insertions, 15 deletions
diff --git a/crates/libsyntax2/src/grammar/paths.rs b/crates/libsyntax2/src/grammar/paths.rs index c277e2a6b..aa5ecf4b8 100644 --- a/crates/libsyntax2/src/grammar/paths.rs +++ b/crates/libsyntax2/src/grammar/paths.rs | |||
@@ -62,7 +62,7 @@ fn path_segment(p: &mut Parser, mode: Mode, first: bool) { | |||
62 | } | 62 | } |
63 | SELF_KW | SUPER_KW => p.bump(), | 63 | SELF_KW | SUPER_KW => p.bump(), |
64 | _ => { | 64 | _ => { |
65 | p.error("expected identifier"); | 65 | p.err_and_bump("expected identifier"); |
66 | } | 66 | } |
67 | }; | 67 | }; |
68 | segment.complete(p, PATH_SEGMENT); | 68 | segment.complete(p, PATH_SEGMENT); |
diff --git a/crates/libsyntax2/src/grammar/patterns.rs b/crates/libsyntax2/src/grammar/patterns.rs index 436f3b26d..220f36db7 100644 --- a/crates/libsyntax2/src/grammar/patterns.rs +++ b/crates/libsyntax2/src/grammar/patterns.rs | |||
@@ -60,6 +60,7 @@ fn atom_pat(p: &mut Parser) -> Option<CompletedMarker> { | |||
60 | // let Bar(..) = (); | 60 | // let Bar(..) = (); |
61 | // } | 61 | // } |
62 | fn path_pat(p: &mut Parser) -> CompletedMarker { | 62 | fn path_pat(p: &mut Parser) -> CompletedMarker { |
63 | assert!(paths::is_path_start(p)); | ||
63 | let m = p.start(); | 64 | let m = p.start(); |
64 | paths::expr_path(p); | 65 | paths::expr_path(p); |
65 | let kind = match p.current() { | 66 | let kind = match p.current() { |
@@ -116,8 +117,11 @@ fn struct_pat_fields(p: &mut Parser) { | |||
116 | p.bump(); | 117 | p.bump(); |
117 | pattern(p); | 118 | pattern(p); |
118 | } | 119 | } |
119 | _ => { | 120 | REF_KW | MUT_KW | IDENT => { |
120 | bind_pat(p, false); | 121 | bind_pat(p, false); |
122 | }, | ||
123 | _ => { | ||
124 | p.err_and_bump("expected ident"); | ||
121 | } | 125 | } |
122 | } | 126 | } |
123 | if !p.at(R_CURLY) { | 127 | if !p.at(R_CURLY) { |
diff --git a/crates/libsyntax2/src/grammar/type_params.rs b/crates/libsyntax2/src/grammar/type_params.rs index 0a3e8fd07..32b69dc5b 100644 --- a/crates/libsyntax2/src/grammar/type_params.rs +++ b/crates/libsyntax2/src/grammar/type_params.rs | |||
@@ -121,7 +121,12 @@ fn where_predicate(p: &mut Parser) { | |||
121 | lifetime_bounds(p) | 121 | lifetime_bounds(p) |
122 | } else { | 122 | } else { |
123 | types::path_type(p); | 123 | types::path_type(p); |
124 | bounds(p); | 124 | if p.at(COLON) { |
125 | bounds(p); | ||
126 | } else { | ||
127 | p.error("expected colon") | ||
128 | } | ||
129 | |||
125 | } | 130 | } |
126 | m.complete(p, WHERE_PRED); | 131 | m.complete(p, WHERE_PRED); |
127 | } | 132 | } |
diff --git a/crates/libsyntax2/src/grammar/types.rs b/crates/libsyntax2/src/grammar/types.rs index 5ba3fcca0..88631fefe 100644 --- a/crates/libsyntax2/src/grammar/types.rs +++ b/crates/libsyntax2/src/grammar/types.rs | |||
@@ -166,8 +166,11 @@ fn fn_pointer_type(p: &mut Parser) { | |||
166 | p.error("expected `fn`"); | 166 | p.error("expected `fn`"); |
167 | return; | 167 | return; |
168 | } | 168 | } |
169 | 169 | if p.at(L_PAREN) { | |
170 | params::param_list_opt_patterns(p); | 170 | params::param_list_opt_patterns(p); |
171 | } else { | ||
172 | p.error("expected parameters") | ||
173 | } | ||
171 | // test fn_pointer_type_with_ret | 174 | // test fn_pointer_type_with_ret |
172 | // type F = fn() -> (); | 175 | // type F = fn() -> (); |
173 | fn_ret_type(p); | 176 | fn_ret_type(p); |
diff --git a/crates/libsyntax2/tests/data/parser/err/0004_use_path_bad_segment.txt b/crates/libsyntax2/tests/data/parser/err/0004_use_path_bad_segment.txt index c6ae68103..64aa07801 100644 --- a/crates/libsyntax2/tests/data/parser/err/0004_use_path_bad_segment.txt +++ b/crates/libsyntax2/tests/data/parser/err/0004_use_path_bad_segment.txt | |||
@@ -1,20 +1,16 @@ | |||
1 | FILE@[0; 12) | 1 | FILE@[0; 12) |
2 | USE_ITEM@[0; 9) | 2 | USE_ITEM@[0; 12) |
3 | USE_KW@[0; 3) | 3 | USE_KW@[0; 3) |
4 | WHITESPACE@[3; 4) | 4 | WHITESPACE@[3; 4) |
5 | USE_TREE@[4; 9) | 5 | USE_TREE@[4; 11) |
6 | PATH@[4; 9) | 6 | PATH@[4; 11) |
7 | PATH@[4; 7) | 7 | PATH@[4; 7) |
8 | PATH_SEGMENT@[4; 7) | 8 | PATH_SEGMENT@[4; 7) |
9 | NAME_REF@[4; 7) | 9 | NAME_REF@[4; 7) |
10 | IDENT@[4; 7) "foo" | 10 | IDENT@[4; 7) "foo" |
11 | COLONCOLON@[7; 9) | 11 | COLONCOLON@[7; 9) |
12 | err: `expected identifier` | 12 | err: `expected identifier` |
13 | err: `expected SEMI` | 13 | PATH_SEGMENT@[9; 11) |
14 | err: `expected an item` | 14 | ERROR@[9; 11) |
15 | PATH_SEGMENT@[9; 9) | 15 | INT_NUMBER@[9; 11) "92" |
16 | ERROR@[9; 11) | ||
17 | INT_NUMBER@[9; 11) "92" | ||
18 | err: `expected an item` | ||
19 | ERROR@[11; 12) | ||
20 | SEMI@[11; 12) | 16 | SEMI@[11; 12) |
diff --git a/crates/libsyntax2/tests/data/parser/err/0014_where_no_bounds.rs b/crates/libsyntax2/tests/data/parser/err/0014_where_no_bounds.rs new file mode 100644 index 000000000..75c1d2f98 --- /dev/null +++ b/crates/libsyntax2/tests/data/parser/err/0014_where_no_bounds.rs | |||
@@ -0,0 +1 @@ | |||
fn foo<T>() where T {} | |||
diff --git a/crates/libsyntax2/tests/data/parser/err/0014_where_no_bounds.txt b/crates/libsyntax2/tests/data/parser/err/0014_where_no_bounds.txt new file mode 100644 index 000000000..61444a88d --- /dev/null +++ b/crates/libsyntax2/tests/data/parser/err/0014_where_no_bounds.txt | |||
@@ -0,0 +1,31 @@ | |||
1 | FILE@[0; 23) | ||
2 | FUNCTION@[0; 22) | ||
3 | FN_KW@[0; 2) | ||
4 | WHITESPACE@[2; 3) | ||
5 | NAME@[3; 6) | ||
6 | IDENT@[3; 6) "foo" | ||
7 | TYPE_PARAM_LIST@[6; 9) | ||
8 | L_ANGLE@[6; 7) | ||
9 | TYPE_PARAM@[7; 8) | ||
10 | NAME@[7; 8) | ||
11 | IDENT@[7; 8) "T" | ||
12 | R_ANGLE@[8; 9) | ||
13 | PARAM_LIST@[9; 11) | ||
14 | L_PAREN@[9; 10) | ||
15 | R_PAREN@[10; 11) | ||
16 | WHITESPACE@[11; 12) | ||
17 | WHERE_CLAUSE@[12; 19) | ||
18 | WHERE_KW@[12; 17) | ||
19 | WHITESPACE@[17; 18) | ||
20 | WHERE_PRED@[18; 19) | ||
21 | PATH_TYPE@[18; 19) | ||
22 | PATH@[18; 19) | ||
23 | PATH_SEGMENT@[18; 19) | ||
24 | NAME_REF@[18; 19) | ||
25 | IDENT@[18; 19) "T" | ||
26 | err: `expected colon` | ||
27 | WHITESPACE@[19; 20) | ||
28 | BLOCK_EXPR@[20; 22) | ||
29 | L_CURLY@[20; 21) | ||
30 | R_CURLY@[21; 22) | ||
31 | WHITESPACE@[22; 23) | ||
diff --git a/crates/libsyntax2/tests/data/parser/ok/0030_traits.rs b/crates/libsyntax2/tests/data/parser/ok/0030_traits.rs new file mode 100644 index 000000000..23c4be0e1 --- /dev/null +++ b/crates/libsyntax2/tests/data/parser/ok/0030_traits.rs | |||
@@ -0,0 +1,11 @@ | |||
1 | pub trait WriteMessage { | ||
2 | fn write_message(&FrontendMessage); | ||
3 | } | ||
4 | |||
5 | trait Runnable { | ||
6 | fn handler(); | ||
7 | } | ||
8 | |||
9 | trait TraitWithExpr { | ||
10 | fn fn_with_expr(x: [i32; 1]); | ||
11 | } | ||
diff --git a/crates/libsyntax2/tests/data/parser/ok/0030_traits.txt b/crates/libsyntax2/tests/data/parser/ok/0030_traits.txt new file mode 100644 index 000000000..8abcb01e0 --- /dev/null +++ b/crates/libsyntax2/tests/data/parser/ok/0030_traits.txt | |||
@@ -0,0 +1,147 @@ | |||
1 | FILE@[0; 164) | ||
2 | TRAIT@[0; 164) | ||
3 | VISIBILITY@[0; 3) | ||
4 | PUB_KW@[0; 3) | ||
5 | WHITESPACE@[3; 4) | ||
6 | TRAIT_KW@[4; 9) | ||
7 | WHITESPACE@[9; 10) | ||
8 | NAME@[10; 22) | ||
9 | IDENT@[10; 22) "WriteMessage" | ||
10 | WHITESPACE@[22; 23) | ||
11 | L_CURLY@[23; 24) | ||
12 | WHITESPACE@[24; 29) | ||
13 | FUNCTION@[29; 164) | ||
14 | FN_KW@[29; 31) | ||
15 | WHITESPACE@[31; 32) | ||
16 | NAME@[32; 45) | ||
17 | IDENT@[32; 45) "write_message" | ||
18 | PARAM_LIST@[45; 164) | ||
19 | L_PAREN@[45; 46) | ||
20 | PARAM@[46; 63) | ||
21 | REF_PAT@[46; 62) | ||
22 | AMP@[46; 47) | ||
23 | BIND_PAT@[47; 62) | ||
24 | NAME@[47; 62) | ||
25 | IDENT@[47; 62) "FrontendMessage" | ||
26 | err: `expected COLON` | ||
27 | err: `expected type` | ||
28 | ERROR@[62; 63) | ||
29 | R_PAREN@[62; 63) | ||
30 | err: `expected COMMA` | ||
31 | err: `expected pattern` | ||
32 | PARAM@[63; 66) | ||
33 | ERROR@[63; 64) | ||
34 | SEMI@[63; 64) | ||
35 | err: `expected COLON` | ||
36 | WHITESPACE@[64; 65) | ||
37 | err: `expected type` | ||
38 | ERROR@[65; 66) | ||
39 | R_CURLY@[65; 66) | ||
40 | err: `expected COMMA` | ||
41 | WHITESPACE@[66; 68) | ||
42 | err: `expected pattern` | ||
43 | PARAM@[68; 82) | ||
44 | ERROR@[68; 73) | ||
45 | TRAIT_KW@[68; 73) | ||
46 | err: `expected COLON` | ||
47 | WHITESPACE@[73; 74) | ||
48 | PATH_TYPE@[74; 82) | ||
49 | PATH@[74; 82) | ||
50 | PATH_SEGMENT@[74; 82) | ||
51 | NAME_REF@[74; 82) | ||
52 | IDENT@[74; 82) "Runnable" | ||
53 | err: `expected COMMA` | ||
54 | WHITESPACE@[82; 83) | ||
55 | err: `expected pattern` | ||
56 | PARAM@[83; 91) | ||
57 | ERROR@[83; 84) | ||
58 | L_CURLY@[83; 84) | ||
59 | err: `expected COLON` | ||
60 | WHITESPACE@[84; 89) | ||
61 | FN_POINTER_TYPE@[89; 91) | ||
62 | FN_KW@[89; 91) | ||
63 | err: `expected parameters` | ||
64 | err: `expected COMMA` | ||
65 | WHITESPACE@[91; 92) | ||
66 | PARAM@[92; 102) | ||
67 | TUPLE_STRUCT_PAT@[92; 101) | ||
68 | PATH@[92; 99) | ||
69 | PATH_SEGMENT@[92; 99) | ||
70 | NAME_REF@[92; 99) | ||
71 | IDENT@[92; 99) "handler" | ||
72 | L_PAREN@[99; 100) | ||
73 | R_PAREN@[100; 101) | ||
74 | err: `expected COLON` | ||
75 | err: `expected type` | ||
76 | ERROR@[101; 102) | ||
77 | SEMI@[101; 102) | ||
78 | err: `expected COMMA` | ||
79 | WHITESPACE@[102; 103) | ||
80 | err: `expected pattern` | ||
81 | PARAM@[103; 111) | ||
82 | ERROR@[103; 104) | ||
83 | R_CURLY@[103; 104) | ||
84 | err: `expected COLON` | ||
85 | WHITESPACE@[104; 106) | ||
86 | err: `expected type` | ||
87 | ERROR@[106; 111) | ||
88 | TRAIT_KW@[106; 111) | ||
89 | err: `expected COMMA` | ||
90 | WHITESPACE@[111; 112) | ||
91 | PARAM@[112; 164) | ||
92 | STRUCT_PAT@[112; 163) | ||
93 | PATH@[112; 125) | ||
94 | PATH_SEGMENT@[112; 125) | ||
95 | NAME_REF@[112; 125) | ||
96 | IDENT@[112; 125) "TraitWithExpr" | ||
97 | WHITESPACE@[125; 126) | ||
98 | L_CURLY@[126; 127) | ||
99 | WHITESPACE@[127; 132) | ||
100 | err: `expected ident` | ||
101 | ERROR@[132; 134) | ||
102 | FN_KW@[132; 134) | ||
103 | err: `expected COMMA` | ||
104 | WHITESPACE@[134; 135) | ||
105 | BIND_PAT@[135; 147) | ||
106 | NAME@[135; 147) | ||
107 | IDENT@[135; 147) "fn_with_expr" | ||
108 | err: `expected COMMA` | ||
109 | err: `expected ident` | ||
110 | ERROR@[147; 148) | ||
111 | L_PAREN@[147; 148) | ||
112 | err: `expected COMMA` | ||
113 | IDENT@[148; 149) "x" | ||
114 | COLON@[149; 150) | ||
115 | WHITESPACE@[150; 151) | ||
116 | SLICE_PAT@[151; 159) | ||
117 | L_BRACK@[151; 152) | ||
118 | BIND_PAT@[152; 155) | ||
119 | NAME@[152; 155) | ||
120 | IDENT@[152; 155) "i32" | ||
121 | err: `expected COMMA` | ||
122 | err: `expected pattern` | ||
123 | ERROR@[155; 156) | ||
124 | SEMI@[155; 156) | ||
125 | err: `expected COMMA` | ||
126 | WHITESPACE@[156; 157) | ||
127 | LITERAL@[157; 158) | ||
128 | INT_NUMBER@[157; 158) "1" | ||
129 | R_BRACK@[158; 159) | ||
130 | err: `expected COMMA` | ||
131 | err: `expected ident` | ||
132 | ERROR@[159; 160) | ||
133 | R_PAREN@[159; 160) | ||
134 | err: `expected COMMA` | ||
135 | err: `expected ident` | ||
136 | ERROR@[160; 161) | ||
137 | SEMI@[160; 161) | ||
138 | WHITESPACE@[161; 162) | ||
139 | R_CURLY@[162; 163) | ||
140 | err: `expected COLON` | ||
141 | WHITESPACE@[163; 164) | ||
142 | err: `expected type` | ||
143 | err: `expected COMMA` | ||
144 | err: `expected R_PAREN` | ||
145 | err: `expected block` | ||
146 | err: `expected R_CURLY` | ||
147 | ERROR@[164; 164) | ||