From aee819955f7b9fc4ebe4296377446d60b9dc9cc4 Mon Sep 17 00:00:00 2001 From: Christoph Seitz Date: Wed, 20 Jun 2018 17:41:19 +0200 Subject: [PATCH] Update documentation. --- src/vs/editor/contrib/snippet/snippet.md | 31 ++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/src/vs/editor/contrib/snippet/snippet.md b/src/vs/editor/contrib/snippet/snippet.md index 403cda77438..6b29d44c16e 100644 --- a/src/vs/editor/contrib/snippet/snippet.md +++ b/src/vs/editor/contrib/snippet/snippet.md @@ -53,6 +53,26 @@ ${TM_FILENAME/(.*)\..+$/$1/} |-> resolves to the filename ``` +Placeholder-Transform +-- + +Like a Variable-Transform, a transformation of a placeholder allows changing the inserted text for the placeholder when moving to the next tab stop. +The inserted text is matched with the regular expression and the match or matches - depending on the options - are replaced with the specified replacement format text. +Every occurrence of a placeholder can define its own transformation independently using the value of the first placeholder. +The format for Placeholder-Transforms is the same as for Variable-Transforms. + +The following sample removes an underscore at the beginning of the text. `_transform` becomes `transform`. + +``` +${1/^_(.*)/$1/} + | | | |-> No options + | | | + | | |-> Replace it with the first capture group + | | + | |-> Regular expression to capture everything after the underscore + | + |-> Placeholder Index +``` Grammar -- @@ -61,12 +81,17 @@ Below is the EBNF for snippets. With `\` (backslash) you can escape `$`, `}` and ``` any ::= tabstop | placeholder | choice | variable | text -tabstop ::= '$' int | '${' int '}' +tabstop ::= '$' int + | '${' int '}' + | '${' int transform '}' placeholder ::= '${' int ':' any '}' + | '${' int ':' any transform '}' choice ::= '${' int '|' text (',' text)* '|}' + | '${' int '|' text (',' text)* '|' transform '}' variable ::= '$' var | '${' var }' | '${' var ':' any '}' - | '${' var '/' regex '/' (format | text)+ '/' options '}' + | '${' var transform '}' +transform ::= '/' regex '/' (format | text)+ '/' options format ::= '$' int | '${' int '}' | '${' int ':' '/upcase' | '/downcase' | '/capitalize' '}' | '${' int ':+' if '}' @@ -78,3 +103,5 @@ var ::= [_a-zA-Z] [_a-zA-Z0-9]* int ::= [0-9]+ text ::= .* ``` + +Transformations for placeholders and choices are an extension to the TextMate snippet grammar and only support by Visual Studio Code. \ No newline at end of file