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, $.string_literal,
$.array_expression, $.array_expression,
$.record_expression,
$.unary_expression, $.unary_expression,
$.binary_expression, $.binary_expression,
@ -106,6 +107,20 @@ module.exports = grammar({
"of", "of",
field("init", $._expr), 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", "type": "SYMBOL",
"name": "array_expression" "name": "array_expression"
}, },
{
"type": "SYMBOL",
"name": "record_expression"
},
{ {
"type": "SYMBOL", "type": "SYMBOL",
"name": "unary_expression" "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": [ "extras": [

View file

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