diff options
-rw-r--r-- | src/grammar.ron | 1 | ||||
-rw-r--r-- | src/parser/grammar/items/traits.rs | 11 | ||||
-rw-r--r-- | src/parser/grammar/mod.rs | 24 | ||||
-rw-r--r-- | src/syntax_kinds/generated.rs | 2 | ||||
-rw-r--r-- | tests/data/parser/inline/0054_impl_item_items.rs | 6 | ||||
-rw-r--r-- | tests/data/parser/inline/0054_impl_item_items.txt | 77 | ||||
-rw-r--r-- | tests/data/parser/inline/0055_self_param.rs | 5 |
7 files changed, 126 insertions, 0 deletions
diff --git a/src/grammar.ron b/src/grammar.ron index fca29f1ef..e10e5aaf4 100644 --- a/src/grammar.ron +++ b/src/grammar.ron | |||
@@ -158,6 +158,7 @@ Grammar( | |||
158 | "TYPE_ARG_LIST", | 158 | "TYPE_ARG_LIST", |
159 | 159 | ||
160 | "PARAM_LIST", | 160 | "PARAM_LIST", |
161 | "SELF_PARAM", | ||
161 | "ARG_LIST", | 162 | "ARG_LIST", |
162 | ] | 163 | ] |
163 | ) | 164 | ) |
diff --git a/src/parser/grammar/items/traits.rs b/src/parser/grammar/items/traits.rs index 812cacfb7..7d657ced0 100644 --- a/src/parser/grammar/items/traits.rs +++ b/src/parser/grammar/items/traits.rs | |||
@@ -29,6 +29,17 @@ pub(super) fn impl_item(p: &mut Parser) { | |||
29 | } | 29 | } |
30 | type_params::where_clause(p); | 30 | type_params::where_clause(p); |
31 | p.expect(L_CURLY); | 31 | p.expect(L_CURLY); |
32 | |||
33 | // test impl_item_items | ||
34 | // impl F { | ||
35 | // type A = i32; | ||
36 | // const B: i32 = 92; | ||
37 | // fn foo() {} | ||
38 | // fn bar(&self) {} | ||
39 | // } | ||
40 | while !p.at(EOF) && !p.at(R_CURLY) { | ||
41 | item(p); | ||
42 | } | ||
32 | p.expect(R_CURLY); | 43 | p.expect(R_CURLY); |
33 | } | 44 | } |
34 | 45 | ||
diff --git a/src/parser/grammar/mod.rs b/src/parser/grammar/mod.rs index 498b45d44..b8847fb68 100644 --- a/src/parser/grammar/mod.rs +++ b/src/parser/grammar/mod.rs | |||
@@ -104,6 +104,7 @@ fn fn_value_parameters(p: &mut Parser) { | |||
104 | assert!(p.at(L_PAREN)); | 104 | assert!(p.at(L_PAREN)); |
105 | let m = p.start(); | 105 | let m = p.start(); |
106 | p.bump(); | 106 | p.bump(); |
107 | self_param(p); | ||
107 | while !p.at(EOF) && !p.at(R_PAREN) { | 108 | while !p.at(EOF) && !p.at(R_PAREN) { |
108 | value_parameter(p); | 109 | value_parameter(p); |
109 | if !p.at(R_PAREN) { | 110 | if !p.at(R_PAREN) { |
@@ -120,6 +121,29 @@ fn fn_value_parameters(p: &mut Parser) { | |||
120 | types::type_(p); | 121 | types::type_(p); |
121 | m.complete(p, VALUE_PARAMETER); | 122 | m.complete(p, VALUE_PARAMETER); |
122 | } | 123 | } |
124 | |||
125 | // test self_param | ||
126 | // impl S { | ||
127 | // fn a(self) {} | ||
128 | // fn b(&self,) {} | ||
129 | // fn c(&mut self, x: i32) {} | ||
130 | // } | ||
131 | fn self_param(p: &mut Parser) { | ||
132 | let la1 = p.nth(1); | ||
133 | let la2 = p.nth(2); | ||
134 | let n_toks = match (p.current(), la1, la2) { | ||
135 | (SELF_KW, _, _) => 1, | ||
136 | (AMPERSAND, SELF_KW, _) => 2, | ||
137 | (AMPERSAND, MUT_KW, SELF_KW) => 3, | ||
138 | _ => return, | ||
139 | }; | ||
140 | let m = p.start(); | ||
141 | for _ in 0..n_toks { p.bump(); } | ||
142 | m.complete(p, SELF_PARAM); | ||
143 | if !p.at(R_PAREN) { | ||
144 | p.expect(COMMA); | ||
145 | } | ||
146 | } | ||
123 | } | 147 | } |
124 | 148 | ||
125 | fn fn_ret_type(p: &mut Parser) { | 149 | fn fn_ret_type(p: &mut Parser) { |
diff --git a/src/syntax_kinds/generated.rs b/src/syntax_kinds/generated.rs index 699f5282e..0603f53fd 100644 --- a/src/syntax_kinds/generated.rs +++ b/src/syntax_kinds/generated.rs | |||
@@ -145,6 +145,7 @@ pub enum SyntaxKind { | |||
145 | TYPE_PARAM_LIST, | 145 | TYPE_PARAM_LIST, |
146 | TYPE_ARG_LIST, | 146 | TYPE_ARG_LIST, |
147 | PARAM_LIST, | 147 | PARAM_LIST, |
148 | SELF_PARAM, | ||
148 | ARG_LIST, | 149 | ARG_LIST, |
149 | // Technical SyntaxKinds: they appear temporally during parsing, | 150 | // Technical SyntaxKinds: they appear temporally during parsing, |
150 | // but never end up in the final tree | 151 | // but never end up in the final tree |
@@ -298,6 +299,7 @@ impl SyntaxKind { | |||
298 | TYPE_PARAM_LIST => &SyntaxInfo { name: "TYPE_PARAM_LIST" }, | 299 | TYPE_PARAM_LIST => &SyntaxInfo { name: "TYPE_PARAM_LIST" }, |
299 | TYPE_ARG_LIST => &SyntaxInfo { name: "TYPE_ARG_LIST" }, | 300 | TYPE_ARG_LIST => &SyntaxInfo { name: "TYPE_ARG_LIST" }, |
300 | PARAM_LIST => &SyntaxInfo { name: "PARAM_LIST" }, | 301 | PARAM_LIST => &SyntaxInfo { name: "PARAM_LIST" }, |
302 | SELF_PARAM => &SyntaxInfo { name: "SELF_PARAM" }, | ||
301 | ARG_LIST => &SyntaxInfo { name: "ARG_LIST" }, | 303 | ARG_LIST => &SyntaxInfo { name: "ARG_LIST" }, |
302 | TOMBSTONE => &SyntaxInfo { name: "TOMBSTONE" }, | 304 | TOMBSTONE => &SyntaxInfo { name: "TOMBSTONE" }, |
303 | EOF => &SyntaxInfo { name: "EOF" }, | 305 | EOF => &SyntaxInfo { name: "EOF" }, |
diff --git a/tests/data/parser/inline/0054_impl_item_items.rs b/tests/data/parser/inline/0054_impl_item_items.rs new file mode 100644 index 000000000..f10851487 --- /dev/null +++ b/tests/data/parser/inline/0054_impl_item_items.rs | |||
@@ -0,0 +1,6 @@ | |||
1 | impl F { | ||
2 | type A = i32; | ||
3 | const B: i32 = 92; | ||
4 | fn foo() {} | ||
5 | fn bar(&self) {} | ||
6 | } | ||
diff --git a/tests/data/parser/inline/0054_impl_item_items.txt b/tests/data/parser/inline/0054_impl_item_items.txt new file mode 100644 index 000000000..739f3d0f9 --- /dev/null +++ b/tests/data/parser/inline/0054_impl_item_items.txt | |||
@@ -0,0 +1,77 @@ | |||
1 | FILE@[0; 89) | ||
2 | IMPL_ITEM@[0; 89) | ||
3 | IMPL_KW@[0; 4) | ||
4 | PATH_TYPE@[4; 7) | ||
5 | PATH@[4; 7) | ||
6 | PATH_SEGMENT@[4; 7) | ||
7 | NAME_REF@[4; 7) | ||
8 | WHITESPACE@[4; 5) | ||
9 | IDENT@[5; 6) "F" | ||
10 | WHITESPACE@[6; 7) | ||
11 | L_CURLY@[7; 8) | ||
12 | TYPE_ITEM@[8; 31) | ||
13 | WHITESPACE@[8; 13) | ||
14 | TYPE_KW@[13; 17) | ||
15 | NAME@[17; 20) | ||
16 | WHITESPACE@[17; 18) | ||
17 | IDENT@[18; 19) "A" | ||
18 | WHITESPACE@[19; 20) | ||
19 | EQ@[20; 21) | ||
20 | PATH_TYPE@[21; 25) | ||
21 | PATH@[21; 25) | ||
22 | PATH_SEGMENT@[21; 25) | ||
23 | NAME_REF@[21; 25) | ||
24 | WHITESPACE@[21; 22) | ||
25 | IDENT@[22; 25) "i32" | ||
26 | SEMI@[25; 26) | ||
27 | WHITESPACE@[26; 31) | ||
28 | CONST_ITEM@[31; 54) | ||
29 | CONST_KW@[31; 36) | ||
30 | NAME@[36; 38) | ||
31 | WHITESPACE@[36; 37) | ||
32 | IDENT@[37; 38) "B" | ||
33 | COLON@[38; 39) | ||
34 | PATH_TYPE@[39; 44) | ||
35 | PATH@[39; 44) | ||
36 | PATH_SEGMENT@[39; 44) | ||
37 | NAME_REF@[39; 44) | ||
38 | WHITESPACE@[39; 40) | ||
39 | IDENT@[40; 43) "i32" | ||
40 | WHITESPACE@[43; 44) | ||
41 | EQ@[44; 45) | ||
42 | LITERAL@[45; 48) | ||
43 | WHITESPACE@[45; 46) | ||
44 | INT_NUMBER@[46; 48) | ||
45 | SEMI@[48; 49) | ||
46 | WHITESPACE@[49; 54) | ||
47 | FN_ITEM@[54; 70) | ||
48 | FN_KW@[54; 56) | ||
49 | NAME@[56; 60) | ||
50 | WHITESPACE@[56; 57) | ||
51 | IDENT@[57; 60) "foo" | ||
52 | PARAM_LIST@[60; 63) | ||
53 | L_PAREN@[60; 61) | ||
54 | R_PAREN@[61; 62) | ||
55 | WHITESPACE@[62; 63) | ||
56 | BLOCK@[63; 70) | ||
57 | L_CURLY@[63; 64) | ||
58 | R_CURLY@[64; 65) | ||
59 | WHITESPACE@[65; 70) | ||
60 | FN_ITEM@[70; 87) | ||
61 | FN_KW@[70; 72) | ||
62 | NAME@[72; 76) | ||
63 | WHITESPACE@[72; 73) | ||
64 | IDENT@[73; 76) "bar" | ||
65 | PARAM_LIST@[76; 84) | ||
66 | L_PAREN@[76; 77) | ||
67 | SELF_PARAM@[77; 82) | ||
68 | AMPERSAND@[77; 78) | ||
69 | SELF_KW@[78; 82) | ||
70 | R_PAREN@[82; 83) | ||
71 | WHITESPACE@[83; 84) | ||
72 | BLOCK@[84; 87) | ||
73 | L_CURLY@[84; 85) | ||
74 | R_CURLY@[85; 86) | ||
75 | WHITESPACE@[86; 87) | ||
76 | R_CURLY@[87; 88) | ||
77 | WHITESPACE@[88; 89) | ||
diff --git a/tests/data/parser/inline/0055_self_param.rs b/tests/data/parser/inline/0055_self_param.rs new file mode 100644 index 000000000..2890c27e2 --- /dev/null +++ b/tests/data/parser/inline/0055_self_param.rs | |||
@@ -0,0 +1,5 @@ | |||
1 | impl S { | ||
2 | fn a(self) {} | ||
3 | fn b(&self,) {} | ||
4 | fn c(&mut self, x: i32) {} | ||
5 | } | ||