Add 'field_identifier' alias

This will be useful for high-lighting.
This commit is contained in:
Bruno BELANYI 2022-06-03 10:31:30 +02:00
parent abe5b2e366
commit 0827093fe7
6 changed files with 48 additions and 16 deletions

View file

@ -23,6 +23,7 @@ module.exports = grammar({
inline: ($) => [ inline: ($) => [
$._type_identifier, $._type_identifier,
$._field_identifier,
], ],
conflicts: ($) => [ conflicts: ($) => [
@ -88,6 +89,8 @@ module.exports = grammar({
_type_identifier: ($) => alias($.identifier, $.type_identifier), _type_identifier: ($) => alias($.identifier, $.type_identifier),
_field_identifier: ($) => alias($.identifier, $.field_identifier),
escape_sequence: (_) => token.immediate( escape_sequence: (_) => token.immediate(
seq( seq(
"\\", "\\",
@ -113,7 +116,7 @@ module.exports = grammar({
record_value: ($) => seq( record_value: ($) => seq(
field("record", $._lvalue), field("record", $._lvalue),
".", ".",
field("field", $.identifier), field("field", $._field_identifier),
), ),
array_value: ($) => seq( array_value: ($) => seq(
@ -177,7 +180,7 @@ module.exports = grammar({
sepBy( sepBy(
",", ",",
seq( seq(
field("field", $.identifier), field("field", $._field_identifier),
"=", "=",
field("init", $._expr), field("init", $._expr),
), ),

View file

@ -142,6 +142,15 @@
"named": true, "named": true,
"value": "type_identifier" "value": "type_identifier"
}, },
"_field_identifier": {
"type": "ALIAS",
"content": {
"type": "SYMBOL",
"name": "identifier"
},
"named": true,
"value": "field_identifier"
},
"escape_sequence": { "escape_sequence": {
"type": "IMMEDIATE_TOKEN", "type": "IMMEDIATE_TOKEN",
"content": { "content": {
@ -259,7 +268,7 @@
"name": "field", "name": "field",
"content": { "content": {
"type": "SYMBOL", "type": "SYMBOL",
"name": "identifier" "name": "_field_identifier"
} }
} }
] ]
@ -731,7 +740,7 @@
"name": "field", "name": "field",
"content": { "content": {
"type": "SYMBOL", "type": "SYMBOL",
"name": "identifier" "name": "_field_identifier"
} }
}, },
{ {
@ -765,7 +774,7 @@
"name": "field", "name": "field",
"content": { "content": {
"type": "SYMBOL", "type": "SYMBOL",
"name": "identifier" "name": "_field_identifier"
} }
}, },
{ {
@ -1460,7 +1469,8 @@
} }
], ],
"inline": [ "inline": [
"_type_identifier" "_type_identifier",
"_field_identifier"
], ],
"supertypes": [] "supertypes": []
} }

View file

@ -1466,7 +1466,7 @@
"required": false, "required": false,
"types": [ "types": [
{ {
"type": "identifier", "type": "field_identifier",
"named": true "named": true
} }
] ]
@ -1596,7 +1596,7 @@
"required": true, "required": true,
"types": [ "types": [
{ {
"type": "identifier", "type": "field_identifier",
"named": true "named": true
} }
] ]
@ -2303,6 +2303,10 @@
"type": "escape_sequence", "type": "escape_sequence",
"named": true "named": true
}, },
{
"type": "field_identifier",
"named": true
},
{ {
"type": "for", "type": "for",
"named": false "named": false

View file

@ -9,7 +9,7 @@
#define STATE_COUNT 148 #define STATE_COUNT 148
#define LARGE_STATE_COUNT 2 #define LARGE_STATE_COUNT 2
#define SYMBOL_COUNT 87 #define SYMBOL_COUNT 87
#define ALIAS_COUNT 1 #define ALIAS_COUNT 2
#define TOKEN_COUNT 49 #define TOKEN_COUNT 49
#define EXTERNAL_TOKEN_COUNT 1 #define EXTERNAL_TOKEN_COUNT 1
#define FIELD_COUNT 26 #define FIELD_COUNT 26
@ -103,7 +103,8 @@ enum {
aux_sym__declaration_chunk_repeat1 = 84, aux_sym__declaration_chunk_repeat1 = 84,
aux_sym__declaration_chunk_repeat2 = 85, aux_sym__declaration_chunk_repeat2 = 85,
aux_sym_record_type_repeat1 = 86, aux_sym_record_type_repeat1 = 86,
alias_sym_type_identifier = 87, alias_sym_field_identifier = 87,
alias_sym_type_identifier = 88,
}; };
static const char * const ts_symbol_names[] = { static const char * const ts_symbol_names[] = {
@ -194,6 +195,7 @@ static const char * const ts_symbol_names[] = {
[aux_sym__declaration_chunk_repeat1] = "_declaration_chunk_repeat1", [aux_sym__declaration_chunk_repeat1] = "_declaration_chunk_repeat1",
[aux_sym__declaration_chunk_repeat2] = "_declaration_chunk_repeat2", [aux_sym__declaration_chunk_repeat2] = "_declaration_chunk_repeat2",
[aux_sym_record_type_repeat1] = "record_type_repeat1", [aux_sym_record_type_repeat1] = "record_type_repeat1",
[alias_sym_field_identifier] = "field_identifier",
[alias_sym_type_identifier] = "type_identifier", [alias_sym_type_identifier] = "type_identifier",
}; };
@ -285,6 +287,7 @@ static const TSSymbol ts_symbol_map[] = {
[aux_sym__declaration_chunk_repeat1] = aux_sym__declaration_chunk_repeat1, [aux_sym__declaration_chunk_repeat1] = aux_sym__declaration_chunk_repeat1,
[aux_sym__declaration_chunk_repeat2] = aux_sym__declaration_chunk_repeat2, [aux_sym__declaration_chunk_repeat2] = aux_sym__declaration_chunk_repeat2,
[aux_sym_record_type_repeat1] = aux_sym_record_type_repeat1, [aux_sym_record_type_repeat1] = aux_sym_record_type_repeat1,
[alias_sym_field_identifier] = alias_sym_field_identifier,
[alias_sym_type_identifier] = alias_sym_type_identifier, [alias_sym_type_identifier] = alias_sym_type_identifier,
}; };
@ -637,6 +640,10 @@ static const TSSymbolMetadata ts_symbol_metadata[] = {
.visible = false, .visible = false,
.named = false, .named = false,
}, },
[alias_sym_field_identifier] = {
.visible = true,
.named = true,
},
[alias_sym_type_identifier] = { [alias_sym_type_identifier] = {
.visible = true, .visible = true,
.named = true, .named = true,
@ -872,6 +879,9 @@ static const TSSymbol ts_alias_sequences[PRODUCTION_ID_COUNT][MAX_ALIAS_SEQUENCE
[7] = { [7] = {
[1] = anon_sym_DASH, [1] = anon_sym_DASH,
}, },
[8] = {
[2] = alias_sym_field_identifier,
},
[15] = { [15] = {
[0] = alias_sym_type_identifier, [0] = alias_sym_type_identifier,
}, },
@ -883,12 +893,17 @@ static const TSSymbol ts_alias_sequences[PRODUCTION_ID_COUNT][MAX_ALIAS_SEQUENCE
}, },
[25] = { [25] = {
[0] = alias_sym_type_identifier, [0] = alias_sym_type_identifier,
[2] = alias_sym_field_identifier,
}, },
[32] = { [32] = {
[3] = alias_sym_type_identifier, [3] = alias_sym_type_identifier,
}, },
[33] = { [33] = {
[0] = alias_sym_type_identifier, [0] = alias_sym_type_identifier,
[2] = alias_sym_field_identifier,
},
[36] = {
[1] = alias_sym_field_identifier,
}, },
}; };

View file

@ -40,9 +40,9 @@ record_type { a = 12, b = "27" }
(source_file (source_file
(record_expression (record_expression
type: (type_identifier) type: (type_identifier)
field: (identifier) field: (field_identifier)
init: (integer_literal) init: (integer_literal)
field: (identifier) field: (field_identifier)
init: (string_literal))) init: (string_literal)))
================================================================================ ================================================================================
@ -56,7 +56,7 @@ record_type { a = 12 }
(source_file (source_file
(record_expression (record_expression
type: (type_identifier) type: (type_identifier)
field: (identifier) field: (field_identifier)
init: (integer_literal))) init: (integer_literal)))
================================================================================ ================================================================================
@ -82,7 +82,7 @@ record_type { a = 12, }
(source_file (source_file
(record_expression (record_expression
type: (type_identifier) type: (type_identifier)
field: (identifier) field: (field_identifier)
init: (integer_literal) init: (integer_literal)
(ERROR))) (ERROR)))
@ -156,4 +156,4 @@ a := array[12] := record.field
index: (integer_literal)) index: (integer_literal))
right: (record_value right: (record_value
record: (identifier) record: (identifier)
field: (identifier))))) field: (field_identifier)))))

View file

@ -33,4 +33,4 @@ a_record.field
(source_file (source_file
(record_value (record_value
record: (identifier) record: (identifier)
field: (identifier))) field: (field_identifier)))