Add 'property' alias

It makes the syntax tree more readable.
This commit is contained in:
Bruno BELANYI 2024-04-08 01:49:24 +01:00
parent 644f6483fe
commit 2549f6f0db
6 changed files with 210 additions and 284 deletions

View file

@ -41,14 +41,18 @@ module.exports = grammar({
_old_module: ($) => seq(
field("type", $.identifier),
"{",
optional(commaSeparated(field("property", $._colon_property))),
optional(commaSeparated(
alias(field("property", $._colon_property), $.property)
)),
"}",
),
_new_module: ($) => seq(
$.identifier,
"(",
optional(commaSeparated(field("property", $._equal_property))),
optional(commaSeparated(
alias(field("property", $._equal_property), $.property)
)),
")",
),
@ -175,7 +179,9 @@ module.exports = grammar({
map_expression: ($) => seq(
"{",
optional(commaSeparated(field("property", $._colon_property))),
optional(commaSeparated(
alias(field("property", $._colon_property), $.property)
)),
"}",
),

90
src/grammar.json generated
View file

@ -107,12 +107,17 @@
"type": "SEQ",
"members": [
{
"type": "FIELD",
"name": "property",
"type": "ALIAS",
"content": {
"type": "SYMBOL",
"name": "_colon_property"
}
"type": "FIELD",
"name": "property",
"content": {
"type": "SYMBOL",
"name": "_colon_property"
}
},
"named": true,
"value": "property"
},
{
"type": "REPEAT",
@ -124,12 +129,17 @@
"value": ","
},
{
"type": "FIELD",
"name": "property",
"type": "ALIAS",
"content": {
"type": "SYMBOL",
"name": "_colon_property"
}
"type": "FIELD",
"name": "property",
"content": {
"type": "SYMBOL",
"name": "_colon_property"
}
},
"named": true,
"value": "property"
}
]
}
@ -177,12 +187,17 @@
"type": "SEQ",
"members": [
{
"type": "FIELD",
"name": "property",
"type": "ALIAS",
"content": {
"type": "SYMBOL",
"name": "_equal_property"
}
"type": "FIELD",
"name": "property",
"content": {
"type": "SYMBOL",
"name": "_equal_property"
}
},
"named": true,
"value": "property"
},
{
"type": "REPEAT",
@ -194,12 +209,17 @@
"value": ","
},
{
"type": "FIELD",
"name": "property",
"type": "ALIAS",
"content": {
"type": "SYMBOL",
"name": "_equal_property"
}
"type": "FIELD",
"name": "property",
"content": {
"type": "SYMBOL",
"name": "_equal_property"
}
},
"named": true,
"value": "property"
}
]
}
@ -748,12 +768,17 @@
"type": "SEQ",
"members": [
{
"type": "FIELD",
"name": "property",
"type": "ALIAS",
"content": {
"type": "SYMBOL",
"name": "_colon_property"
}
"type": "FIELD",
"name": "property",
"content": {
"type": "SYMBOL",
"name": "_colon_property"
}
},
"named": true,
"value": "property"
},
{
"type": "REPEAT",
@ -765,12 +790,17 @@
"value": ","
},
{
"type": "FIELD",
"name": "property",
"type": "ALIAS",
"content": {
"type": "SYMBOL",
"name": "_colon_property"
}
"type": "FIELD",
"name": "property",
"content": {
"type": "SYMBOL",
"name": "_colon_property"
}
},
"named": true,
"value": "property"
}
]
}

222
src/node-types.json generated
View file

@ -203,92 +203,12 @@
"type": "map_expression",
"named": true,
"fields": {
"field": {
"multiple": true,
"required": false,
"types": [
{
"type": "identifier",
"named": true
}
]
},
"property": {
"multiple": true,
"required": false,
"types": [
{
"type": ":",
"named": false
},
{
"type": "boolean_literal",
"named": true
},
{
"type": "identifier",
"named": true
},
{
"type": "integer_literal",
"named": true
},
{
"type": "interpreted_string_literal",
"named": true
},
{
"type": "list_expression",
"named": true
},
{
"type": "map_expression",
"named": true
},
{
"type": "raw_string_literal",
"named": true
},
{
"type": "select_expression",
"named": true
}
]
},
"value": {
"multiple": true,
"required": false,
"types": [
{
"type": "boolean_literal",
"named": true
},
{
"type": "identifier",
"named": true
},
{
"type": "integer_literal",
"named": true
},
{
"type": "interpreted_string_literal",
"named": true
},
{
"type": "list_expression",
"named": true
},
{
"type": "map_expression",
"named": true
},
{
"type": "raw_string_literal",
"named": true
},
{
"type": "select_expression",
"type": "property",
"named": true
}
]
@ -299,58 +219,12 @@
"type": "module",
"named": true,
"fields": {
"field": {
"multiple": true,
"required": false,
"types": [
{
"type": "identifier",
"named": true
}
]
},
"property": {
"multiple": true,
"required": false,
"types": [
{
"type": ":",
"named": false
},
{
"type": "=",
"named": false
},
{
"type": "boolean_literal",
"named": true
},
{
"type": "identifier",
"named": true
},
{
"type": "integer_literal",
"named": true
},
{
"type": "interpreted_string_literal",
"named": true
},
{
"type": "list_expression",
"named": true
},
{
"type": "map_expression",
"named": true
},
{
"type": "raw_string_literal",
"named": true
},
{
"type": "select_expression",
"type": "property",
"named": true
}
]
@ -364,44 +238,6 @@
"named": true
}
]
},
"value": {
"multiple": true,
"required": false,
"types": [
{
"type": "boolean_literal",
"named": true
},
{
"type": "identifier",
"named": true
},
{
"type": "integer_literal",
"named": true
},
{
"type": "interpreted_string_literal",
"named": true
},
{
"type": "list_expression",
"named": true
},
{
"type": "map_expression",
"named": true
},
{
"type": "raw_string_literal",
"named": true
},
{
"type": "select_expression",
"named": true
}
]
}
},
"children": {
@ -415,6 +251,60 @@
]
}
},
{
"type": "property",
"named": true,
"fields": {
"field": {
"multiple": false,
"required": true,
"types": [
{
"type": "identifier",
"named": true
}
]
},
"value": {
"multiple": false,
"required": true,
"types": [
{
"type": "boolean_literal",
"named": true
},
{
"type": "identifier",
"named": true
},
{
"type": "integer_literal",
"named": true
},
{
"type": "interpreted_string_literal",
"named": true
},
{
"type": "list_expression",
"named": true
},
{
"type": "map_expression",
"named": true
},
{
"type": "raw_string_literal",
"named": true
},
{
"type": "select_expression",
"named": true
}
]
}
}
},
{
"type": "select_case",
"named": true,

100
src/parser.c generated
View file

@ -129,8 +129,8 @@ static const char * const ts_symbol_names[] = {
[sym__case_value] = "_case_value",
[sym_list_expression] = "list_expression",
[sym_map_expression] = "map_expression",
[sym__colon_property] = "_colon_property",
[sym__equal_property] = "_equal_property",
[sym__colon_property] = "property",
[sym__equal_property] = "property",
[aux_sym_source_file_repeat1] = "source_file_repeat1",
[aux_sym__old_module_repeat1] = "_old_module_repeat1",
[aux_sym__new_module_repeat1] = "_new_module_repeat1",
@ -192,7 +192,7 @@ static const TSSymbol ts_symbol_map[] = {
[sym_list_expression] = sym_list_expression,
[sym_map_expression] = sym_map_expression,
[sym__colon_property] = sym__colon_property,
[sym__equal_property] = sym__equal_property,
[sym__equal_property] = sym__colon_property,
[aux_sym_source_file_repeat1] = aux_sym_source_file_repeat1,
[aux_sym__old_module_repeat1] = aux_sym__old_module_repeat1,
[aux_sym__new_module_repeat1] = aux_sym__new_module_repeat1,
@ -407,11 +407,11 @@ static const TSSymbolMetadata ts_symbol_metadata[] = {
.named = true,
},
[sym__colon_property] = {
.visible = false,
.visible = true,
.named = true,
},
[sym__equal_property] = {
.visible = false,
.visible = true,
.named = true,
},
[aux_sym_source_file_repeat1] = {
@ -472,104 +472,90 @@ static const char * const ts_field_names[] = {
};
static const TSFieldMapSlice ts_field_map_slices[PRODUCTION_ID_COUNT] = {
[1] = {.index = 0, .length = 4},
[2] = {.index = 4, .length = 3},
[3] = {.index = 7, .length = 3},
[4] = {.index = 10, .length = 1},
[5] = {.index = 11, .length = 4},
[6] = {.index = 15, .length = 3},
[7] = {.index = 18, .length = 3},
[8] = {.index = 21, .length = 1},
[9] = {.index = 22, .length = 2},
[10] = {.index = 24, .length = 7},
[11] = {.index = 31, .length = 6},
[12] = {.index = 37, .length = 6},
[13] = {.index = 43, .length = 6},
[14] = {.index = 49, .length = 2},
[15] = {.index = 51, .length = 2},
[16] = {.index = 53, .length = 2},
[17] = {.index = 55, .length = 4},
[18] = {.index = 59, .length = 2},
[1] = {.index = 0, .length = 2},
[2] = {.index = 2, .length = 1},
[3] = {.index = 3, .length = 3},
[4] = {.index = 6, .length = 1},
[5] = {.index = 7, .length = 4},
[6] = {.index = 11, .length = 3},
[7] = {.index = 14, .length = 3},
[8] = {.index = 17, .length = 1},
[9] = {.index = 18, .length = 2},
[10] = {.index = 20, .length = 5},
[11] = {.index = 25, .length = 2},
[12] = {.index = 27, .length = 4},
[13] = {.index = 31, .length = 4},
[14] = {.index = 35, .length = 2},
[15] = {.index = 37, .length = 2},
[16] = {.index = 39, .length = 2},
[17] = {.index = 41, .length = 4},
[18] = {.index = 45, .length = 2},
};
static const TSFieldMapEntry ts_field_map_entries[] = {
[0] =
{field_field, 0, .inherited = true},
{field_property, 0, .inherited = true},
{field_type, 0, .inherited = true},
{field_value, 0, .inherited = true},
[4] =
{field_field, 0, .inherited = true},
[2] =
{field_property, 0, .inherited = true},
{field_value, 0, .inherited = true},
[7] =
[3] =
{field_left, 0},
{field_operator, 1},
{field_right, 2},
[10] =
[6] =
{field_type, 0},
[7] =
{field_field, 2, .inherited = true},
{field_property, 2},
{field_type, 0},
{field_value, 2, .inherited = true},
[11] =
{field_field, 2, .inherited = true},
{field_property, 2},
{field_type, 0},
{field_value, 2, .inherited = true},
[15] =
{field_field, 2, .inherited = true},
{field_property, 2},
{field_value, 2, .inherited = true},
[18] =
[14] =
{field_field, 1, .inherited = true},
{field_property, 1},
{field_value, 1, .inherited = true},
[21] =
[17] =
{field_element, 1},
[22] =
[18] =
{field_field, 0},
{field_value, 2},
[24] =
[20] =
{field_field, 2, .inherited = true},
{field_field, 3, .inherited = true},
{field_property, 2},
{field_property, 3, .inherited = true},
{field_type, 0},
{field_value, 2, .inherited = true},
{field_value, 3, .inherited = true},
[31] =
{field_field, 0, .inherited = true},
{field_field, 1, .inherited = true},
[25] =
{field_property, 0, .inherited = true},
{field_property, 1, .inherited = true},
{field_value, 0, .inherited = true},
{field_value, 1, .inherited = true},
[37] =
[27] =
{field_field, 2, .inherited = true},
{field_field, 3, .inherited = true},
{field_property, 2},
{field_property, 3, .inherited = true},
{field_value, 2, .inherited = true},
{field_value, 3, .inherited = true},
[43] =
[31] =
{field_field, 1, .inherited = true},
{field_field, 2, .inherited = true},
{field_property, 1},
{field_property, 2, .inherited = true},
{field_value, 1, .inherited = true},
{field_value, 2, .inherited = true},
[49] =
[35] =
{field_element, 1},
{field_element, 2, .inherited = true},
[51] =
[37] =
{field_element, 0, .inherited = true},
{field_element, 1, .inherited = true},
[53] =
[39] =
{field_condition, 2},
{field_type, 0},
[55] =
[41] =
{field_condition, 3},
{field_namespace, 2},
{field_type, 0},
{field_variable, 4},
[59] =
[45] =
{field_pattern, 0},
{field_value, 2},
};

View file

@ -246,8 +246,9 @@ foo = {foo:42}
(assignment
(identifier)
(map_expression
(identifier)
(integer_literal))))
(property
(identifier)
(integer_literal)))))
================================================================================
Map (singleton multiline)
@ -263,8 +264,9 @@ foo = {
(assignment
(identifier)
(map_expression
(identifier)
(integer_literal))))
(property
(identifier)
(integer_literal)))))
================================================================================
Map (singleton trailing comma)
@ -280,8 +282,9 @@ foo = {
(assignment
(identifier)
(map_expression
(identifier)
(integer_literal))))
(property
(identifier)
(integer_literal)))))
================================================================================
Map (mixed values)
@ -298,10 +301,12 @@ foo = {
(assignment
(identifier)
(map_expression
(identifier)
(integer_literal)
(identifier)
(interpreted_string_literal))))
(property
(identifier)
(integer_literal))
(property
(identifier)
(interpreted_string_literal)))))
================================================================================
Map (map of map)
@ -317,10 +322,12 @@ foo = {
(assignment
(identifier)
(map_expression
(identifier)
(map_expression
(property
(identifier)
(integer_literal)))))
(map_expression
(property
(identifier)
(integer_literal)))))))
================================================================================
Map (rogue comma)

View file

@ -36,8 +36,9 @@ foo {
(source_file
(module
(identifier)
(identifier)
(integer_literal)))
(property
(identifier)
(integer_literal))))
================================================================================
Single property (trailing comma)
@ -52,8 +53,9 @@ foo {
(source_file
(module
(identifier)
(identifier)
(integer_literal)))
(property
(identifier)
(integer_literal))))
================================================================================
Mixed values
@ -70,12 +72,15 @@ foo {
(source_file
(module
(identifier)
(identifier)
(boolean_literal)
(identifier)
(interpreted_string_literal)
(identifier)
(integer_literal)))
(property
(identifier)
(boolean_literal))
(property
(identifier)
(interpreted_string_literal))
(property
(identifier)
(integer_literal))))
================================================================================
Complex value
@ -94,11 +99,13 @@ foo {
(source_file
(module
(identifier)
(identifier)
(list_expression
(map_expression
(identifier)
(interpreted_string_literal)))))
(property
(identifier)
(list_expression
(map_expression
(property
(identifier)
(interpreted_string_literal)))))))
================================================================================
Rogue comma