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 4a20da5c8f
commit dd50817b9d
6 changed files with 210 additions and 284 deletions

View file

@ -41,14 +41,18 @@ module.exports = grammar({
_old_module: ($) => seq( _old_module: ($) => seq(
field("type", $.identifier), field("type", $.identifier),
"{", "{",
optional(commaSeparated(field("property", $._colon_property))), optional(commaSeparated(
alias(field("property", $._colon_property), $.property)
)),
"}", "}",
), ),
_new_module: ($) => seq( _new_module: ($) => seq(
$.identifier, $.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( 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", "type": "SEQ",
"members": [ "members": [
{ {
"type": "FIELD", "type": "ALIAS",
"name": "property",
"content": { "content": {
"type": "SYMBOL", "type": "FIELD",
"name": "_colon_property" "name": "property",
} "content": {
"type": "SYMBOL",
"name": "_colon_property"
}
},
"named": true,
"value": "property"
}, },
{ {
"type": "REPEAT", "type": "REPEAT",
@ -124,12 +129,17 @@
"value": "," "value": ","
}, },
{ {
"type": "FIELD", "type": "ALIAS",
"name": "property",
"content": { "content": {
"type": "SYMBOL", "type": "FIELD",
"name": "_colon_property" "name": "property",
} "content": {
"type": "SYMBOL",
"name": "_colon_property"
}
},
"named": true,
"value": "property"
} }
] ]
} }
@ -177,12 +187,17 @@
"type": "SEQ", "type": "SEQ",
"members": [ "members": [
{ {
"type": "FIELD", "type": "ALIAS",
"name": "property",
"content": { "content": {
"type": "SYMBOL", "type": "FIELD",
"name": "_equal_property" "name": "property",
} "content": {
"type": "SYMBOL",
"name": "_equal_property"
}
},
"named": true,
"value": "property"
}, },
{ {
"type": "REPEAT", "type": "REPEAT",
@ -194,12 +209,17 @@
"value": "," "value": ","
}, },
{ {
"type": "FIELD", "type": "ALIAS",
"name": "property",
"content": { "content": {
"type": "SYMBOL", "type": "FIELD",
"name": "_equal_property" "name": "property",
} "content": {
"type": "SYMBOL",
"name": "_equal_property"
}
},
"named": true,
"value": "property"
} }
] ]
} }
@ -748,12 +768,17 @@
"type": "SEQ", "type": "SEQ",
"members": [ "members": [
{ {
"type": "FIELD", "type": "ALIAS",
"name": "property",
"content": { "content": {
"type": "SYMBOL", "type": "FIELD",
"name": "_colon_property" "name": "property",
} "content": {
"type": "SYMBOL",
"name": "_colon_property"
}
},
"named": true,
"value": "property"
}, },
{ {
"type": "REPEAT", "type": "REPEAT",
@ -765,12 +790,17 @@
"value": "," "value": ","
}, },
{ {
"type": "FIELD", "type": "ALIAS",
"name": "property",
"content": { "content": {
"type": "SYMBOL", "type": "FIELD",
"name": "_colon_property" "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", "type": "map_expression",
"named": true, "named": true,
"fields": { "fields": {
"field": {
"multiple": true,
"required": false,
"types": [
{
"type": "identifier",
"named": true
}
]
},
"property": { "property": {
"multiple": true, "multiple": true,
"required": false, "required": false,
"types": [ "types": [
{ {
"type": ":", "type": "property",
"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",
"named": true "named": true
} }
] ]
@ -299,58 +219,12 @@
"type": "module", "type": "module",
"named": true, "named": true,
"fields": { "fields": {
"field": {
"multiple": true,
"required": false,
"types": [
{
"type": "identifier",
"named": true
}
]
},
"property": { "property": {
"multiple": true, "multiple": true,
"required": false, "required": false,
"types": [ "types": [
{ {
"type": ":", "type": "property",
"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",
"named": true "named": true
} }
] ]
@ -364,44 +238,6 @@
"named": true "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": { "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", "type": "select_case",
"named": true, "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__case_value] = "_case_value",
[sym_list_expression] = "list_expression", [sym_list_expression] = "list_expression",
[sym_map_expression] = "map_expression", [sym_map_expression] = "map_expression",
[sym__colon_property] = "_colon_property", [sym__colon_property] = "property",
[sym__equal_property] = "_equal_property", [sym__equal_property] = "property",
[aux_sym_source_file_repeat1] = "source_file_repeat1", [aux_sym_source_file_repeat1] = "source_file_repeat1",
[aux_sym__old_module_repeat1] = "_old_module_repeat1", [aux_sym__old_module_repeat1] = "_old_module_repeat1",
[aux_sym__new_module_repeat1] = "_new_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_list_expression] = sym_list_expression,
[sym_map_expression] = sym_map_expression, [sym_map_expression] = sym_map_expression,
[sym__colon_property] = sym__colon_property, [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_source_file_repeat1] = aux_sym_source_file_repeat1,
[aux_sym__old_module_repeat1] = aux_sym__old_module_repeat1, [aux_sym__old_module_repeat1] = aux_sym__old_module_repeat1,
[aux_sym__new_module_repeat1] = aux_sym__new_module_repeat1, [aux_sym__new_module_repeat1] = aux_sym__new_module_repeat1,
@ -407,11 +407,11 @@ static const TSSymbolMetadata ts_symbol_metadata[] = {
.named = true, .named = true,
}, },
[sym__colon_property] = { [sym__colon_property] = {
.visible = false, .visible = true,
.named = true, .named = true,
}, },
[sym__equal_property] = { [sym__equal_property] = {
.visible = false, .visible = true,
.named = true, .named = true,
}, },
[aux_sym_source_file_repeat1] = { [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] = { static const TSFieldMapSlice ts_field_map_slices[PRODUCTION_ID_COUNT] = {
[1] = {.index = 0, .length = 4}, [1] = {.index = 0, .length = 2},
[2] = {.index = 4, .length = 3}, [2] = {.index = 2, .length = 1},
[3] = {.index = 7, .length = 3}, [3] = {.index = 3, .length = 3},
[4] = {.index = 10, .length = 1}, [4] = {.index = 6, .length = 1},
[5] = {.index = 11, .length = 4}, [5] = {.index = 7, .length = 4},
[6] = {.index = 15, .length = 3}, [6] = {.index = 11, .length = 3},
[7] = {.index = 18, .length = 3}, [7] = {.index = 14, .length = 3},
[8] = {.index = 21, .length = 1}, [8] = {.index = 17, .length = 1},
[9] = {.index = 22, .length = 2}, [9] = {.index = 18, .length = 2},
[10] = {.index = 24, .length = 7}, [10] = {.index = 20, .length = 5},
[11] = {.index = 31, .length = 6}, [11] = {.index = 25, .length = 2},
[12] = {.index = 37, .length = 6}, [12] = {.index = 27, .length = 4},
[13] = {.index = 43, .length = 6}, [13] = {.index = 31, .length = 4},
[14] = {.index = 49, .length = 2}, [14] = {.index = 35, .length = 2},
[15] = {.index = 51, .length = 2}, [15] = {.index = 37, .length = 2},
[16] = {.index = 53, .length = 2}, [16] = {.index = 39, .length = 2},
[17] = {.index = 55, .length = 4}, [17] = {.index = 41, .length = 4},
[18] = {.index = 59, .length = 2}, [18] = {.index = 45, .length = 2},
}; };
static const TSFieldMapEntry ts_field_map_entries[] = { static const TSFieldMapEntry ts_field_map_entries[] = {
[0] = [0] =
{field_field, 0, .inherited = true},
{field_property, 0, .inherited = true}, {field_property, 0, .inherited = true},
{field_type, 0, .inherited = true}, {field_type, 0, .inherited = true},
{field_value, 0, .inherited = true}, [2] =
[4] =
{field_field, 0, .inherited = true},
{field_property, 0, .inherited = true}, {field_property, 0, .inherited = true},
{field_value, 0, .inherited = true}, [3] =
[7] =
{field_left, 0}, {field_left, 0},
{field_operator, 1}, {field_operator, 1},
{field_right, 2}, {field_right, 2},
[10] = [6] =
{field_type, 0}, {field_type, 0},
[7] =
{field_field, 2, .inherited = true},
{field_property, 2},
{field_type, 0},
{field_value, 2, .inherited = true},
[11] = [11] =
{field_field, 2, .inherited = true}, {field_field, 2, .inherited = true},
{field_property, 2}, {field_property, 2},
{field_type, 0},
{field_value, 2, .inherited = true}, {field_value, 2, .inherited = true},
[15] = [14] =
{field_field, 2, .inherited = true},
{field_property, 2},
{field_value, 2, .inherited = true},
[18] =
{field_field, 1, .inherited = true}, {field_field, 1, .inherited = true},
{field_property, 1}, {field_property, 1},
{field_value, 1, .inherited = true}, {field_value, 1, .inherited = true},
[21] = [17] =
{field_element, 1}, {field_element, 1},
[22] = [18] =
{field_field, 0}, {field_field, 0},
{field_value, 2}, {field_value, 2},
[24] = [20] =
{field_field, 2, .inherited = true}, {field_field, 2, .inherited = true},
{field_field, 3, .inherited = true},
{field_property, 2}, {field_property, 2},
{field_property, 3, .inherited = true}, {field_property, 3, .inherited = true},
{field_type, 0}, {field_type, 0},
{field_value, 2, .inherited = true}, {field_value, 2, .inherited = true},
{field_value, 3, .inherited = true}, [25] =
[31] =
{field_field, 0, .inherited = true},
{field_field, 1, .inherited = true},
{field_property, 0, .inherited = true}, {field_property, 0, .inherited = true},
{field_property, 1, .inherited = true}, {field_property, 1, .inherited = true},
{field_value, 0, .inherited = true}, [27] =
{field_value, 1, .inherited = true},
[37] =
{field_field, 2, .inherited = true}, {field_field, 2, .inherited = true},
{field_field, 3, .inherited = true},
{field_property, 2}, {field_property, 2},
{field_property, 3, .inherited = true}, {field_property, 3, .inherited = true},
{field_value, 2, .inherited = true}, {field_value, 2, .inherited = true},
{field_value, 3, .inherited = true}, [31] =
[43] =
{field_field, 1, .inherited = true}, {field_field, 1, .inherited = true},
{field_field, 2, .inherited = true},
{field_property, 1}, {field_property, 1},
{field_property, 2, .inherited = true}, {field_property, 2, .inherited = true},
{field_value, 1, .inherited = true}, {field_value, 1, .inherited = true},
{field_value, 2, .inherited = true}, [35] =
[49] =
{field_element, 1}, {field_element, 1},
{field_element, 2, .inherited = true}, {field_element, 2, .inherited = true},
[51] = [37] =
{field_element, 0, .inherited = true}, {field_element, 0, .inherited = true},
{field_element, 1, .inherited = true}, {field_element, 1, .inherited = true},
[53] = [39] =
{field_condition, 2}, {field_condition, 2},
{field_type, 0}, {field_type, 0},
[55] = [41] =
{field_condition, 3}, {field_condition, 3},
{field_namespace, 2}, {field_namespace, 2},
{field_type, 0}, {field_type, 0},
{field_variable, 4}, {field_variable, 4},
[59] = [45] =
{field_pattern, 0}, {field_pattern, 0},
{field_value, 2}, {field_value, 2},
}; };

View file

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

View file

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