File tree Expand file tree Collapse file tree 3 files changed +78
-6
lines changed Expand file tree Collapse file tree 3 files changed +78
-6
lines changed Original file line number Diff line number Diff line change @@ -92,6 +92,8 @@ module.exports = grammar({
92
92
[ $ . class_parameters ] ,
93
93
// 'for' operator_identifier ':' _annotated_type • ':' …
94
94
[ $ . _type , $ . compound_type ] ,
95
+ // 'given' '(' '[' _type_parameter • ',' …
96
+ [ $ . _variant_type_parameter , $ . type_lambda ] ,
95
97
// 'given' '(' operator_identifier ':' _type • ',' …
96
98
[ $ . name_and_type , $ . parameter ] ,
97
99
[ $ . _simple_expression , $ . binding , $ . tuple_pattern ] ,
@@ -984,7 +986,10 @@ module.exports = grammar({
984
986
985
987
function_type : $ =>
986
988
prec . left (
987
- seq ( field ( "parameter_types" , $ . parameter_types ) , $ . _arrow_then_type ) ,
989
+ choice (
990
+ seq ( field ( "type_parameters" , $ . type_parameters ) , $ . _arrow_then_type ) ,
991
+ seq ( field ( "parameter_types" , $ . parameter_types ) , $ . _arrow_then_type ) ,
992
+ )
988
993
) ,
989
994
990
995
_arrow_then_type : $ =>
@@ -1158,6 +1163,15 @@ module.exports = grammar({
1158
1163
lambda_expression : $ =>
1159
1164
prec . right (
1160
1165
seq (
1166
+ optional (
1167
+ seq (
1168
+ field (
1169
+ "type_parameters" ,
1170
+ $ . type_parameters ,
1171
+ ) ,
1172
+ "=>" ,
1173
+ ) ,
1174
+ ) ,
1161
1175
field (
1162
1176
"parameters" ,
1163
1177
choice (
Original file line number Diff line number Diff line change @@ -1116,7 +1116,6 @@ object O {
1116
1116
{ b =>
1117
1117
if (c) d.e }
1118
1118
{ a => implicit b => b }
1119
- { (a: Int) ?=> (b: Int) => b }
1120
1119
{ (_, a) => a }
1121
1120
}
1122
1121
@@ -1198,6 +1197,31 @@ object O {
1198
1197
(identifier)
1199
1198
(identifier))))
1200
1199
(block
1200
+ (lambda_expression
1201
+ (bindings
1202
+ (binding
1203
+ (wildcard))
1204
+ (binding
1205
+ (identifier)))
1206
+ (identifier))))))
1207
+
1208
+ ================================================================================
1209
+ Lambda Expression (Scala 3 syntax)
1210
+ ================================================================================
1211
+
1212
+ object O:
1213
+ val f = (a: Int) ?=> (b: Int) => b
1214
+
1215
+ val less: Comparer = [X: Ord] => (x: X, y: X) => ???
1216
+
1217
+ --------------------------------------------------------------------------------
1218
+
1219
+ (compilation_unit
1220
+ (object_definition
1221
+ (identifier)
1222
+ (template_body
1223
+ (val_definition
1224
+ (identifier)
1201
1225
(lambda_expression
1202
1226
(bindings
1203
1227
(binding
@@ -1209,14 +1233,22 @@ object O {
1209
1233
(identifier)
1210
1234
(type_identifier)))
1211
1235
(identifier))))
1212
- (block
1236
+ (val_definition
1237
+ (identifier)
1238
+ (type_identifier)
1213
1239
(lambda_expression
1240
+ (type_parameters
1241
+ (identifier)
1242
+ (context_bound
1243
+ (type_identifier)))
1214
1244
(bindings
1215
1245
(binding
1216
- (wildcard))
1246
+ (identifier)
1247
+ (type_identifier))
1217
1248
(binding
1218
- (identifier)))
1219
- (identifier))))))
1249
+ (identifier)
1250
+ (type_identifier)))
1251
+ (operator_identifier))))))
1220
1252
1221
1253
================================================================================
1222
1254
Unit expressions
Original file line number Diff line number Diff line change @@ -163,6 +163,32 @@ object Main {
163
163
(type_identifier)
164
164
(type_identifier)))))))
165
165
166
+ ================================================================================
167
+ Polymorphic function types (Scala 3 syntax)
168
+ ================================================================================
169
+
170
+ class A:
171
+ type Comparer = [X: Ord] => (X, X) => Boolean
172
+
173
+ --------------------------------------------------------------------------------
174
+
175
+ (compilation_unit
176
+ (class_definition
177
+ (identifier)
178
+ (template_body
179
+ (type_definition
180
+ (type_identifier)
181
+ (function_type
182
+ (type_parameters
183
+ (identifier)
184
+ (context_bound
185
+ (type_identifier)))
186
+ (function_type
187
+ (parameter_types
188
+ (type_identifier)
189
+ (type_identifier))
190
+ (type_identifier)))))))
191
+
166
192
================================================================================
167
193
Context function types (Scala 3 syntax)
168
194
================================================================================
You can’t perform that action at this time.
0 commit comments