remove escape sequence for single quoted string

This commit is contained in:
Dmitriy Pleshevskiy 2022-12-11 14:16:23 +03:00
parent 3fe837dccb
commit fc3754658c
Signed by: pleshevskiy
GPG Key ID: 1B59187B161C0215
5 changed files with 32 additions and 30 deletions

View File

@ -286,12 +286,7 @@ module.exports = grammar({
choice( choice(
seq( seq(
"'", "'",
repeat( alias($._unescaped_single_string_fragment, $.string_fragment),
choice(
alias($._unescaped_single_string_fragment, $.string_fragment),
$.escape_sequence
)
),
"'" "'"
), ),
seq( seq(
@ -306,7 +301,7 @@ module.exports = grammar({
) )
), ),
_unescaped_single_string_fragment: ($) => token.immediate(/[^'\\\n]+/), _unescaped_single_string_fragment: ($) => token.immediate(/[^'\n]+/),
_unescaped_double_string_fragment: ($) => token.immediate(/[^"\\\n]+/), _unescaped_double_string_fragment: ($) => token.immediate(/[^"\\\n]+/),

View File

@ -1213,25 +1213,13 @@
"value": "'" "value": "'"
}, },
{ {
"type": "REPEAT", "type": "ALIAS",
"content": { "content": {
"type": "CHOICE", "type": "SYMBOL",
"members": [ "name": "_unescaped_single_string_fragment"
{ },
"type": "ALIAS", "named": true,
"content": { "value": "string_fragment"
"type": "SYMBOL",
"name": "_unescaped_single_string_fragment"
},
"named": true,
"value": "string_fragment"
},
{
"type": "SYMBOL",
"name": "escape_sequence"
}
]
}
}, },
{ {
"type": "STRING", "type": "STRING",
@ -1279,7 +1267,7 @@
"type": "IMMEDIATE_TOKEN", "type": "IMMEDIATE_TOKEN",
"content": { "content": {
"type": "PATTERN", "type": "PATTERN",
"value": "[^'\\\\\\n]+" "value": "[^'\\n]+"
} }
}, },
"_unescaped_double_string_fragment": { "_unescaped_double_string_fragment": {

Binary file not shown.

View File

@ -57,6 +57,25 @@ Use quoted string as a shape key
(shape (shape_key (string (string_fragment)))) (shape (shape_key (string (string_fragment))))
) )
================================================================================
Use escape sequence in quoted string as a shape key
================================================================================
'\# hello \# world'
"\# hello \# world"
--------------------------------------------------------------------------------
(source_file
(shape (shape_key (string (string_fragment))))
(shape (shape_key (string
(escape_sequence)
(string_fragment)
(escape_sequence)
(string_fragment)
)))
)
================================================================================ ================================================================================
Define multiple shapes using semicolons Define multiple shapes using semicolons
================================================================================ ================================================================================
@ -159,9 +178,9 @@ foo: |go
) )
================================================================================ ================================================================================
Text block with quotes (d2-vim style) Text block with quotes (custom escape characters)
================================================================================ ================================================================================
foo: |`go foo: |$$$go
awsSession := From(c.Request.Context()) awsSession := From(c.Request.Context())
@ -171,7 +190,7 @@ foo: |`go
ctx, cancelFn := context.WithTimeout(c.Request.Context(), AWS_TIMEOUT) ctx, cancelFn := context.WithTimeout(c.Request.Context(), AWS_TIMEOUT)
defer cancelFn() defer cancelFn()
`| $$$|
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
@ -190,7 +209,7 @@ Online text block
================================================================================ ================================================================================
foo: | helo world | foo: | helo world |
bar: |%%md ## hello world %%| bar: |##md ## hello world ##|
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------

Binary file not shown.