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(
choice(
alias($._unescaped_single_string_fragment, $.string_fragment), 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

@ -1212,11 +1212,6 @@
"type": "STRING", "type": "STRING",
"value": "'" "value": "'"
}, },
{
"type": "REPEAT",
"content": {
"type": "CHOICE",
"members": [
{ {
"type": "ALIAS", "type": "ALIAS",
"content": { "content": {
@ -1226,13 +1221,6 @@
"named": true, "named": true,
"value": "string_fragment" "value": "string_fragment"
}, },
{
"type": "SYMBOL",
"name": "escape_sequence"
}
]
}
},
{ {
"type": "STRING", "type": "STRING",
"value": "'" "value": "'"
@ -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.