Add record expression

This commit is contained in:
Bruno BELANYI 2022-06-01 19:54:09 +02:00
parent babf666642
commit 136924cb26
5 changed files with 1134 additions and 509 deletions

View file

@ -31,6 +31,7 @@ module.exports = grammar({
$.string_literal,
$.array_expression,
$.record_expression,
$.unary_expression,
$.binary_expression,
@ -106,6 +107,20 @@ module.exports = grammar({
"of",
field("init", $._expr),
),
record_expression: ($) => seq(
field("type", $.identifier),
"{",
sepBy(
",",
seq(
field("field", $.identifier),
"=",
field("init", $._expr),
),
),
"}",
),
}
});

View file

@ -30,6 +30,10 @@
"type": "SYMBOL",
"name": "array_expression"
},
{
"type": "SYMBOL",
"name": "record_expression"
},
{
"type": "SYMBOL",
"name": "unary_expression"
@ -515,6 +519,102 @@
}
}
]
},
"record_expression": {
"type": "SEQ",
"members": [
{
"type": "FIELD",
"name": "type",
"content": {
"type": "SYMBOL",
"name": "identifier"
}
},
{
"type": "STRING",
"value": "{"
},
{
"type": "CHOICE",
"members": [
{
"type": "SEQ",
"members": [
{
"type": "SEQ",
"members": [
{
"type": "FIELD",
"name": "field",
"content": {
"type": "SYMBOL",
"name": "identifier"
}
},
{
"type": "STRING",
"value": "="
},
{
"type": "FIELD",
"name": "init",
"content": {
"type": "SYMBOL",
"name": "_expr"
}
}
]
},
{
"type": "REPEAT",
"content": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": ","
},
{
"type": "SEQ",
"members": [
{
"type": "FIELD",
"name": "field",
"content": {
"type": "SYMBOL",
"name": "identifier"
}
},
{
"type": "STRING",
"value": "="
},
{
"type": "FIELD",
"name": "init",
"content": {
"type": "SYMBOL",
"name": "_expr"
}
}
]
}
]
}
}
]
},
{
"type": "BLANK"
}
]
},
{
"type": "STRING",
"value": "}"
}
]
}
},
"extras": [

View file

@ -23,6 +23,10 @@
"type": "nil_literal",
"named": true
},
{
"type": "record_expression",
"named": true
},
{
"type": "sequence_expression",
"named": true
@ -57,6 +61,10 @@
"type": "nil_literal",
"named": true
},
{
"type": "record_expression",
"named": true
},
{
"type": "sequence_expression",
"named": true
@ -107,6 +115,10 @@
"type": "nil_literal",
"named": true
},
{
"type": "record_expression",
"named": true
},
{
"type": "sequence_expression",
"named": true
@ -151,6 +163,10 @@
"type": "nil_literal",
"named": true
},
{
"type": "record_expression",
"named": true
},
{
"type": "sequence_expression",
"named": true
@ -167,6 +183,70 @@
}
}
},
{
"type": "record_expression",
"named": true,
"fields": {
"field": {
"multiple": true,
"required": false,
"types": [
{
"type": "identifier",
"named": true
}
]
},
"init": {
"multiple": true,
"required": false,
"types": [
{
"type": "array_expression",
"named": true
},
{
"type": "binary_expression",
"named": true
},
{
"type": "integer_literal",
"named": true
},
{
"type": "nil_literal",
"named": true
},
{
"type": "record_expression",
"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": "sequence_expression",
"named": true,
@ -191,6 +271,10 @@
"type": "nil_literal",
"named": true
},
{
"type": "record_expression",
"named": true
},
{
"type": "sequence_expression",
"named": true
@ -230,6 +314,10 @@
"type": "nil_literal",
"named": true
},
{
"type": "record_expression",
"named": true
},
{
"type": "sequence_expression",
"named": true
@ -284,6 +372,10 @@
"type": "nil_literal",
"named": true
},
{
"type": "record_expression",
"named": true
},
{
"type": "sequence_expression",
"named": true
@ -322,10 +414,18 @@
"type": ")",
"named": false
},
{
"type": ",",
"named": false
},
{
"type": ";",
"named": false
},
{
"type": "=",
"named": false
},
{
"type": "[",
"named": false
@ -357,5 +457,13 @@
{
"type": "operator",
"named": true
},
{
"type": "{",
"named": false
},
{
"type": "}",
"named": false
}
]

File diff suppressed because it is too large Load diff

View file

@ -28,3 +28,60 @@ array_of_array_of_int[12] of array_of_int[27] of 0
type: (identifier)
size: (integer_literal)
init: (integer_literal))))
================================================================================
Record expression
================================================================================
record_type { a = 12, b = "27" }
--------------------------------------------------------------------------------
(source_file
(record_expression
type: (identifier)
field: (identifier)
init: (integer_literal)
field: (identifier)
init: (string_literal)))
================================================================================
Record expression single field
================================================================================
record_type { a = 12 }
--------------------------------------------------------------------------------
(source_file
(record_expression
type: (identifier)
field: (identifier)
init: (integer_literal)))
================================================================================
Record expression no fields
================================================================================
record_type {}
--------------------------------------------------------------------------------
(source_file
(record_expression
type: (identifier)))
================================================================================
Record expression trailing comma
================================================================================
record_type { a = 12, }
--------------------------------------------------------------------------------
(source_file
(record_expression
type: (identifier)
field: (identifier)
init: (integer_literal)
(ERROR)))