Add support for double-quotes inside strings

This commit is contained in:
Emmanuel Briot 2022-12-12 10:58:23 +01:00
parent ec82f7b2cf
commit d6ea15a3e0
5 changed files with 39 additions and 4 deletions

View File

@ -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(

View File

@ -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)

View File

@ -33,7 +33,7 @@
"type": "TOKEN",
"content": {
"type": "PATTERN",
"value": "\"[^\"]*\""
"value": "\"(\"\"|[^\"])*\""
}
},
"character_literal": {

View File

@ -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);

34
test/corpus/literals.txt Normal file
View File

@ -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))))))