Support single tick in SRTP constraints (#16)

* Support single tick in SRTP constraints

* Fix member constraint
pull/625/head
Vlad Zarytovskii 2023-04-23 13:10:08 +07:00 committed by GitHub
parent 65f9331a5f
commit b4053d740a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 194 additions and 12 deletions

@ -73,3 +73,97 @@ let inline private functionName x = 4
(identifier))))
body: (const
(int)))))
================================================================================
basic function with srt constraint (old-style, with ^)
================================================================================
let inline double<^a when ^a:(member Double: unit -> ^a)> (x: ^a) = x.Double()
--------------------------------------------------------------------------------
(file
(value_declaration
(function_or_value_defn
(function_declaration_left
(identifier)
(type_arguments
(type_argument_defn
(type_argument
(identifier)))
(type_argument_constraints
(constraint
(static_type_argument
(identifier))
(trait_member_constraint
(identifier)
(type
(type
(long_identifier
(identifier)))
(type
(type_argument
(identifier))))))))
(argument_patterns
(typed_pattern
(identifier_pattern
(long_identifier
(identifier)))
(type
(type_argument
(identifier))))))
(call_expression
(dot_expression
(long_identifier_or_op
(long_identifier
(identifier)))
(long_identifier_or_op
(long_identifier
(identifier))))))))
================================================================================
basic function with srt constraint (new-style, with ')
================================================================================
let inline double<'a when 'a:(member Double: unit -> 'a)> (x: 'a) = x.Double()
--------------------------------------------------------------------------------
(file
(value_declaration
(function_or_value_defn
(function_declaration_left
(identifier)
(type_arguments
(type_argument_defn
(type_argument
(identifier)))
(type_argument_constraints
(constraint
(static_type_argument
(identifier))
(trait_member_constraint
(identifier)
(type
(type
(long_identifier
(identifier)))
(type
(type_argument
(identifier))))))))
(argument_patterns
(typed_pattern
(identifier_pattern
(long_identifier
(identifier)))
(type
(type_argument
(identifier))))))
(call_expression
(dot_expression
(long_identifier_or_op
(long_identifier
(identifier)))
(long_identifier_or_op
(long_identifier
(identifier))))))))

@ -1016,7 +1016,7 @@ module.exports = grammar({
choice(
seq($.type_argument, ":>", $.type),
seq($.type_argument, ":", "null"),
seq($.static_type_argument, ":", "(", $.member_signature, ")"),
seq($.static_type_argument, ":", "(", $.trait_member_constraint, ")"),
seq($.type_argument, ":", "(", "new", ":", "unit", "->", "'T", ")"),
seq($.type_argument, ":", "struct"),
seq($.type_argument, ":", "not", "struct"),
@ -1049,8 +1049,8 @@ module.exports = grammar({
static_type_argument: $ =>
choice(
seq("^", $.identifier),
seq("^", $.identifier, repeat(seq("or", "^", $.identifier)))
seq(choice("^", "'"), $.identifier),
seq(choice("^", "'"), $.identifier, repeat(seq("or", choice("^", "'"), $.identifier)))
),
type_arguments: $ =>
@ -1062,6 +1062,15 @@ module.exports = grammar({
">"
),
trait_member_constraint: $ =>
seq(
optional("static"),
"member",
$.identifier,
':',
$.type
),
member_signature: $ =>
seq(
$.identifier,

@ -3407,7 +3407,7 @@
},
{
"type": "SYMBOL",
"name": "member_signature"
"name": "trait_member_constraint"
},
{
"type": "STRING",
@ -3705,8 +3705,17 @@
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "^"
"type": "CHOICE",
"members": [
{
"type": "STRING",
"value": "^"
},
{
"type": "STRING",
"value": "'"
}
]
},
{
"type": "SYMBOL",
@ -3718,8 +3727,17 @@
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "^"
"type": "CHOICE",
"members": [
{
"type": "STRING",
"value": "^"
},
{
"type": "STRING",
"value": "'"
}
]
},
{
"type": "SYMBOL",
@ -3735,8 +3753,17 @@
"value": "or"
},
{
"type": "STRING",
"value": "^"
"type": "CHOICE",
"members": [
{
"type": "STRING",
"value": "^"
},
{
"type": "STRING",
"value": "'"
}
]
},
{
"type": "SYMBOL",
@ -3798,6 +3825,39 @@
}
]
},
"trait_member_constraint": {
"type": "SEQ",
"members": [
{
"type": "CHOICE",
"members": [
{
"type": "STRING",
"value": "static"
},
{
"type": "BLANK"
}
]
},
{
"type": "STRING",
"value": "member"
},
{
"type": "SYMBOL",
"name": "identifier"
},
{
"type": "STRING",
"value": ":"
},
{
"type": "SYMBOL",
"name": "type"
}
]
},
"member_signature": {
"type": "SEQ",
"members": [

@ -1041,11 +1041,11 @@
"required": true,
"types": [
{
"type": "member_signature",
"type": "static_type_argument",
"named": true
},
{
"type": "static_type_argument",
"type": "trait_member_constraint",
"named": true
},
{
@ -2610,6 +2610,25 @@
"named": true,
"fields": {}
},
{
"type": "trait_member_constraint",
"named": true,
"fields": {},
"children": {
"multiple": true,
"required": true,
"types": [
{
"type": "identifier",
"named": true
},
{
"type": "type",
"named": true
}
]
}
},
{
"type": "triple_quoted_string",
"named": true,