Skip to content

Commit e395081

Browse files
committed
feat: support type instantiation expressions
1 parent fd577c4 commit e395081

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

grammar.js

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,11 +88,11 @@ module.exports = grammar({
8888

8989
conflicts: $ => [
9090
[$._simple_type, $._expression],
91+
[$._simple_type, $.generic_type, $._expression],
9192
[$.qualified_type, $._expression],
92-
[$.generic_type, $._expression],
9393
[$.generic_type, $._simple_type],
94+
[$.parameter_declaration, $._simple_type, $.generic_type, $._expression],
9495
[$.parameter_declaration, $._simple_type, $._expression],
95-
[$.parameter_declaration, $.generic_type, $._expression],
9696
[$.parameter_declaration, $._expression],
9797
[$.parameter_declaration, $._simple_type],
9898
],
@@ -304,10 +304,10 @@ module.exports = grammar({
304304
$.negated_type,
305305
),
306306

307-
generic_type: $ => seq(
307+
generic_type: $ => prec.dynamic(1, seq(
308308
field('type', choice($._type_identifier, $.qualified_type, $.union_type, $.negated_type)),
309309
field('type_arguments', $.type_arguments),
310-
),
310+
)),
311311

312312
type_arguments: $ => prec.dynamic(2, seq(
313313
'[',
@@ -665,6 +665,7 @@ module.exports = grammar({
665665
$.call_expression,
666666
$.type_assertion_expression,
667667
$.type_conversion_expression,
668+
$.type_instantiation_expression,
668669
$.identifier,
669670
alias(choice('new', 'make'), $.identifier),
670671
$.composite_literal,
@@ -771,6 +772,14 @@ module.exports = grammar({
771772
')',
772773
)),
773774

775+
type_instantiation_expression: $ => prec.dynamic(-1, seq(
776+
field('type', $._type),
777+
'[',
778+
commaSep1($._type),
779+
optional(','),
780+
']',
781+
)),
782+
774783
composite_literal: $ => prec(PREC.composite_literal, seq(
775784
field('type', choice(
776785
$.map_type,

0 commit comments

Comments
 (0)