aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/grammar.ron7
-rw-r--r--src/parser/grammar/type_args.rs24
-rw-r--r--src/syntax_kinds/generated.rs14
-rw-r--r--tests/data/parser/inline/0039_path_expr.txt11
-rw-r--r--tests/data/parser/inline/0058_type_arg.rs1
-rw-r--r--tests/data/parser/inline/0058_type_arg.txt39
6 files changed, 84 insertions, 12 deletions
diff --git a/src/grammar.ron b/src/grammar.ron
index e10e5aaf4..6c67db739 100644
--- a/src/grammar.ron
+++ b/src/grammar.ron
@@ -152,10 +152,13 @@ Grammar(
152 "LET_STMT", 152 "LET_STMT",
153 "EXPR_STMT", 153 "EXPR_STMT",
154 154
155 "TYPE_PARAM",
156 "LIFETIME_PARAM",
157 "TYPE_PARAM_LIST", 155 "TYPE_PARAM_LIST",
156 "LIFETIME_PARAM",
157 "TYPE_PARAM",
158 "TYPE_ARG_LIST", 158 "TYPE_ARG_LIST",
159 "LIFETIME_ARG",
160 "TYPE_ARG",
161 "ASSOC_TYPE_ARG",
159 162
160 "PARAM_LIST", 163 "PARAM_LIST",
161 "SELF_PARAM", 164 "SELF_PARAM",
diff --git a/src/parser/grammar/type_args.rs b/src/parser/grammar/type_args.rs
index adac73e7e..6b2217012 100644
--- a/src/parser/grammar/type_args.rs
+++ b/src/parser/grammar/type_args.rs
@@ -16,7 +16,7 @@ pub(super) fn list(p: &mut Parser, colon_colon_required: bool) {
16 }; 16 };
17 17
18 while !p.at(EOF) && !p.at(R_ANGLE) { 18 while !p.at(EOF) && !p.at(R_ANGLE) {
19 types::type_(p); 19 type_arg(p);
20 if !p.at(R_ANGLE) && !p.expect(COMMA) { 20 if !p.at(R_ANGLE) && !p.expect(COMMA) {
21 break; 21 break;
22 } 22 }
@@ -24,3 +24,25 @@ pub(super) fn list(p: &mut Parser, colon_colon_required: bool) {
24 p.expect(R_ANGLE); 24 p.expect(R_ANGLE);
25 m.complete(p, TYPE_ARG_LIST); 25 m.complete(p, TYPE_ARG_LIST);
26} 26}
27
28// test type_arg
29// type A = B<'static, i32, Item=u64>
30fn type_arg(p: &mut Parser) {
31 let m = p.start();
32 match p.current() {
33 LIFETIME => {
34 p.bump();
35 m.complete(p, LIFETIME_ARG);
36 },
37 IDENT if p.nth(1) == EQ => {
38 p.bump();
39 p.bump();
40 types::type_(p);
41 m.complete(p, ASSOC_TYPE_ARG);
42 },
43 _ => {
44 types::type_(p);
45 m.complete(p, TYPE_ARG);
46 },
47 }
48}
diff --git a/src/syntax_kinds/generated.rs b/src/syntax_kinds/generated.rs
index 0603f53fd..7c9333fc5 100644
--- a/src/syntax_kinds/generated.rs
+++ b/src/syntax_kinds/generated.rs
@@ -140,10 +140,13 @@ pub enum SyntaxKind {
140 BLOCK, 140 BLOCK,
141 LET_STMT, 141 LET_STMT,
142 EXPR_STMT, 142 EXPR_STMT,
143 TYPE_PARAM,
144 LIFETIME_PARAM,
145 TYPE_PARAM_LIST, 143 TYPE_PARAM_LIST,
144 LIFETIME_PARAM,
145 TYPE_PARAM,
146 TYPE_ARG_LIST, 146 TYPE_ARG_LIST,
147 LIFETIME_ARG,
148 TYPE_ARG,
149 ASSOC_TYPE_ARG,
147 PARAM_LIST, 150 PARAM_LIST,
148 SELF_PARAM, 151 SELF_PARAM,
149 ARG_LIST, 152 ARG_LIST,
@@ -294,10 +297,13 @@ impl SyntaxKind {
294 BLOCK => &SyntaxInfo { name: "BLOCK" }, 297 BLOCK => &SyntaxInfo { name: "BLOCK" },
295 LET_STMT => &SyntaxInfo { name: "LET_STMT" }, 298 LET_STMT => &SyntaxInfo { name: "LET_STMT" },
296 EXPR_STMT => &SyntaxInfo { name: "EXPR_STMT" }, 299 EXPR_STMT => &SyntaxInfo { name: "EXPR_STMT" },
297 TYPE_PARAM => &SyntaxInfo { name: "TYPE_PARAM" },
298 LIFETIME_PARAM => &SyntaxInfo { name: "LIFETIME_PARAM" },
299 TYPE_PARAM_LIST => &SyntaxInfo { name: "TYPE_PARAM_LIST" }, 300 TYPE_PARAM_LIST => &SyntaxInfo { name: "TYPE_PARAM_LIST" },
301 LIFETIME_PARAM => &SyntaxInfo { name: "LIFETIME_PARAM" },
302 TYPE_PARAM => &SyntaxInfo { name: "TYPE_PARAM" },
300 TYPE_ARG_LIST => &SyntaxInfo { name: "TYPE_ARG_LIST" }, 303 TYPE_ARG_LIST => &SyntaxInfo { name: "TYPE_ARG_LIST" },
304 LIFETIME_ARG => &SyntaxInfo { name: "LIFETIME_ARG" },
305 TYPE_ARG => &SyntaxInfo { name: "TYPE_ARG" },
306 ASSOC_TYPE_ARG => &SyntaxInfo { name: "ASSOC_TYPE_ARG" },
301 PARAM_LIST => &SyntaxInfo { name: "PARAM_LIST" }, 307 PARAM_LIST => &SyntaxInfo { name: "PARAM_LIST" },
302 SELF_PARAM => &SyntaxInfo { name: "SELF_PARAM" }, 308 SELF_PARAM => &SyntaxInfo { name: "SELF_PARAM" },
303 ARG_LIST => &SyntaxInfo { name: "ARG_LIST" }, 309 ARG_LIST => &SyntaxInfo { name: "ARG_LIST" },
diff --git a/tests/data/parser/inline/0039_path_expr.txt b/tests/data/parser/inline/0039_path_expr.txt
index 36a4ace6a..c3fc0c4bf 100644
--- a/tests/data/parser/inline/0039_path_expr.txt
+++ b/tests/data/parser/inline/0039_path_expr.txt
@@ -63,11 +63,12 @@ FILE@[0; 68)
63 TYPE_ARG_LIST@[59; 64) 63 TYPE_ARG_LIST@[59; 64)
64 COLONCOLON@[59; 61) 64 COLONCOLON@[59; 61)
65 L_ANGLE@[61; 62) 65 L_ANGLE@[61; 62)
66 PATH_TYPE@[62; 63) 66 TYPE_ARG@[62; 63)
67 PATH@[62; 63) 67 PATH_TYPE@[62; 63)
68 PATH_SEGMENT@[62; 63) 68 PATH@[62; 63)
69 NAME_REF@[62; 63) 69 PATH_SEGMENT@[62; 63)
70 IDENT@[62; 63) "b" 70 NAME_REF@[62; 63)
71 IDENT@[62; 63) "b"
71 R_ANGLE@[63; 64) 72 R_ANGLE@[63; 64)
72 SEMI@[64; 65) 73 SEMI@[64; 65)
73 WHITESPACE@[65; 66) 74 WHITESPACE@[65; 66)
diff --git a/tests/data/parser/inline/0058_type_arg.rs b/tests/data/parser/inline/0058_type_arg.rs
new file mode 100644
index 000000000..f0c8cc3a8
--- /dev/null
+++ b/tests/data/parser/inline/0058_type_arg.rs
@@ -0,0 +1 @@
type A = B<'static, i32, Item=u64>
diff --git a/tests/data/parser/inline/0058_type_arg.txt b/tests/data/parser/inline/0058_type_arg.txt
new file mode 100644
index 000000000..af4bcedef
--- /dev/null
+++ b/tests/data/parser/inline/0058_type_arg.txt
@@ -0,0 +1,39 @@
1FILE@[0; 35)
2 TYPE_ITEM@[0; 35)
3 TYPE_KW@[0; 4)
4 NAME@[4; 7)
5 WHITESPACE@[4; 5)
6 IDENT@[5; 6) "A"
7 WHITESPACE@[6; 7)
8 EQ@[7; 8)
9 PATH_TYPE@[8; 35)
10 PATH@[8; 35)
11 PATH_SEGMENT@[8; 35)
12 NAME_REF@[8; 10)
13 WHITESPACE@[8; 9)
14 IDENT@[9; 10) "B"
15 TYPE_ARG_LIST@[10; 35)
16 L_ANGLE@[10; 11)
17 LIFETIME_ARG@[11; 18)
18 LIFETIME@[11; 18) "'static"
19 COMMA@[18; 19)
20 TYPE_ARG@[19; 23)
21 PATH_TYPE@[19; 23)
22 PATH@[19; 23)
23 PATH_SEGMENT@[19; 23)
24 NAME_REF@[19; 23)
25 WHITESPACE@[19; 20)
26 IDENT@[20; 23) "i32"
27 COMMA@[23; 24)
28 ASSOC_TYPE_ARG@[24; 33)
29 WHITESPACE@[24; 25)
30 IDENT@[25; 29) "Item"
31 EQ@[29; 30)
32 PATH_TYPE@[30; 33)
33 PATH@[30; 33)
34 PATH_SEGMENT@[30; 33)
35 NAME_REF@[30; 33)
36 IDENT@[30; 33) "u64"
37 R_ANGLE@[33; 34)
38 WHITESPACE@[34; 35)
39 err: `expected SEMI`