@@ -77,6 +77,12 @@ export default grammar({
7777 [ $ . constant_pattern , $ . _name ] ,
7878 [ $ . constant_pattern , $ . lvalue_expression , $ . _name ] ,
7979
80+ [ $ . type , $ . _name_invocation_pattern , $ . recursive_pattern ] ,
81+ [ $ . attribute , $ . type , $ . _name_invocation_pattern , $ . recursive_pattern ] ,
82+ [ $ . attribute_argument , $ . argument , $ . _simple_name , $ . subpattern ] ,
83+
84+ [ $ . parenthesized_pattern , $ . _parenthesized_pattern_with_designation ] ,
85+
8086 [ $ . _reserved_identifier , $ . modifier ] ,
8187 [ $ . _reserved_identifier , $ . scoped_type ] ,
8288 [ $ . _reserved_identifier , $ . implicit_type ] ,
@@ -1142,6 +1148,8 @@ export default grammar({
11421148 $ . recursive_pattern ,
11431149 $ . var_pattern ,
11441150 $ . negated_pattern ,
1151+ // This must come before plain parenthesized_pattern to create GLR conflict
1152+ prec . dynamic ( 1 , alias ( $ . _parenthesized_pattern_with_designation , $ . recursive_pattern ) ) ,
11451153 $ . parenthesized_pattern ,
11461154 $ . relational_pattern ,
11471155 $ . or_pattern ,
@@ -1150,6 +1158,14 @@ export default grammar({
11501158 $ . type_pattern ,
11511159 ) ,
11521160
1161+ // Uses '(' pattern ')' to create direct conflict with parenthesized_pattern
1162+ _parenthesized_pattern_with_designation : $ => seq (
1163+ '(' ,
1164+ $ . pattern ,
1165+ ')' ,
1166+ $ . _variable_designation ,
1167+ ) ,
1168+
11531169 constant_pattern : $ => choice (
11541170 $ . binary_expression ,
11551171 $ . default_expression ,
@@ -1161,12 +1177,32 @@ export default grammar({
11611177 $ . tuple_expression ,
11621178 $ . typeof_expression ,
11631179 $ . member_access_expression ,
1164- $ . invocation_expression ,
1180+ alias ( $ . _name_invocation_pattern , $ . invocation_expression ) ,
1181+ alias ( $ . _complex_invocation_expression , $ . invocation_expression ) ,
11651182 $ . cast_expression ,
11661183 $ . _simple_name ,
11671184 $ . literal ,
11681185 ) ,
11691186
1187+ // Invocation with name - creates conflict with recursive_pattern's Name(positional_pattern_clause)
1188+ _name_invocation_pattern : $ => seq (
1189+ field ( 'function' , $ . _name ) ,
1190+ field ( 'arguments' , $ . argument_list ) ,
1191+ ) ,
1192+
1193+ // Invocation where function is not a simple name
1194+ _complex_invocation_expression : $ => prec ( PREC . INVOCATION , seq (
1195+ field ( 'function' , choice (
1196+ $ . member_access_expression ,
1197+ $ . element_access_expression ,
1198+ $ . invocation_expression ,
1199+ $ . parenthesized_expression ,
1200+ $ . conditional_access_expression ,
1201+ $ . cast_expression ,
1202+ ) ) ,
1203+ field ( 'arguments' , $ . argument_list ) ,
1204+ ) ) ,
1205+
11701206 discard : _ => '_' ,
11711207
11721208 parenthesized_pattern : $ => seq ( '(' , $ . pattern , ')' ) ,
@@ -1185,16 +1221,50 @@ export default grammar({
11851221 optional ( $ . _variable_designation ) ,
11861222 ) ) ,
11871223
1188- recursive_pattern : $ => prec . left ( seq (
1189- optional ( field ( 'type' , $ . type ) ) ,
1190- choice (
1191- seq (
1192- $ . positional_pattern_clause ,
1193- optional ( $ . property_pattern_clause ) ,
1224+ recursive_pattern : $ => prec . left ( choice (
1225+ // name followed by positional pattern WITH variable designation
1226+ prec . dynamic ( 1 , seq (
1227+ field ( 'type' , $ . _name ) ,
1228+ $ . positional_pattern_clause ,
1229+ optional ( $ . property_pattern_clause ) ,
1230+ $ . _variable_designation ,
1231+ ) ) ,
1232+ // name followed by positional pattern WITHOUT variable designation
1233+ prec . dynamic ( - 1 , seq (
1234+ field ( 'type' , $ . _name ) ,
1235+ $ . positional_pattern_clause ,
1236+ optional ( $ . property_pattern_clause ) ,
1237+ ) ) ,
1238+ // positional pattern with variable designation (no type prefix)
1239+ prec . dynamic ( 1 , seq (
1240+ $ . positional_pattern_clause ,
1241+ $ . _variable_designation ,
1242+ ) ) ,
1243+ // positional pattern without variable designation (no type prefix)
1244+ $ . positional_pattern_clause ,
1245+ // other type followed by pattern clauses (type is required here to avoid ambiguity)
1246+ seq (
1247+ field ( 'type' , $ . type ) ,
1248+ choice (
1249+ seq (
1250+ $ . positional_pattern_clause ,
1251+ optional ( $ . property_pattern_clause ) ,
1252+ ) ,
1253+ $ . property_pattern_clause ,
11941254 ) ,
1195- $ . property_pattern_clause ,
1255+ optional ( $ . _variable_designation ) ,
1256+ ) ,
1257+ // no type, just pattern clauses (no variable designation to avoid conflict with above)
1258+ seq (
1259+ choice (
1260+ seq (
1261+ $ . positional_pattern_clause ,
1262+ $ . property_pattern_clause ,
1263+ ) ,
1264+ $ . property_pattern_clause ,
1265+ ) ,
1266+ optional ( $ . _variable_designation ) ,
11961267 ) ,
1197- optional ( $ . _variable_designation ) ,
11981268 ) ) ,
11991269
12001270 positional_pattern_clause : $ => prec ( 1 , seq (
0 commit comments