Add some name visibilities

This commit is contained in:
Fabian Stamm 2024-10-02 19:18:54 +02:00
parent 9ee4a7c843
commit 6763d967af
4 changed files with 204 additions and 122 deletions

View File

@ -14,12 +14,14 @@ module.exports = grammar({
$.service_declaration,
$.enum_declaration,
),
type_declaration: ($) => seq("type", $.identifier, optional($.attributes)),
type_declaration: ($) =>
seq("type", field("name", $.identifier), optional($.attributes)),
attributes: ($) =>
seq("{", optional(seq($.attribute, repeat($.attribute))), "}"),
attribute: ($) => seq($.pair, ";"),
enum_declaration: ($) => seq("enum", $.identifier, $.enum_values),
enum_declaration: ($) =>
seq("enum", field("name", $.identifier), $.enum_values),
enum_values: ($) =>
seq(
"{",
@ -32,12 +34,17 @@ module.exports = grammar({
enum_value_declaration: ($) => seq($.identifier),
define_declaration: ($) =>
seq("define", $.identifier, choice($.string, $.identifier), ";"),
seq(
"define",
field("key", $.identifier),
field("value", choice($.string, $.identifier)),
";",
),
import_declaration: ($) => seq("import", $.string, ";"),
import_declaration: ($) => seq("import", field("source", $.string), ";"),
service_declaration: ($) =>
seq("service", $.identifier, $.service_functions),
seq("service", field("name", $.identifier), $.service_functions),
service_functions: ($) =>
seq(
@ -53,7 +60,8 @@ module.exports = grammar({
"}",
),
function_decorator: ($) => seq("@", $.identifier, $.decorator_arguments),
function_decorator: ($) =>
seq("@", field("name", $.identifier), $.decorator_arguments),
decorator_arguments: ($) =>
seq(
"(",
@ -84,11 +92,7 @@ module.exports = grammar({
")",
),
function_argument: ($) =>
seq(
field("argument_identifier", $.identifier),
":",
field("argument_type", $.type),
),
seq(field("name", $.identifier), ":", field("type", $.type)),
pair: ($) =>
seq(

32
src/grammar.json generated
View File

@ -41,8 +41,12 @@
"value": "type"
},
{
"type": "FIELD",
"name": "name",
"content": {
"type": "SYMBOL",
"name": "identifier"
}
},
{
"type": "CHOICE",
@ -116,8 +120,12 @@
"value": "enum"
},
{
"type": "FIELD",
"name": "name",
"content": {
"type": "SYMBOL",
"name": "identifier"
}
},
{
"type": "SYMBOL",
@ -218,10 +226,17 @@
"value": "define"
},
{
"type": "FIELD",
"name": "key",
"content": {
"type": "SYMBOL",
"name": "identifier"
}
},
{
"type": "FIELD",
"name": "value",
"content": {
"type": "CHOICE",
"members": [
{
@ -233,6 +248,7 @@
"name": "identifier"
}
]
}
},
{
"type": "STRING",
@ -248,8 +264,12 @@
"value": "import"
},
{
"type": "FIELD",
"name": "source",
"content": {
"type": "SYMBOL",
"name": "string"
}
},
{
"type": "STRING",
@ -265,8 +285,12 @@
"value": "service"
},
{
"type": "FIELD",
"name": "name",
"content": {
"type": "SYMBOL",
"name": "identifier"
}
},
{
"type": "SYMBOL",
@ -331,8 +355,12 @@
"value": "@"
},
{
"type": "FIELD",
"name": "name",
"content": {
"type": "SYMBOL",
"name": "identifier"
}
},
{
"type": "SYMBOL",
@ -511,7 +539,7 @@
"members": [
{
"type": "FIELD",
"name": "argument_identifier",
"name": "name",
"content": {
"type": "SYMBOL",
"name": "identifier"
@ -523,7 +551,7 @@
},
{
"type": "FIELD",
"name": "argument_type",
"name": "type",
"content": {
"type": "SYMBOL",
"name": "type"

98
src/node-types.json generated
View File

@ -66,9 +66,19 @@
{
"type": "define_declaration",
"named": true,
"fields": {},
"children": {
"multiple": true,
"fields": {
"key": {
"multiple": false,
"required": true,
"types": [
{
"type": "identifier",
"named": true
}
]
},
"value": {
"multiple": false,
"required": true,
"types": [
{
@ -81,6 +91,7 @@
}
]
}
}
},
{
"type": "document",
@ -116,18 +127,25 @@
{
"type": "enum_declaration",
"named": true,
"fields": {},
"fields": {
"name": {
"multiple": false,
"required": true,
"types": [
{
"type": "identifier",
"named": true
}
]
}
},
"children": {
"multiple": true,
"multiple": false,
"required": true,
"types": [
{
"type": "enum_values",
"named": true
},
{
"type": "identifier",
"named": true
}
]
}
@ -189,7 +207,7 @@
"type": "function_argument",
"named": true,
"fields": {
"argument_identifier": {
"name": {
"multiple": false,
"required": true,
"types": [
@ -199,7 +217,7 @@
}
]
},
"argument_type": {
"type": {
"multiple": false,
"required": true,
"types": [
@ -229,18 +247,25 @@
{
"type": "function_decorator",
"named": true,
"fields": {},
"fields": {
"name": {
"multiple": false,
"required": true,
"types": [
{
"type": "identifier",
"named": true
}
]
}
},
"children": {
"multiple": true,
"multiple": false,
"required": true,
"types": [
{
"type": "decorator_arguments",
"named": true
},
{
"type": "identifier",
"named": true
}
]
}
@ -248,8 +273,8 @@
{
"type": "import_declaration",
"named": true,
"fields": {},
"children": {
"fields": {
"source": {
"multiple": false,
"required": true,
"types": [
@ -259,6 +284,7 @@
}
]
}
}
},
{
"type": "map_key_type",
@ -318,15 +344,22 @@
{
"type": "service_declaration",
"named": true,
"fields": {},
"children": {
"multiple": true,
"fields": {
"name": {
"multiple": false,
"required": true,
"types": [
{
"type": "identifier",
"named": true
}
]
}
},
"children": {
"multiple": false,
"required": true,
"types": [
{
"type": "service_functions",
"named": true
@ -468,15 +501,11 @@
{
"type": "type_declaration",
"named": true,
"fields": {},
"children": {
"multiple": true,
"fields": {
"name": {
"multiple": false,
"required": true,
"types": [
{
"type": "attributes",
"named": true
},
{
"type": "identifier",
"named": true
@ -484,6 +513,17 @@
]
}
},
"children": {
"multiple": false,
"required": false,
"types": [
{
"type": "attributes",
"named": true
}
]
}
},
{
"type": "\"",
"named": false

80
src/parser.c generated
View File

@ -13,7 +13,7 @@
#define EXTERNAL_TOKEN_COUNT 0
#define FIELD_COUNT 7
#define MAX_ALIAS_SEQUENCE_LENGTH 5
#define PRODUCTION_ID_COUNT 6
#define PRODUCTION_ID_COUNT 9
enum ts_symbol_identifiers {
anon_sym_type = 1,
@ -468,48 +468,58 @@ static const TSSymbolMetadata ts_symbol_metadata[] = {
};
enum ts_field_identifiers {
field_argument_identifier = 1,
field_argument_type = 2,
field_key = 3,
field_name = 4,
field_parameters = 5,
field_return_type = 6,
field_key = 1,
field_name = 2,
field_parameters = 3,
field_return_type = 4,
field_source = 5,
field_type = 6,
field_value = 7,
};
static const char * const ts_field_names[] = {
[0] = NULL,
[field_argument_identifier] = "argument_identifier",
[field_argument_type] = "argument_type",
[field_key] = "key",
[field_name] = "name",
[field_parameters] = "parameters",
[field_return_type] = "return_type",
[field_source] = "source",
[field_type] = "type",
[field_value] = "value",
};
static const TSFieldMapSlice ts_field_map_slices[PRODUCTION_ID_COUNT] = {
[1] = {.index = 0, .length = 2},
[2] = {.index = 2, .length = 2},
[3] = {.index = 4, .length = 2},
[4] = {.index = 6, .length = 2},
[5] = {.index = 8, .length = 3},
[1] = {.index = 0, .length = 1},
[2] = {.index = 1, .length = 1},
[3] = {.index = 2, .length = 2},
[4] = {.index = 4, .length = 2},
[5] = {.index = 6, .length = 2},
[6] = {.index = 8, .length = 2},
[7] = {.index = 10, .length = 2},
[8] = {.index = 12, .length = 3},
};
static const TSFieldMapEntry ts_field_map_entries[] = {
[0] =
{field_name, 1},
[1] =
{field_source, 1},
[2] =
{field_key, 1},
{field_value, 2},
[4] =
{field_key, 0},
{field_value, 2},
[2] =
[6] =
{field_key, 0},
{field_value, 3},
[4] =
[8] =
{field_name, 1},
{field_parameters, 2},
[6] =
{field_argument_identifier, 0},
{field_argument_type, 2},
[8] =
[10] =
{field_name, 0},
{field_type, 2},
[12] =
{field_name, 0},
{field_parameters, 1},
{field_return_type, 3},
@ -2323,21 +2333,21 @@ static const TSParseActionEntry ts_parse_actions[] = {
[52] = {.entry = {.count = 2, .reusable = true}}, REDUCE(aux_sym_service_functions_repeat2, 2, 0, 0), SHIFT_REPEAT(86),
[55] = {.entry = {.count = 2, .reusable = false}}, REDUCE(aux_sym_service_functions_repeat2, 2, 0, 0), SHIFT_REPEAT(87),
[58] = {.entry = {.count = 2, .reusable = false}}, REDUCE(aux_sym_service_functions_repeat2, 2, 0, 0), SHIFT_REPEAT(80),
[61] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_type_declaration, 2, 0, 0),
[61] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_type_declaration, 2, 0, 1),
[63] = {.entry = {.count = 1, .reusable = true}}, SHIFT(43),
[65] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_attributes, 3, 0, 0),
[67] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_enum_values, 4, 0, 0),
[69] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_enum_values, 3, 0, 0),
[71] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_type_declaration, 3, 0, 0),
[73] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_enum_declaration, 3, 0, 0),
[75] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_import_declaration, 3, 0, 0),
[71] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_type_declaration, 3, 0, 1),
[73] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_enum_declaration, 3, 0, 1),
[75] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_import_declaration, 3, 0, 2),
[77] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_service_functions, 2, 0, 0),
[79] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_service_declaration, 3, 0, 0),
[79] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_service_declaration, 3, 0, 1),
[81] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_attributes, 2, 0, 0),
[83] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_service_functions, 3, 0, 0),
[85] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_enum_values, 2, 0, 0),
[87] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_attributes, 4, 0, 0),
[89] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_define_declaration, 4, 0, 0),
[89] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_define_declaration, 4, 0, 3),
[91] = {.entry = {.count = 1, .reusable = true}}, SHIFT(24),
[93] = {.entry = {.count = 1, .reusable = true}}, SHIFT(55),
[95] = {.entry = {.count = 1, .reusable = true}}, REDUCE(aux_sym_attributes_repeat1, 2, 0, 0),
@ -2352,8 +2362,8 @@ static const TSParseActionEntry ts_parse_actions[] = {
[115] = {.entry = {.count = 1, .reusable = false}}, REDUCE(aux_sym_service_functions_repeat1, 2, 0, 0),
[117] = {.entry = {.count = 1, .reusable = false}}, SHIFT(49),
[119] = {.entry = {.count = 1, .reusable = true}}, SHIFT(42),
[121] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_service_function, 5, 0, 5),
[123] = {.entry = {.count = 1, .reusable = false}}, REDUCE(sym_service_function, 5, 0, 5),
[121] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_service_function, 5, 0, 8),
[123] = {.entry = {.count = 1, .reusable = false}}, REDUCE(sym_service_function, 5, 0, 8),
[125] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_array_type, 2, 0, 0),
[127] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_map_type, 5, 0, 0),
[129] = {.entry = {.count = 1, .reusable = false}}, SHIFT(48),
@ -2362,12 +2372,12 @@ static const TSParseActionEntry ts_parse_actions[] = {
[135] = {.entry = {.count = 1, .reusable = false}}, REDUCE(aux_sym__string_content, 2, 0, 0),
[137] = {.entry = {.count = 2, .reusable = true}}, REDUCE(aux_sym__string_content, 2, 0, 0), SHIFT_REPEAT(42),
[140] = {.entry = {.count = 1, .reusable = true}}, SHIFT(22),
[142] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_service_notification, 4, 0, 3),
[144] = {.entry = {.count = 1, .reusable = false}}, REDUCE(sym_service_notification, 4, 0, 3),
[142] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_service_notification, 4, 0, 6),
[144] = {.entry = {.count = 1, .reusable = false}}, REDUCE(sym_service_notification, 4, 0, 6),
[146] = {.entry = {.count = 1, .reusable = true}}, SHIFT(78),
[148] = {.entry = {.count = 1, .reusable = true}}, SHIFT(57),
[150] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_function_decorator, 3, 0, 0),
[152] = {.entry = {.count = 1, .reusable = false}}, REDUCE(sym_function_decorator, 3, 0, 0),
[150] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_function_decorator, 3, 0, 1),
[152] = {.entry = {.count = 1, .reusable = false}}, REDUCE(sym_function_decorator, 3, 0, 1),
[154] = {.entry = {.count = 1, .reusable = true}}, SHIFT(62),
[156] = {.entry = {.count = 1, .reusable = true}}, SHIFT(40),
[158] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_string, 2, 0, 0),
@ -2404,7 +2414,7 @@ static const TSParseActionEntry ts_parse_actions[] = {
[223] = {.entry = {.count = 1, .reusable = true}}, SHIFT(53),
[225] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_function_arguments, 4, 0, 0),
[227] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_function_arguments, 2, 0, 0),
[229] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_function_argument, 3, 0, 4),
[229] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_function_argument, 3, 0, 7),
[231] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_attribute, 2, 0, 0),
[233] = {.entry = {.count = 1, .reusable = true}}, SHIFT(27),
[235] = {.entry = {.count = 1, .reusable = true}}, SHIFT(9),
@ -2416,12 +2426,12 @@ static const TSParseActionEntry ts_parse_actions[] = {
[247] = {.entry = {.count = 1, .reusable = true}}, SHIFT(71),
[249] = {.entry = {.count = 1, .reusable = true}}, SHIFT(26),
[251] = {.entry = {.count = 1, .reusable = true}}, SHIFT(36),
[253] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_pair, 4, 0, 2),
[253] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_pair, 4, 0, 5),
[255] = {.entry = {.count = 1, .reusable = true}}, SHIFT(8),
[257] = {.entry = {.count = 1, .reusable = true}}, SHIFT(19),
[259] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_map_key_type, 1, 0, 0),
[261] = {.entry = {.count = 1, .reusable = true}}, SHIFT(6),
[263] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_pair, 3, 0, 1),
[263] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_pair, 3, 0, 4),
[265] = {.entry = {.count = 1, .reusable = true}}, SHIFT(44),
[267] = {.entry = {.count = 1, .reusable = true}}, ACCEPT_INPUT(),
[269] = {.entry = {.count = 1, .reusable = true}}, SHIFT(79),