Add array expression

This commit is contained in:
Bruno BELANYI 2022-06-01 19:48:54 +02:00
parent 02f83784b1
commit babf666642
5 changed files with 883 additions and 500 deletions

View file

@ -30,6 +30,8 @@ module.exports = grammar({
$.integer_literal,
$.string_literal,
$.array_expression,
$.unary_expression,
$.binary_expression,
$.sequence_expression,
@ -95,6 +97,15 @@ module.exports = grammar({
},
sequence_expression: ($) => seq("(", sepBy(";", $._expr), ")"),
array_expression: ($) => seq(
field("type", $.identifier),
"[",
field("size", $._expr),
"]",
"of",
field("init", $._expr),
),
}
});

View file

@ -26,6 +26,10 @@
"type": "SYMBOL",
"name": "string_literal"
},
{
"type": "SYMBOL",
"name": "array_expression"
},
{
"type": "SYMBOL",
"name": "unary_expression"
@ -470,6 +474,47 @@
"value": ")"
}
]
},
"array_expression": {
"type": "SEQ",
"members": [
{
"type": "FIELD",
"name": "type",
"content": {
"type": "SYMBOL",
"name": "identifier"
}
},
{
"type": "STRING",
"value": "["
},
{
"type": "FIELD",
"name": "size",
"content": {
"type": "SYMBOL",
"name": "_expr"
}
},
{
"type": "STRING",
"value": "]"
},
{
"type": "STRING",
"value": "of"
},
{
"type": "FIELD",
"name": "init",
"content": {
"type": "SYMBOL",
"name": "_expr"
}
}
]
}
},
"extras": [

View file

@ -1,4 +1,88 @@
[
{
"type": "array_expression",
"named": true,
"fields": {
"init": {
"multiple": false,
"required": true,
"types": [
{
"type": "array_expression",
"named": true
},
{
"type": "binary_expression",
"named": true
},
{
"type": "integer_literal",
"named": true
},
{
"type": "nil_literal",
"named": true
},
{
"type": "sequence_expression",
"named": true
},
{
"type": "string_literal",
"named": true
},
{
"type": "unary_expression",
"named": true
}
]
},
"size": {
"multiple": false,
"required": true,
"types": [
{
"type": "array_expression",
"named": true
},
{
"type": "binary_expression",
"named": true
},
{
"type": "integer_literal",
"named": true
},
{
"type": "nil_literal",
"named": true
},
{
"type": "sequence_expression",
"named": true
},
{
"type": "string_literal",
"named": true
},
{
"type": "unary_expression",
"named": true
}
]
},
"type": {
"multiple": false,
"required": true,
"types": [
{
"type": "identifier",
"named": true
}
]
}
}
},
{
"type": "binary_expression",
"named": true,
@ -7,6 +91,10 @@
"multiple": false,
"required": true,
"types": [
{
"type": "array_expression",
"named": true
},
{
"type": "binary_expression",
"named": true
@ -47,6 +135,10 @@
"multiple": false,
"required": true,
"types": [
{
"type": "array_expression",
"named": true
},
{
"type": "binary_expression",
"named": true
@ -83,6 +175,10 @@
"multiple": true,
"required": false,
"types": [
{
"type": "array_expression",
"named": true
},
{
"type": "binary_expression",
"named": true
@ -118,6 +214,10 @@
"multiple": false,
"required": true,
"types": [
{
"type": "array_expression",
"named": true
},
{
"type": "binary_expression",
"named": true
@ -168,6 +268,10 @@
"multiple": false,
"required": true,
"types": [
{
"type": "array_expression",
"named": true
},
{
"type": "binary_expression",
"named": true
@ -222,10 +326,22 @@
"type": ";",
"named": false
},
{
"type": "[",
"named": false
},
{
"type": "]",
"named": false
},
{
"type": "escape_sequence",
"named": true
},
{
"type": "identifier",
"named": true
},
{
"type": "integer_literal",
"named": true
@ -234,6 +350,10 @@
"type": "nil_literal",
"named": true
},
{
"type": "of",
"named": false
},
{
"type": "operator",
"named": true

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,30 @@
================================================================================
Array expression
================================================================================
array_of_int[42] of 0
--------------------------------------------------------------------------------
(source_file
(array_expression
type: (identifier)
size: (integer_literal)
init: (integer_literal)))
================================================================================
Array associativity
================================================================================
array_of_array_of_int[12] of array_of_int[27] of 0
--------------------------------------------------------------------------------
(source_file
(array_expression
type: (identifier)
size: (integer_literal)
init: (array_expression
type: (identifier)
size: (integer_literal)
init: (integer_literal))))