From 17de5b425ab004c248cdbc144699fb382a704a69 Mon Sep 17 00:00:00 2001 From: mhoffm Date: Tue, 8 Jun 2021 01:28:18 +0200 Subject: [PATCH] wip --- grammar.js | 4 ++-- queries/highlights.scm | 3 ++- src/grammar.json | 10 +++++++--- src/node-types.json | 21 ++++++++++++++------- src/parser.c | 8 ++++---- 5 files changed, 29 insertions(+), 17 deletions(-) diff --git a/grammar.js b/grammar.js index 69ff67b..1626362 100644 --- a/grammar.js +++ b/grammar.js @@ -27,13 +27,13 @@ module.exports = grammar({ )), attribute: $ => seq( - $.identifier, + field('name', $.identifier), '=', $.expression ), block: $ => seq( - field('type', $.identifier), + field('name', $.identifier), repeat(choice($.string_lit, $.identifier)), '{', optional($.body), diff --git a/queries/highlights.scm b/queries/highlights.scm index c3cb3c1..7f27078 100644 --- a/queries/highlights.scm +++ b/queries/highlights.scm @@ -1,6 +1,7 @@ ; highlights.scm -(block type: (identifier) @keyword) +(block name: (identifier) @hcl_block_name) +(attribute name: (identifier) @hcl_attribute_name) (identifier) @string.special (string_lit) @string (numeric_lit) @number diff --git a/src/grammar.json b/src/grammar.json index 204c6de..4e58cba 100644 --- a/src/grammar.json +++ b/src/grammar.json @@ -30,8 +30,12 @@ "type": "SEQ", "members": [ { - "type": "SYMBOL", - "name": "identifier" + "type": "FIELD", + "name": "name", + "content": { + "type": "SYMBOL", + "name": "identifier" + } }, { "type": "STRING", @@ -48,7 +52,7 @@ "members": [ { "type": "FIELD", - "name": "type", + "name": "name", "content": { "type": "SYMBOL", "name": "identifier" diff --git a/src/node-types.json b/src/node-types.json index 585350c..75f2c28 100644 --- a/src/node-types.json +++ b/src/node-types.json @@ -2,18 +2,25 @@ { "type": "attribute", "named": true, - "fields": {}, + "fields": { + "name": { + "multiple": false, + "required": true, + "types": [ + { + "type": "identifier", + "named": true + } + ] + } + }, "children": { - "multiple": true, + "multiple": false, "required": true, "types": [ { "type": "expression", "named": true - }, - { - "type": "identifier", - "named": true } ] } @@ -22,7 +29,7 @@ "type": "block", "named": true, "fields": { - "type": { + "name": { "multiple": false, "required": true, "types": [ diff --git a/src/parser.c b/src/parser.c index 8acf52d..039e7ca 100644 --- a/src/parser.c +++ b/src/parser.c @@ -294,12 +294,12 @@ static const TSSymbolMetadata ts_symbol_metadata[] = { }; enum { - field_type = 1, + field_name = 1, }; static const char * const ts_field_names[] = { [0] = NULL, - [field_type] = "type", + [field_name] = "name", }; static const TSFieldMapSlice ts_field_map_slices[PRODUCTION_ID_COUNT] = { @@ -308,7 +308,7 @@ static const TSFieldMapSlice ts_field_map_slices[PRODUCTION_ID_COUNT] = { static const TSFieldMapEntry ts_field_map_entries[] = { [0] = - {field_type, 0}, + {field_name, 0}, }; static const TSSymbol ts_alias_sequences[PRODUCTION_ID_COUNT][MAX_ALIAS_SEQUENCE_LENGTH] = { @@ -2942,7 +2942,7 @@ static const TSParseActionEntry ts_parse_actions[] = { [109] = {.entry = {.count = 1, .reusable = true}}, SHIFT(5), [111] = {.entry = {.count = 1, .reusable = true}}, SHIFT(15), [113] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_block, 4, .production_id = 1), - [115] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_attribute, 3), + [115] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_attribute, 3, .production_id = 1), [117] = {.entry = {.count = 1, .reusable = true}}, SHIFT(14), [119] = {.entry = {.count = 1, .reusable = true}}, SHIFT(13), [121] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_block, 5, .production_id = 1),