Skip to content

Commit 008991b

Browse files
committed
Create a separate higher-precedence '<' token for generics
Fixes #73
1 parent db0cc94 commit 008991b

File tree

4 files changed

+12227
-12108
lines changed

4 files changed

+12227
-12108
lines changed

corpus/types.txt

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,3 +211,27 @@ type c = A<&dyn Fn(&B) -> C>;
211211
(type_arguments
212212
(reference_type
213213
(dynamic_type (function_type (type_identifier) (parameters (reference_type (type_identifier))) (type_identifier))))))))
214+
215+
====================================
216+
Type cast expressions with generics
217+
====================================
218+
219+
a as B<C>;
220+
d as *mut E<<F as E>::G>;
221+
222+
---
223+
224+
(source_file
225+
(type_cast_expression
226+
(identifier)
227+
(generic_type (type_identifier) (type_arguments (type_identifier))))
228+
(type_cast_expression
229+
(identifier)
230+
(pointer_type
231+
(mutable_specifier)
232+
(generic_type
233+
(type_identifier)
234+
(type_arguments
235+
(scoped_type_identifier
236+
(bracketed_type (qualified_type (type_identifier) (type_identifier)))
237+
(type_identifier)))))))

grammar.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -606,7 +606,7 @@ module.exports = grammar({
606606
$.variadic_parameter,
607607
'_',
608608
$._type
609-
))),
609+
))),
610610
optional(','),
611611
')'
612612
),
@@ -652,7 +652,7 @@ module.exports = grammar({
652652
')'
653653
)),
654654
),
655-
)),
655+
)),
656656

657657
// Section - Types
658658

@@ -705,7 +705,7 @@ module.exports = grammar({
705705
for_lifetimes: $ => seq(
706706
'for',
707707
'<',
708-
sepBy1(',', $.lifetime,),
708+
sepBy1(',', $.lifetime),
709709
optional(','),
710710
'>'
711711
),
@@ -771,7 +771,7 @@ module.exports = grammar({
771771
)),
772772

773773
type_arguments: $ => seq(
774-
'<',
774+
token(prec(1, '<')),
775775
sepBy1(',', choice(
776776
$._type,
777777
$.type_binding,
@@ -943,7 +943,7 @@ module.exports = grammar({
943943
[PREC.bitand, '&'],
944944
[PREC.bitor, '|'],
945945
[PREC.bitxor, '^'],
946-
[PREC.comparative, choice('==', '!=', '<', '<=', '>', '>=')],
946+
[PREC.comparative, choice('==', '!=', '<', '<=', '>', '>=')],
947947
[PREC.shift, choice('<<', '>>')],
948948
[PREC.additive, choice('+', '-')],
949949
[PREC.multiplicative, choice('*', '/', '%')],

src/grammar.json

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4310,8 +4310,15 @@
43104310
"type": "SEQ",
43114311
"members": [
43124312
{
4313-
"type": "STRING",
4314-
"value": "<"
4313+
"type": "TOKEN",
4314+
"content": {
4315+
"type": "PREC",
4316+
"value": 1,
4317+
"content": {
4318+
"type": "STRING",
4319+
"value": "<"
4320+
}
4321+
}
43154322
},
43164323
{
43174324
"type": "SEQ",

0 commit comments

Comments
 (0)