Add type declarations

For now, simplified to type aliases only.
This commit is contained in:
Bruno BELANYI 2022-06-01 20:52:20 +02:00
parent e898312c95
commit 506fab8896
5 changed files with 2004 additions and 1701 deletions

View file

@ -228,12 +228,26 @@ module.exports = grammar({
_declaration_chunk: ($) => prec.left(
choice(
repeat1($.type_declaration),
repeat1(choice($.function_declaration, $.primitive_declaration)),
$.variable_declaration,
$.import_declaration,
),
),
type_declaration: ($) => seq(
"type",
field("name", $.identifier),
"=",
field("value", $._type)
),
_type: ($) => choice(
$.type_alias,
),
type_alias: ($) => $.identifier,
function_declaration: ($) => seq(
"function",
$._function_declaration_common,

View file

@ -1045,6 +1045,13 @@
"content": {
"type": "CHOICE",
"members": [
{
"type": "REPEAT1",
"content": {
"type": "SYMBOL",
"name": "type_declaration"
}
},
{
"type": "REPEAT1",
"content": {
@ -1072,6 +1079,48 @@
]
}
},
"type_declaration": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "type"
},
{
"type": "FIELD",
"name": "name",
"content": {
"type": "SYMBOL",
"name": "identifier"
}
},
{
"type": "STRING",
"value": "="
},
{
"type": "FIELD",
"name": "value",
"content": {
"type": "SYMBOL",
"name": "_type"
}
}
]
},
"_type": {
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "type_alias"
}
]
},
"type_alias": {
"type": "SYMBOL",
"name": "identifier"
},
"function_declaration": {
"type": "SEQ",
"members": [

View file

@ -1357,6 +1357,10 @@
"type": "primitive_declaration",
"named": true
},
{
"type": "type_declaration",
"named": true
},
{
"type": "variable_declaration",
"named": true
@ -1740,6 +1744,10 @@
"type": "string_literal",
"named": true
},
{
"type": "type_declaration",
"named": true
},
{
"type": "unary_expression",
"named": true
@ -1770,6 +1778,47 @@
]
}
},
{
"type": "type_alias",
"named": true,
"fields": {},
"children": {
"multiple": false,
"required": true,
"types": [
{
"type": "identifier",
"named": true
}
]
}
},
{
"type": "type_declaration",
"named": true,
"fields": {
"name": {
"multiple": false,
"required": true,
"types": [
{
"type": "identifier",
"named": true
}
]
},
"value": {
"multiple": false,
"required": true,
"types": [
{
"type": "type_alias",
"named": true
}
]
}
}
},
{
"type": "unary_expression",
"named": true,
@ -2250,6 +2299,10 @@
"type": "to",
"named": false
},
{
"type": "type",
"named": false
},
{
"type": "var",
"named": false

File diff suppressed because it is too large Load diff

View file

@ -6,6 +6,20 @@ Empty declarations
(source_file)
================================================================================
Type alias declaration
================================================================================
type alias = int
--------------------------------------------------------------------------------
(source_file
(type_declaration
name: (identifier)
value: (type_alias
(identifier))))
================================================================================
Function declaration
================================================================================