Add array types

This commit is contained in:
Bruno BELANYI 2022-06-01 20:54:35 +02:00
parent dd0af53fa0
commit 1e5f7cd5d5
5 changed files with 1529 additions and 1378 deletions

View file

@ -245,6 +245,7 @@ module.exports = grammar({
_type: ($) => choice(
$.type_alias,
$.record_type,
$.array_type,
),
type_alias: ($) => $.identifier,
@ -261,6 +262,12 @@ module.exports = grammar({
field("type", $.identifier),
),
array_type: ($) => seq(
"array",
"of",
field("element_type", $.identifier),
),
function_declaration: ($) => seq(
"function",
$._function_declaration_common,

View file

@ -1118,6 +1118,10 @@
{
"type": "SYMBOL",
"name": "record_type"
},
{
"type": "SYMBOL",
"name": "array_type"
}
]
},
@ -1196,6 +1200,27 @@
}
]
},
"array_type": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "array"
},
{
"type": "STRING",
"value": "of"
},
{
"type": "FIELD",
"name": "element_type",
"content": {
"type": "SYMBOL",
"name": "identifier"
}
}
]
},
"function_declaration": {
"type": "SEQ",
"members": [

View file

@ -171,6 +171,22 @@
}
}
},
{
"type": "array_type",
"named": true,
"fields": {
"element_type": {
"multiple": false,
"required": true,
"types": [
{
"type": "identifier",
"named": true
}
]
}
}
},
{
"type": "array_value",
"named": true,
@ -1837,6 +1853,10 @@
"multiple": false,
"required": true,
"types": [
{
"type": "array_type",
"named": true
},
{
"type": "record_type",
"named": true
@ -2253,6 +2273,10 @@
"type": "]",
"named": false
},
{
"type": "array",
"named": false
},
{
"type": "break_expression",
"named": true

File diff suppressed because it is too large Load diff

View file

@ -81,6 +81,37 @@ type record = { a: int, }
type: (identifier)
(ERROR))))
================================================================================
Array type declaration
================================================================================
type array_of_int = array of int
--------------------------------------------------------------------------------
(source_file
(type_declaration
name: (identifier)
value: (array_type
element_type: (identifier))))
================================================================================
Array type declaration non-associativity
================================================================================
type array_of_array_of_int = array of array of int
--------------------------------------------------------------------------------
(source_file
(ERROR
(type_declaration
name: (identifier)
value: (array_type
element_type: (identifier)))
(identifier))
(identifier))
================================================================================
Function declaration
================================================================================