Differentiate concrete types from type constructors

pull/204/head
Jonathan Arnett 2021-12-17 01:51:25 +07:00
parent 62672649b0
commit 71c1660942
7 changed files with 2738 additions and 2492 deletions

@ -25,24 +25,24 @@ const a = uri.Uri(host: "github.com")
value: (string))
(constant
name: (identifier)
type: (type_constructor)
type: (type)
value: (integer))
(constant
name: (identifier)
type: (type_constructor)
type: (type)
value: (float))
(constant
name: (identifier)
type: (tuple_type
(type_constructor)
(type_constructor))
(type)
(type))
value: (tuple
(integer)
(string)))
(constant
name: (identifier)
type: (type_constructor
(type_constructor))
(type))
value: (list
(integer)
(integer)))
@ -131,24 +131,24 @@ pub const a = uri.Uri(host: "github.com")
value: (string))
(public_constant
name: (identifier)
type: (type_constructor)
type: (type)
value: (integer))
(public_constant
name: (identifier)
type: (type_constructor)
type: (type)
value: (float))
(public_constant
name: (identifier)
type: (tuple_type
(type_constructor)
(type_constructor))
(type)
(type))
value: (tuple
(integer)
(string)))
(public_constant
name: (identifier)
type: (type_constructor
(type_constructor))
(type))
value: (list
(integer)
(integer)))

@ -14,10 +14,10 @@ external fn a() -> #(List(Int), fn(Int) -> String) = "x" "y"
name: (function_name)
parameters: (external_function_parameters
(external_function_parameter
type: (type_constructor)))
type: (type)))
return_type: (type_constructor
(type_constructor)
(type_constructor))
(type)
(type))
body: (external_function_body
(string)
(string)))
@ -26,8 +26,8 @@ external fn a() -> #(List(Int), fn(Int) -> String) = "x" "y"
parameters: (external_function_parameters
(external_function_parameter
name: (identifier)
type: (type_constructor)))
return_type: (type_constructor)
type: (type)))
return_type: (type)
body: (external_function_body
(string)
(string)))
@ -35,11 +35,11 @@ external fn a() -> #(List(Int), fn(Int) -> String) = "x" "y"
name: (function_name)
return_type: (tuple_type
(type_constructor
(type_constructor))
(type))
(function_type
parameter_types: (function_parameter_types
(type_constructor))
return_type: (type_constructor)))
(type))
return_type: (type)))
body: (external_function_body
(string)
(string))))
@ -60,10 +60,10 @@ pub external fn a() -> #(List(Int), fn(Int) -> String) = "x" "y"
name: (function_name)
parameters: (external_function_parameters
(external_function_parameter
type: (type_constructor)))
type: (type)))
return_type: (type_constructor
(type_constructor)
(type_constructor))
(type)
(type))
body: (external_function_body
(string)
(string)))
@ -72,8 +72,8 @@ pub external fn a() -> #(List(Int), fn(Int) -> String) = "x" "y"
parameters: (external_function_parameters
(external_function_parameter
name: (identifier)
type: (type_constructor)))
return_type: (type_constructor)
type: (type)))
return_type: (type)
body: (external_function_body
(string)
(string)))
@ -81,11 +81,11 @@ pub external fn a() -> #(List(Int), fn(Int) -> String) = "x" "y"
name: (function_name)
return_type: (tuple_type
(type_constructor
(type_constructor))
(type))
(function_type
parameter_types: (function_parameter_types
(type_constructor))
return_type: (type_constructor)))
(type))
return_type: (type)))
body: (external_function_body
(string)
(string))))

@ -19,11 +19,11 @@ fn replace(
parameters: (function_parameters
(function_parameter
name: (identifier)
type: (type_constructor))
type: (type))
(function_parameter
name: (identifier)
type: (type_constructor)))
return_type: (type_constructor))
type: (type)))
return_type: (type))
(function
name: (identifier)
parameters: (function_parameters
@ -48,12 +48,12 @@ fn replace(
(function_parameter
label: (identifier)
name: (identifier)
type: (type_constructor))
type: (type))
(function_parameter
label: (identifier)
name: (identifier)
type: (type_constructor))
type: (type))
(function_parameter
label: (identifier)
name: (identifier)
type: (type_constructor)))))
type: (type)))))

@ -161,19 +161,28 @@ module.exports = grammar({
choice(
$.type_hole,
alias($.constant_tuple_type, $.tuple_type),
alias($.constant_type_constructor, $.type_constructor),
alias($.constant_remote_type_constructor, $.remote_type_constructor)
$._constant_type_name,
$._constant_remote_type_name
),
constant_tuple_type: ($) =>
seq("#", "(", optional(series_of($._constant_type, ",")), ")"),
constant_type_constructor: ($) => $._constant_type_constructor,
constant_remote_type_constructor: ($) =>
seq($._name, ".", $._constant_type_constructor),
_constant_type_constructor: ($) =>
_constant_type_name: ($) =>
choice(
alias($.constant_type_constructor, $.type_constructor),
alias($.constant_type, $.type)
),
_constant_remote_type_name: ($) =>
seq(
$._upname,
optional(seq("(", optional(series_of($._constant_type, ",")), ")"))
$._name,
".",
choice(
alias($.constant_type_constructor, $.remote_type_constructor),
alias($.constant_type, $.remote_type)
)
),
constant_type_constructor: ($) =>
seq($._upname, "(", optional(series_of($._constant_type, ",")), ")"),
constant_type: ($) => $._upname,
/* External types */
public_external_type: ($) => seq("pub", $._external_type),
@ -309,8 +318,8 @@ module.exports = grammar({
$.type_hole,
$.tuple_type,
$.function_type,
$.type_constructor,
$.remote_type_constructor,
$._type_name,
$._remote_type_name,
$.type_var
),
_type_annotation: ($) => seq(":", field("type", $._type)),
@ -326,13 +335,19 @@ module.exports = grammar({
field("return_type", $._type)
),
function_parameter_types: ($) => series_of($._type, ","),
type_constructor: ($) => $._type_constructor,
remote_type_constructor: ($) => seq($._name, ".", $._type_constructor),
_type_constructor: ($) =>
_type_name: ($) => choice($.type_constructor, $.type),
_remote_type_name: ($) =>
seq(
$._upname,
optional(seq("(", optional(series_of($._type, ",")), ")"))
$._name,
".",
choice(
alias($.type_constructor, $.remote_type_constructor),
alias($.type, $.remote_type)
)
),
type_constructor: ($) =>
seq($._upname, seq("(", optional(series_of($._type, ",")), ")")),
type: ($) => $._upname,
type_var: ($) => $._name,
/* Common alias becomes a real boy */

@ -932,22 +932,12 @@
"value": "tuple_type"
},
{
"type": "ALIAS",
"content": {
"type": "SYMBOL",
"name": "constant_type_constructor"
},
"named": true,
"value": "type_constructor"
"type": "SYMBOL",
"name": "_constant_type_name"
},
{
"type": "ALIAS",
"content": {
"type": "SYMBOL",
"name": "constant_remote_type_constructor"
},
"named": true,
"value": "remote_type_constructor"
"type": "SYMBOL",
"name": "_constant_remote_type_name"
}
]
},
@ -1001,11 +991,30 @@
}
]
},
"constant_type_constructor": {
"type": "SYMBOL",
"name": "_constant_type_constructor"
"_constant_type_name": {
"type": "CHOICE",
"members": [
{
"type": "ALIAS",
"content": {
"type": "SYMBOL",
"name": "constant_type_constructor"
},
"named": true,
"value": "type_constructor"
},
{
"type": "ALIAS",
"content": {
"type": "SYMBOL",
"name": "constant_type"
},
"named": true,
"value": "type"
}
]
},
"constant_remote_type_constructor": {
"_constant_remote_type_name": {
"type": "SEQ",
"members": [
{
@ -1017,18 +1026,41 @@
"value": "."
},
{
"type": "SYMBOL",
"name": "_constant_type_constructor"
"type": "CHOICE",
"members": [
{
"type": "ALIAS",
"content": {
"type": "SYMBOL",
"name": "constant_type_constructor"
},
"named": true,
"value": "remote_type_constructor"
},
{
"type": "ALIAS",
"content": {
"type": "SYMBOL",
"name": "constant_type"
},
"named": true,
"value": "remote_type"
}
]
}
]
},
"_constant_type_constructor": {
"constant_type_constructor": {
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "_upname"
},
{
"type": "STRING",
"value": "("
},
{
"type": "CHOICE",
"members": [
@ -1036,45 +1068,24 @@
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "("
},
{
"type": "CHOICE",
"members": [
{
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "_constant_type"
},
{
"type": "REPEAT",
"content": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": ","
},
{
"type": "SYMBOL",
"name": "_constant_type"
}
]
}
}
]
},
{
"type": "BLANK"
}
]
"type": "SYMBOL",
"name": "_constant_type"
},
{
"type": "STRING",
"value": ")"
"type": "REPEAT",
"content": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": ","
},
{
"type": "SYMBOL",
"name": "_constant_type"
}
]
}
}
]
},
@ -1082,9 +1093,17 @@
"type": "BLANK"
}
]
},
{
"type": "STRING",
"value": ")"
}
]
},
"constant_type": {
"type": "SYMBOL",
"name": "_upname"
},
"public_external_type": {
"type": "SEQ",
"members": [
@ -2025,11 +2044,11 @@
},
{
"type": "SYMBOL",
"name": "type_constructor"
"name": "_type_name"
},
{
"type": "SYMBOL",
"name": "remote_type_constructor"
"name": "_remote_type_name"
},
{
"type": "SYMBOL",
@ -2178,11 +2197,20 @@
}
]
},
"type_constructor": {
"type": "SYMBOL",
"name": "_type_constructor"
"_type_name": {
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "type_constructor"
},
{
"type": "SYMBOL",
"name": "type"
}
]
},
"remote_type_constructor": {
"_remote_type_name": {
"type": "SEQ",
"members": [
{
@ -2194,12 +2222,31 @@
"value": "."
},
{
"type": "SYMBOL",
"name": "_type_constructor"
"type": "CHOICE",
"members": [
{
"type": "ALIAS",
"content": {
"type": "SYMBOL",
"name": "type_constructor"
},
"named": true,
"value": "remote_type_constructor"
},
{
"type": "ALIAS",
"content": {
"type": "SYMBOL",
"name": "type"
},
"named": true,
"value": "remote_type"
}
]
}
]
},
"_type_constructor": {
"type_constructor": {
"type": "SEQ",
"members": [
{
@ -2207,65 +2254,65 @@
"name": "_upname"
},
{
"type": "CHOICE",
"type": "SEQ",
"members": [
{
"type": "SEQ",
"type": "STRING",
"value": "("
},
{
"type": "CHOICE",
"members": [
{
"type": "STRING",
"value": "("
},
{
"type": "CHOICE",
"type": "SEQ",
"members": [
{
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "_type"
},
{
"type": "REPEAT",
"content": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": ","
},
{
"type": "SYMBOL",
"name": "_type"
}
]
}
}
]
"type": "SYMBOL",
"name": "_type"
},
{
"type": "BLANK"
"type": "REPEAT",
"content": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": ","
},
{
"type": "SYMBOL",
"name": "_type"
}
]
}
}
]
},
{
"type": "STRING",
"value": ")"
"type": "BLANK"
}
]
},
{
"type": "BLANK"
"type": "STRING",
"value": ")"
}
]
}
]
},
"type": {
"type": "SYMBOL",
"name": "_upname"
},
"type_var": {
"type": "SYMBOL",
"name": "_name"
},
"identifier": {
"type": "SYMBOL",
"name": "_name"
},
"_discard_name": {
"type": "PATTERN",
"value": "_[_0-9a-z]*"
@ -2277,10 +2324,6 @@
"_upname": {
"type": "PATTERN",
"value": "[A-Z][0-9a-zA-Z]*"
},
"identifier": {
"type": "SYMBOL",
"name": "_name"
}
},
"extras": [

@ -288,9 +288,17 @@
]
},
"type": {
"multiple": false,
"multiple": true,
"required": false,
"types": [
{
"type": ".",
"named": false
},
{
"type": "remote_type",
"named": true
},
{
"type": "remote_type_constructor",
"named": true
@ -299,6 +307,10 @@
"type": "tuple_type",
"named": true
},
{
"type": "type",
"named": true
},
{
"type": "type_constructor",
"named": true
@ -384,13 +396,21 @@
]
},
"return_type": {
"multiple": false,
"multiple": true,
"required": true,
"types": [
{
"type": ".",
"named": false
},
{
"type": "function_type",
"named": true
},
{
"type": "remote_type",
"named": true
},
{
"type": "remote_type_constructor",
"named": true
@ -399,6 +419,10 @@
"type": "tuple_type",
"named": true
},
{
"type": "type",
"named": true
},
{
"type": "type_constructor",
"named": true
@ -445,13 +469,21 @@
]
},
"type": {
"multiple": false,
"multiple": true,
"required": true,
"types": [
{
"type": ".",
"named": false
},
{
"type": "function_type",
"named": true
},
{
"type": "remote_type",
"named": true
},
{
"type": "remote_type_constructor",
"named": true
@ -460,6 +492,10 @@
"type": "tuple_type",
"named": true
},
{
"type": "type",
"named": true
},
{
"type": "type_constructor",
"named": true
@ -565,13 +601,21 @@
]
},
"return_type": {
"multiple": false,
"multiple": true,
"required": false,
"types": [
{
"type": ".",
"named": false
},
{
"type": "function_type",
"named": true
},
{
"type": "remote_type",
"named": true
},
{
"type": "remote_type_constructor",
"named": true
@ -580,6 +624,10 @@
"type": "tuple_type",
"named": true
},
{
"type": "type",
"named": true
},
{
"type": "type_constructor",
"named": true
@ -621,13 +669,21 @@
]
},
"type": {
"multiple": false,
"multiple": true,
"required": false,
"types": [
{
"type": ".",
"named": false
},
{
"type": "function_type",
"named": true
},
{
"type": "remote_type",
"named": true
},
{
"type": "remote_type_constructor",
"named": true
@ -636,6 +692,10 @@
"type": "tuple_type",
"named": true
},
{
"type": "type",
"named": true
},
{
"type": "type_constructor",
"named": true
@ -664,6 +724,10 @@
"type": "function_type",
"named": true
},
{
"type": "remote_type",
"named": true
},
{
"type": "remote_type_constructor",
"named": true
@ -672,6 +736,10 @@
"type": "tuple_type",
"named": true
},
{
"type": "type",
"named": true
},
{
"type": "type_constructor",
"named": true
@ -717,13 +785,21 @@
]
},
"return_type": {
"multiple": false,
"multiple": true,
"required": true,
"types": [
{
"type": ".",
"named": false
},
{
"type": "function_type",
"named": true
},
{
"type": "remote_type",
"named": true
},
{
"type": "remote_type_constructor",
"named": true
@ -732,6 +808,10 @@
"type": "tuple_type",
"named": true
},
{
"type": "type",
"named": true
},
{
"type": "type_constructor",
"named": true
@ -852,9 +932,17 @@
]
},
"type": {
"multiple": false,
"multiple": true,
"required": false,
"types": [
{
"type": ".",
"named": false
},
{
"type": "remote_type",
"named": true
},
{
"type": "remote_type_constructor",
"named": true
@ -863,6 +951,10 @@
"type": "tuple_type",
"named": true
},
{
"type": "type",
"named": true
},
{
"type": "type_constructor",
"named": true
@ -948,13 +1040,21 @@
]
},
"return_type": {
"multiple": false,
"multiple": true,
"required": true,
"types": [
{
"type": ".",
"named": false
},
{
"type": "function_type",
"named": true
},
{
"type": "remote_type",
"named": true
},
{
"type": "remote_type_constructor",
"named": true
@ -963,6 +1063,10 @@
"type": "tuple_type",
"named": true
},
{
"type": "type",
"named": true
},
{
"type": "type_constructor",
"named": true
@ -1086,6 +1190,11 @@
]
}
},
{
"type": "remote_type",
"named": true,
"fields": {}
},
{
"type": "remote_type_constructor",
"named": true,
@ -1098,6 +1207,10 @@
"type": "function_type",
"named": true
},
{
"type": "remote_type",
"named": true
},
{
"type": "remote_type_constructor",
"named": true
@ -1106,6 +1219,10 @@
"type": "tuple_type",
"named": true
},
{
"type": "type",
"named": true
},
{
"type": "type_constructor",
"named": true
@ -1282,6 +1399,10 @@
"type": "function_type",
"named": true
},
{
"type": "remote_type",
"named": true
},
{
"type": "remote_type_constructor",
"named": true
@ -1290,6 +1411,10 @@
"type": "tuple_type",
"named": true
},
{
"type": "type",
"named": true
},
{
"type": "type_constructor",
"named": true
@ -1305,6 +1430,11 @@
]
}
},
{
"type": "type",
"named": true,
"fields": {}
},
{
"type": "type_constructor",
"named": true,
@ -1317,6 +1447,10 @@
"type": "function_type",
"named": true
},
{
"type": "remote_type",
"named": true
},
{
"type": "remote_type_constructor",
"named": true
@ -1325,6 +1459,10 @@
"type": "tuple_type",
"named": true
},
{
"type": "type",
"named": true
},
{
"type": "type_constructor",
"named": true

File diff suppressed because it is too large Load Diff