File tree 3 files changed +78
-6
lines changed
3 files changed +78
-6
lines changed Original file line number Diff line number Diff line change @@ -91,6 +91,8 @@ module.exports = grammar({
91
91
[ $ . class_parameters ] ,
92
92
// 'for' operator_identifier ':' _annotated_type • ':' …
93
93
[ $ . _type , $ . compound_type ] ,
94
+ // 'given' '(' '[' _type_parameter • ',' …
95
+ [ $ . _variant_type_parameter , $ . type_lambda ] ,
94
96
// 'if' parenthesized_expression • '{' …
95
97
[ $ . _if_condition , $ . _simple_expression ] ,
96
98
// _postfix_expression_choice ':' '(' wildcard • ':' …
@@ -939,7 +941,10 @@ module.exports = grammar({
939
941
940
942
function_type : $ =>
941
943
prec . left (
942
- seq ( field ( "parameter_types" , $ . parameter_types ) , $ . _arrow_then_type ) ,
944
+ choice (
945
+ seq ( field ( "type_parameters" , $ . type_parameters ) , $ . _arrow_then_type ) ,
946
+ seq ( field ( "parameter_types" , $ . parameter_types ) , $ . _arrow_then_type ) ,
947
+ )
943
948
) ,
944
949
945
950
_arrow_then_type : $ =>
@@ -1104,6 +1109,15 @@ module.exports = grammar({
1104
1109
lambda_expression : $ =>
1105
1110
prec . right (
1106
1111
seq (
1112
+ optional (
1113
+ seq (
1114
+ field (
1115
+ "type_parameters" ,
1116
+ $ . type_parameters ,
1117
+ ) ,
1118
+ "=>" ,
1119
+ ) ,
1120
+ ) ,
1107
1121
field (
1108
1122
"parameters" ,
1109
1123
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 @@ -140,6 +140,32 @@ object Main {
140
140
(type_identifier)
141
141
(type_identifier)))))))
142
142
143
+ ================================================================================
144
+ Polymorphic function types (Scala 3 syntax)
145
+ ================================================================================
146
+
147
+ class A:
148
+ type Comparer = [X: Ord] => (X, X) => Boolean
149
+
150
+ --------------------------------------------------------------------------------
151
+
152
+ (compilation_unit
153
+ (class_definition
154
+ (identifier)
155
+ (template_body
156
+ (type_definition
157
+ (type_identifier)
158
+ (function_type
159
+ (type_parameters
160
+ (identifier)
161
+ (context_bound
162
+ (type_identifier)))
163
+ (function_type
164
+ (parameter_types
165
+ (type_identifier)
166
+ (type_identifier))
167
+ (type_identifier)))))))
168
+
143
169
================================================================================
144
170
Context function types (Scala 3 syntax)
145
171
================================================================================
You can’t perform that action at this time.
0 commit comments