From adcee9355e6eff3e95bb4a0eb844ec16d07b7ace Mon Sep 17 00:00:00 2001 From: Garrett D'Amore Date: Sun, 28 Jul 2024 18:42:51 -0700 Subject: [PATCH] misc fixups --- grammar.js | 8 ++++---- queries/nova-highlights.scm | 4 ++-- src/grammar.json | 28 ++++++++++++---------------- src/node-types.json | 21 ++++++++++----------- src/parser.c | 4 ++-- test/corpus/quotedstring.scm | 20 +++++++++++++++++++- 6 files changed, 49 insertions(+), 36 deletions(-) diff --git a/grammar.js b/grammar.js index ba07ff8..d5cde41 100644 --- a/grammar.js +++ b/grammar.js @@ -1201,12 +1201,12 @@ module.exports = grammar({ choice( seq( "`", - field("content", token.immediate(prec(1, /[^`]*/))), + token.immediate(prec(1, /[^`]*/)), token.immediate(/`[cdw]?/), ), seq( 'r"', - field("content", token.immediate(prec(1, /[^"]*/))), + token.immediate(prec(1, /[^"]*/)), token.immediate(/"[cdw]?/), ), ), @@ -1214,14 +1214,14 @@ module.exports = grammar({ hex_string: ($) => seq( 'x"', - field("content", token.immediate(prec(1, /[0-9A-Fa-f\s]*/))), + token.immediate(prec(1, /[0-9A-Fa-f\s]*/)), token.immediate(/"[cdw]?/), ), quoted_string: ($) => seq( '"', - field("content", repeat(choice(/[^"\\]+/, $.escape_sequence))), + repeat(choice(/[^"\\]+/, $.escape_sequence)), token.immediate(/"[cdw]?/), ), diff --git a/queries/nova-highlights.scm b/queries/nova-highlights.scm index a6baa7d..b3008c1 100644 --- a/queries/nova-highlights.scm +++ b/queries/nova-highlights.scm @@ -25,7 +25,7 @@ (float_literal) @value.number (char_literal) @value.number ; not sure what is best for this (special_keyword) @value.symbols -(htmlenttity) @value.entity +(htmlentity) @value.entity (escape_sequence) @value.entity [ @@ -254,7 +254,7 @@ (version_specification (version) (int_literal) @invalid) ; deprecated in 2.101 (version_condition (identifier) @value.symbol) -(module_fqn) @cdata ; this is a crummy workaround since we don't have anything for imports +(module_fqn) @processing ; this is a crummy workaround since we don't have anything for imports (module_declaration (module_fqn)) @definition.package (class_declaration (identifier) @identifier.type.class) (struct_declaration (identifier) @identifier.type.struct) diff --git a/src/grammar.json b/src/grammar.json index 44743fd..f0d7a5a 100644 --- a/src/grammar.json +++ b/src/grammar.json @@ -6071,23 +6071,19 @@ "value": "\"" }, { - "type": "FIELD", - "name": "content", + "type": "REPEAT", "content": { - "type": "REPEAT", - "content": { - "type": "CHOICE", - "members": [ - { - "type": "PATTERN", - "value": "[^\"\\\\]+" - }, - { - "type": "SYMBOL", - "name": "escape_sequence" - } - ] - } + "type": "CHOICE", + "members": [ + { + "type": "PATTERN", + "value": "[^\"\\\\]+" + }, + { + "type": "SYMBOL", + "name": "escape_sequence" + } + ] } }, { diff --git a/src/node-types.json b/src/node-types.json index 46aa0d2..0a95cf8 100644 --- a/src/node-types.json +++ b/src/node-types.json @@ -9699,17 +9699,16 @@ { "type": "quoted_string", "named": true, - "fields": { - "content": { - "multiple": true, - "required": false, - "types": [ - { - "type": "escape_sequence", - "named": true - } - ] - } + "fields": {}, + "children": { + "multiple": true, + "required": false, + "types": [ + { + "type": "escape_sequence", + "named": true + } + ] } }, { diff --git a/src/parser.c b/src/parser.c index 95d2889..382b2b3 100644 --- a/src/parser.c +++ b/src/parser.c @@ -535491,8 +535491,8 @@ static const TSParseActionEntry ts_parse_actions[] = { [2800] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_char_literal, 3, 0, 0), [2802] = {.entry = {.count = 1, .reusable = false}}, REDUCE(sym_special_keyword, 1, 0, 0), [2804] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_special_keyword, 1, 0, 0), - [2806] = {.entry = {.count = 1, .reusable = false}}, REDUCE(sym_quoted_string, 3, 0, 11), - [2808] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_quoted_string, 3, 0, 11), + [2806] = {.entry = {.count = 1, .reusable = false}}, REDUCE(sym_quoted_string, 3, 0, 0), + [2808] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_quoted_string, 3, 0, 0), [2810] = {.entry = {.count = 1, .reusable = false}}, REDUCE(sym_keyword, 1, 0, 0), [2812] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_keyword, 1, 0, 0), [2814] = {.entry = {.count = 1, .reusable = false}}, REDUCE(sym_quoted_string, 2, 0, 0), diff --git a/test/corpus/quotedstring.scm b/test/corpus/quotedstring.scm index a837939..04bb419 100644 --- a/test/corpus/quotedstring.scm +++ b/test/corpus/quotedstring.scm @@ -47,7 +47,7 @@ auto s3 = "a\u1234b\\"; ================================================================================ Quoted String with Character Entity ================================================================================ -auto s3 = "a\&trademark;"; +auto s3 = "a\&trademark;over"; -------------------------------------------------------------------------------- @@ -91,3 +91,21 @@ auto s10 = "🥂"w; (identifier) (string_literal (quoted_string)))) + +================================================================================ +Quoted String with Entity +================================================================================ + +auto s10 = "alpha\ beta"w; + +-------------------------------------------------------------------------------- + +(source_file + (auto_declaration + (storage_class + (auto)) + (identifier) + (string_literal + (quoted_string + (escape_sequence + (htmlentity))))))