Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

[XML] add [sublime-snippet] syntax definition #576

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
96 changes: 96 additions & 0 deletions XML/Snippet Content.sublime-syntax
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
%YAML 1.2
---
# See http://www.sublimetext.com/docs/3/syntax.html
scope: text.sublime-snippet-content
name: Sublime Text Snippet Content
hidden: true
contexts:
main:
- include: possible_caret

possible_caret:
- match: '\\[$}]'
scope: constant.character.escape.sublime-snippet-content
- match: '\$(?=\{|\w)'
scope: meta.text-substitution.sublime-snippet-content keyword.other.caret.sublime-snippet-content
push: caret
- match: '\$'
scope: invalid.illegal.unescaped-dollar.sublime-snippet-content

caret:
- match: '(?:(\d+(?!\w))|(PARAM\d+|SELECTION|TM_CURRENT_LINE|TM_CURRENT_WORD|TM_FILENAME|TM_FILEPATH|TM_FULLNAME|TM_LINE_INDEX|TM_LINE_NUMBER|TM_SELECTED_TEXT|TM_SOFT_TABS|TM_TAB_SIZE)\b)' # http://docs.sublimetext.info/en/latest/extensibility/snippets.html?highlight=snippet#environment-variables
captures:
1: constant.numeric.sublime-snippet-content
2: constant.language.sublime-snippet-content
pop: true
- match: '\{'
scope: keyword.other.caret.begin.sublime-snippet-content
set: [inside_caret, caret]
- match: '\w+'
scope: meta.text-substitution.sublime-snippet-content constant.other.sublime-snippet-content #invalid.illegal.unknown-variable.sublime-snippet-content
pop: true

inside_caret:
- meta_scope: meta.text-substitution.sublime-snippet-content
- match: '\}'
scope: keyword.other.caret.end.sublime-snippet-content
pop: true
- include: possible_caret
- match: ':'
scope: keyword.operator.alternation.sublime-snippet-content
push:
- meta_content_scope: string.unquoted.text-substitution.sublime-snippet-content
- include: possible_caret
- match: '(?=\})'
pop: true
- match: '/'
scope: keyword.operator.regexp.begin.sublime-snippet-content
push:
- match: '/'
scope: keyword.operator.regexp.end.sublime-snippet-content
set:
- match: '/'
scope: keyword.operator.replacement.end.sublime-snippet-content
set:
- match: '[gims-]*' # x mode doesn't seem to work properly in snippets
scope: storage.modifier.mode.regexp.sublime-snippet-content
- match: '(?=\})'
pop: true
- match: '[^}]+'
scope: invalid.illegal.unexpected-token.sublime-snippet-content
- include: regex_replacement
- include: scope:source.regexp#base-literal

regex_replacement: # http://www.boost.org/doc/libs/1_56_0/libs/regex/doc/html/boost_regex/format/boost_format_syntax.html
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

- match: '\$\$'
scope: constant.character.escape.regexp-replacement
- match: '\$(\d+|\{\d+\}|&|\+(\{\w+\})?|^N)'
scope: keyword.other.backref-and-recursion.regexp-replacement
- match: \$(MATCH|PREMATCH|POSTMATCH|\{\^(MATCH|PREMATCH|POSTMATCH)\}|[`']|LAST_PAREN_MATCH|LAST_SUBMATCH_RESULT)
scope: keyword.other.backref-and-recursion.regexp-replacement
- match: '\\[1-9]'
scope: keyword.other.backref-and-recursion.regexp-replacement
- match: '\\[aefnrtv()]'
scope: constant.character.escape.regexp-replacement
- match: '\\[lLuUE]'
scope: keyword.operator.case-conversion.regexp-replacement
- match: '\)'
scope: meta.literal.regexp-replacement
- match: '\\x(\h{2}|\{\h{4}\})'
scope: constant.character.escape.regexp-replacement
- match: '\(\?([1-9]|\{\w+\})'
scope: keyword.other.backref-and-recursion.conditional.regexp-replacement
push:
- meta_scope: meta.group.conditional.regexp-replacement
- match: ':'
scope: keyword.operator.alternation.regexp-replacement
- match: '\)'
scope: keyword.other.backref-and-recursion.conditional.regexp-replacement
pop: true
- include: regex_replacement
- match: '\\\\'
scope: constant.character.escape.regexp-replacement
- match: '\\.'
scope: constant.character.escape.regexp-replacement
- match: '.'
scope: meta.literal.regexp-replacement
54 changes: 54 additions & 0 deletions XML/Snippet.sublime-syntax
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
%YAML 1.2
---
# See http://www.sublimetext.com/docs/3/syntax.html
file_extensions:
- sublime-snippet
name: Sublime Text Snippet (XML)
scope: text.xml.sublime-snippet
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that the new_snippet command in Packages/Default/new_templates.py currently references the normal XML syntax, and this should be changed in the ST3 codebase after merging.

v.assign_syntax('Packages/XML/XML.sublime-syntax')

contexts:
main:
- match: '(<)(content)(>)'
captures:
1: meta.tag.xml punctuation.definition.tag.begin.xml
2: meta.tag.xml entity.name.tag.localname.xml meta.toc-list.snippet-content.sublime-snippet
3: meta.tag.xml punctuation.definition.tag.end.xml
push:
- match: '<!\[CDATA\['
scope: string.unquoted.cdata.xml punctuation.definition.string.begin.xml
set:
- meta_content_scope: string.unquoted.cdata.xml
- match: '\]\]>'
scope: string.unquoted.cdata.xml punctuation.definition.string.end.xml
set:
- match: '<!\[CDATA\['
set:
- meta_scope: invalid.illegal.multiple-cdata-not-allowed.sublime-snippet-content
- match: '\]\]>'
pop: true
- include: inside_content
- include: snippet_content
- match: '(?=\S)'
set: inside_content
- match: '(<)(scope)(>)'
captures:
1: meta.tag.xml punctuation.definition.tag.begin.xml
2: meta.tag.xml entity.name.tag.localname.xml meta.toc-list.snippet-scope.sublime-snippet
3: meta.tag.xml punctuation.definition.tag.end.xml
- match: '(<)(tabTrigger)(>)'
captures:
1: meta.tag.xml punctuation.definition.tag.begin.xml
2: meta.tag.xml entity.name.tag.localname.xml meta.toc-list.snippet-trigger.sublime-snippet
3: meta.tag.xml punctuation.definition.tag.end.xml
- include: scope:text.xml

snippet_content:
- include: scope:text.sublime-snippet-content

inside_content:
- match: '(</)(content)(>)'
captures:
1: meta.tag.xml punctuation.definition.tag.begin.xml
2: meta.tag.xml entity.name.tag.localname.xml
3: meta.tag.xml punctuation.definition.tag.end.xml
pop: true
- include: snippet_content
2 changes: 1 addition & 1 deletion XML/XML.sublime-settings
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"hidden_extensions": ["rss", "sublime-snippet", "vcproj", "tmLanguage", "tmTheme", "tmSnippet", "tmPreferences", "dae"]
"hidden_extensions": ["rss", "vcproj", "tmLanguage", "tmTheme", "tmSnippet", "tmPreferences", "dae"]
}
Loading