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, $.integer_literal,
$.string_literal, $.string_literal,
$.array_expression,
$.unary_expression, $.unary_expression,
$.binary_expression, $.binary_expression,
$.sequence_expression, $.sequence_expression,
@ -95,6 +97,15 @@ module.exports = grammar({
}, },
sequence_expression: ($) => seq("(", sepBy(";", $._expr), ")"), 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", "type": "SYMBOL",
"name": "string_literal" "name": "string_literal"
}, },
{
"type": "SYMBOL",
"name": "array_expression"
},
{ {
"type": "SYMBOL", "type": "SYMBOL",
"name": "unary_expression" "name": "unary_expression"
@ -470,6 +474,47 @@
"value": ")" "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": [ "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", "type": "binary_expression",
"named": true, "named": true,
@ -7,6 +91,10 @@
"multiple": false, "multiple": false,
"required": true, "required": true,
"types": [ "types": [
{
"type": "array_expression",
"named": true
},
{ {
"type": "binary_expression", "type": "binary_expression",
"named": true "named": true
@ -47,6 +135,10 @@
"multiple": false, "multiple": false,
"required": true, "required": true,
"types": [ "types": [
{
"type": "array_expression",
"named": true
},
{ {
"type": "binary_expression", "type": "binary_expression",
"named": true "named": true
@ -83,6 +175,10 @@
"multiple": true, "multiple": true,
"required": false, "required": false,
"types": [ "types": [
{
"type": "array_expression",
"named": true
},
{ {
"type": "binary_expression", "type": "binary_expression",
"named": true "named": true
@ -118,6 +214,10 @@
"multiple": false, "multiple": false,
"required": true, "required": true,
"types": [ "types": [
{
"type": "array_expression",
"named": true
},
{ {
"type": "binary_expression", "type": "binary_expression",
"named": true "named": true
@ -168,6 +268,10 @@
"multiple": false, "multiple": false,
"required": true, "required": true,
"types": [ "types": [
{
"type": "array_expression",
"named": true
},
{ {
"type": "binary_expression", "type": "binary_expression",
"named": true "named": true
@ -222,10 +326,22 @@
"type": ";", "type": ";",
"named": false "named": false
}, },
{
"type": "[",
"named": false
},
{
"type": "]",
"named": false
},
{ {
"type": "escape_sequence", "type": "escape_sequence",
"named": true "named": true
}, },
{
"type": "identifier",
"named": true
},
{ {
"type": "integer_literal", "type": "integer_literal",
"named": true "named": true
@ -234,6 +350,10 @@
"type": "nil_literal", "type": "nil_literal",
"named": true "named": true
}, },
{
"type": "of",
"named": false
},
{ {
"type": "operator", "type": "operator",
"named": true "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))))