Skip to content

Allow top level text to not escape } when it is not part of the ${} #2033

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Open
echasnovski opened this issue Oct 4, 2024 · 0 comments
Open
Milestone

Comments

@echasnovski
Copy link

Currently snippet grammar states the following:

any         ::= tabstop | placeholder | choice | variable | text
...
text        ::= ([^$}\] | '\$' | '\}' | '\\')*

This means that } should be escaped even when not used as closing part of ${}. For example, in this snippet string: hello {world\\}.

However, it introduces friction for languages which use {} (which are many, I'd say).

VS Code also seems to allow not escaping } in the top level context (here is one example).


Proposal: allow top level text to not escape }. I believe this can be encapsulated in the following change to the grammar:

Patch for changing grammar
diff --git a/_specifications/lsp/3.18/language/completion.md b/_specifications/lsp/3.18/language/completion.md
index 68fe55b..adf45b8 100644
--- a/_specifications/lsp/3.18/language/completion.md
+++ b/_specifications/lsp/3.18/language/completion.md
@@ -819,8 +819,8 @@ Below is the grammar for snippets in EBNF ([extended Backus-Naur form, XML varia
 any         ::= tabstop | placeholder | choice | variable | text
 tabstop     ::= '$' int | '${' int '}'
-placeholder ::= '${' int ':' any '}'
+placeholder ::= '${' int ':' (tabstop | placeholder | choice | variable | innertext) '}'
 choice      ::= '${' int '|' choicetext (',' choicetext)* '|}'
 variable    ::= '$' var | '${' var }'
-                | '${' var ':' any '}'
+                | '${' var ':' (tabstop | placeholder | choice | variable | innertext) '}'
                 | '${' var '/' regex '/' (format | formattext)* '/' options '}'
 format      ::= '$' int | '${' int '}'
@@ -838,10 +838,11 @@ options     ::= Regular Expression option (ctor-options)
 var         ::= [_a-zA-Z] [_a-zA-Z0-9]*
 int         ::= [0-9]+
-text        ::= ([^$}\] | '\$' | '\}' | '\\')*
+text        ::= ([^$\] | '\$' | '\\')*
+innertext   ::= ([^$}\] | '\$' | '\}' | '\\')*
 choicetext  ::= ([^,|\] | '\,' | '\|' | '\\')*
 formattext  ::= ([^$/\] | '\$' | '\/' | '\\')*
-ifOnly      ::= text
+ifOnly      ::= innertext
 if          ::= ([^:\] | '\:' | '\\')*
-else        ::= text
+else        ::= innertext
# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

No branches or pull requests

2 participants