Skip to content

Commit

Permalink
Snippet: Fix syntax tests by using embed
Browse files Browse the repository at this point in the history
There was also an incorrect test case that has been fixed.
  • Loading branch information
FichteFoll committed Feb 25, 2022
1 parent 6829a2c commit bf1b059
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,28 +48,26 @@ contexts:
pop: true
- match: '/'
scope: keyword.other.regex.start.snippet
push:
- match: '/'
scope: keyword.other.regex.mid.snippet
set:
- match: '/'
scope: keyword.other.regex.end.snippet
set:
- match: '[gims-]*' # x mode doesn't seem to work properly in snippets
scope: constant.other.regex-modifier.snippet
- match: '(?=\})'
pop: true
- match: '[^}]+'
scope: invalid.illegal.unexpected-token.snippet
- match: ''
push: scope:source.regexp-replacement
with_prototype:
- match: (?=/)
pop: true
- match: ''
push:
# Will not work if extended mode is enabled in the regex
- meta_scope: source.regexp.embedded
- match: (?=/)
pop: true
- include: scope:source.regexp#base-literal
push: inside_caret_pattern

inside_caret_pattern:
- match: '/'
scope: keyword.other.regex.mid.snippet
set: inside_caret_replacement
- match: ''
embed: scope:source.regexp
escape: (?<=[^\\]|\\\\)(?=/)

inside_caret_replacement:
- match: '/'
scope: keyword.other.regex.end.snippet
set:
- match: '[gims-]*' # x mode doesn't seem to work properly in snippets
scope: constant.other.regex-modifier.snippet
- match: '(?=\})'
pop: true
- match: '[^}]+'
scope: invalid.illegal.unexpected-token.snippet
- match: ''
embed: scope:source.regexp-replacement
escape: (?<=[^\\]|\\\\)(?=/)
11 changes: 7 additions & 4 deletions Package/Sublime Text Snippet/syntax_test_snippet.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ Transformation: ${1/^(\w)|(?:_(\w))/(?1\u$1:)(?2 \u${2}:)/g}
# ^^ keyword.other.block
# ^ constant.numeric
# ^ keyword.other.regex.start
# ^ keyword.control.anchors
# ^ keyword.control.anchor
# ^^^^ meta.group
# ^^ keyword.control.character-class
# ^ keyword.operator.alternation
Expand Down Expand Up @@ -207,10 +207,13 @@ It is possible to include a literal newline in the replacement: ${1/test/_
# ^ keyword.other.block.end
${TM_CURRENT_LINE/^\\s*((?:\\/\\/[\\/!]?|#|%|--|::|(?i:rem)|'|;)\\s*).*/$1/}
# ^ meta.group.regexp meta.group.regexp meta.literal.regexp
# ^ keyword.other.regex.mid.snippet
${TM_CURRENT_LINE/^\\s*((?:\/\/[\/!]?|#|%|--|::|(?i:rem)|'|;)\\s*).*/$1/}
# ^^^^ constant.character.escape.regexp
# ^^ constant.character.escape.regexp
# ^ keyword.other.regex.end.snippet
${TM_CURRENT_LINE/^\\s*((?:\\/\1/}
# ^ keyword.other.regex.mid.snippet
]]>snippet<</content>
#^^^ meta.tag.cdata punctuation.definition.tag.end
# ^^^^^^^ source.sublime.snippet
Expand Down

0 comments on commit bf1b059

Please sign in to comment.