From d6ea15a3e0344d010c505807c75027fe6bbb9d9b Mon Sep 17 00:00:00 2001 From: Emmanuel Briot Date: Mon, 12 Dec 2022 10:58:23 +0100 Subject: [PATCH] Add support for double-quotes inside strings --- grammar.js | 2 +- queries/highlights.scm | 4 ++-- src/grammar.json | 2 +- src/parser.c | 1 + test/corpus/literals.txt | 34 ++++++++++++++++++++++++++++++++++ 5 files changed, 39 insertions(+), 4 deletions(-) create mode 100644 test/corpus/literals.txt diff --git a/grammar.js b/grammar.js index 31c3458..3e0ac15 100644 --- a/grammar.js +++ b/grammar.js @@ -115,7 +115,7 @@ module.exports = grammar({ identifier: $ => /[a-zA-Z\u{80}-\u{10FFFF}][0-9a-zA-Z_\u{80}-\u{10FFFF}]*/u, comment: $ => token(seq('--', /.*/)), - string_literal: $ => token(/"[^"]*"/), + string_literal: $ => token(/"(""|[^"])*"/), character_literal: $ => token(/'.'/), numeric_literal: $ => token( choice( diff --git a/queries/highlights.scm b/queries/highlights.scm index 1a4003f..6133388 100644 --- a/queries/highlights.scm +++ b/queries/highlights.scm @@ -113,8 +113,8 @@ (use_clause "use" @include "type" @include) (with_clause "private" @include) (with_clause "limited" @include) -(use_clause (identifier) @namespace) -(with_clause (identifier) @namespace) +(use_clause (_) @namespace) +(with_clause (_) @namespace) (loop_statement "end" @keyword.repeat) (if_statement "end" @conditional) diff --git a/src/grammar.json b/src/grammar.json index 333c9e1..cd8ed7a 100644 --- a/src/grammar.json +++ b/src/grammar.json @@ -33,7 +33,7 @@ "type": "TOKEN", "content": { "type": "PATTERN", - "value": "\"[^\"]*\"" + "value": "\"(\"\"|[^\"])*\"" } }, "character_literal": { diff --git a/src/parser.c b/src/parser.c index f26962c..7dcc72e 100644 --- a/src/parser.c +++ b/src/parser.c @@ -5854,6 +5854,7 @@ static bool ts_lex(TSLexer *lexer, TSStateId state) { END_STATE(); case 37: ACCEPT_TOKEN(sym_string_literal); + if (lookahead == '"') ADVANCE(8); END_STATE(); case 38: ACCEPT_TOKEN(sym_character_literal); diff --git a/test/corpus/literals.txt b/test/corpus/literals.txt new file mode 100644 index 0000000..4475630 --- /dev/null +++ b/test/corpus/literals.txt @@ -0,0 +1,34 @@ +================================================================================ +String literals +================================================================================ + +A : String := "12'34"; + +-------- + +(compilation + (compilation_unit + (object_declaration + (identifier) + (identifier) + (expression + (term + (string_literal)))))) + +================================================================================ +String literals with quotes +================================================================================ + +A : String := "12""23"; + +-------- + +(compilation + (compilation_unit + (object_declaration + (identifier) + (identifier) + (expression + (term + (string_literal)))))) +