From dffcf27797758ad46e89c63f4e88a680a2ff6ea8 Mon Sep 17 00:00:00 2001 From: DeathAxe <deathaxe82@googlemail.com> Date: Tue, 7 Sep 2021 19:11:32 +0200 Subject: [PATCH 1/9] Fix compatibility issue with ST4114+ Fixes #213 This commit applies the required patch of ST4114's HTML.sublime-syntax in order to fix VUE's incompatibility with most recent ST, while maintaining backward compatibility with older builds. The relevant contexts are overridden and variables are copied over from HTML.sublime-syntax. Note: The `style-close-tag` was probably not needed, as it hasn't changed, but it is copied to maintain formal consistency with script tags. --- Vue Component.sublime-syntax | 329 ++++++++++++++++++----- Vue Component.sublime-syntax.yaml-macros | 113 +++++++- src/macros.py | 28 +- 3 files changed, 397 insertions(+), 73 deletions(-) diff --git a/Vue Component.sublime-syntax b/Vue Component.sublime-syntax index 026c5b8..89dc5e7 100644 --- a/Vue Component.sublime-syntax +++ b/Vue Component.sublime-syntax @@ -7,6 +7,48 @@ scope: text.html.vue file_extensions: - vue +variables: + # Embedded script and style syntaxes may be wrapped into html comments for + # historical reasons. The following patterns match them, while maintaining + # correct boundaries of embedded source scopes. That's required to enable + # embedded syntax's comment toggling in the first and last line. + # + # see: + # - https://github.com/sublimehq/Packages/issues/2322 + # - https://github.com/sublimehq/sublime_text/issues/4701 + script_content_begin: |- + (?x: + # whitespace followed by opening html comment begin punctuation + \s*(<!--) + # or any other non-whitespace character ahead + | (?=\s*(?!<!--)\S) + # or beginning of a line + | ^ + ) + script_content_end: |- + (?x: + # optional html comment end punctuation followed by </script> tag + (?: (\s*) (-->) \s* )? (?=</(?i:script){{tag_name_break_char}}) + # or standalone html comment end punctuation in a line + | ^ (\s*) (-->) \s* $ + ) + style_content_begin: '{{script_content_begin}}' + style_content_end: |- + (?x: + # optional html comment end punctuation followed by </style> tag + (?: (\s*) (-->) \s* )? (?=</(?i:style){{tag_name_break_char}}) + # or standalone html comment end punctuation in a line + | ^ (\s*) (-->) \s* $ + ) + template_content_begin: '{{script_content_begin}}' + template_content_end: |- + (?x: + # optional html comment end punctuation followed by </template> tag + (?: (\s*) (-->) \s* )? (?=</(?i:template){{tag_name_break_char}}) + # or standalone html comment end punctuation in a line + | ^ (\s*) (-->) \s* $ + ) + contexts: main: - meta_prepend: true @@ -73,13 +115,48 @@ contexts: escape: "'" escape_captures: 0: meta.string.html string.quoted.single.html punctuation.definition.string.end.html - - include: else-pop + style-close-tag: + # for compatibility with ST builds before 4114 + - match: (</)((?i:style){{tag_name_break}}) + captures: + 1: punctuation.definition.tag.begin.html + 2: entity.name.tag.style.html + set: + - meta_scope: meta.tag.style.end.html + - include: tag-end + style-common: - meta_prepend: true - include: style-lang-attribute + style-css: + # for compatibility with ST builds before 4114 + - meta_scope: meta.tag.style.begin.html + - include: style-common + - match: '>' + scope: punctuation.definition.tag.end.html + set: + - style-close-tag + - style-css-content + + style-css-content: + # for compatibility with ST builds before 4114 + - meta_include_prototype: false + - match: '{{style_content_begin}}' + captures: + 1: comment.block.html punctuation.definition.comment.begin.html + pop: 1 # make sure to match only once + embed: scope:source.css + embed_scope: source.css.embedded.html + escape: '{{style_content_end}}' + escape_captures: + 1: source.css.embedded.html + 2: comment.block.html punctuation.definition.comment.end.html + 3: source.css.embedded.html + 4: comment.block.html punctuation.definition.comment.end.html + style-lang-attribute: - match: (?i:lang){{attribute_name_break}} scope: meta.attribute-with-value.html entity.other.attribute-name.html @@ -101,11 +178,19 @@ contexts: - match: '>' scope: punctuation.definition.tag.end.html set: - - include: style-close-tag - - embed_scope: source.sass.embedded.html - match: '' - embed: scope:source.sass - escape: (?i)(?=(?:-->\s*)?</style{{tag_name_break_char}}) + - - include: style-close-tag + - - match: '{{style_content_begin}}' + escape_captures: + 1: source.sass.embedded.html + 2: comment.block.html punctuation.definition.comment.end.html + 3: source.sass.embedded.html + 4: comment.block.html punctuation.definition.comment.end.html + embed_scope: source.sass.embedded.html + captures: + 1: comment.block.html punctuation.definition.comment.begin.html + pop: 1 + embed: scope:source.sass + escape: '{{style_content_end}}' - tag-generic-attribute-meta - tag-generic-attribute-value - match: (?i)(?=scss{{unquoted_attribute_break}}|\'scss\'|"scss") @@ -115,11 +200,19 @@ contexts: - match: '>' scope: punctuation.definition.tag.end.html set: - - include: style-close-tag - - embed_scope: source.scss.embedded.html - match: '' - embed: scope:source.scss - escape: (?i)(?=(?:-->\s*)?</style{{tag_name_break_char}}) + - - include: style-close-tag + - - match: '{{style_content_begin}}' + escape_captures: + 1: source.scss.embedded.html + 2: comment.block.html punctuation.definition.comment.end.html + 3: source.scss.embedded.html + 4: comment.block.html punctuation.definition.comment.end.html + embed_scope: source.scss.embedded.html + captures: + 1: comment.block.html punctuation.definition.comment.begin.html + pop: 1 + embed: scope:source.scss + escape: '{{style_content_end}}' - tag-generic-attribute-meta - tag-generic-attribute-value - match: (?i)(?=stylus{{unquoted_attribute_break}}|\'stylus\'|"stylus") @@ -129,11 +222,19 @@ contexts: - match: '>' scope: punctuation.definition.tag.end.html set: - - include: style-close-tag - - embed_scope: source.stylus.embedded.html - match: '' - embed: scope:source.stylus - escape: (?i)(?=(?:-->\s*)?</style{{tag_name_break_char}}) + - - include: style-close-tag + - - match: '{{style_content_begin}}' + escape_captures: + 1: source.stylus.embedded.html + 2: comment.block.html punctuation.definition.comment.end.html + 3: source.stylus.embedded.html + 4: comment.block.html punctuation.definition.comment.end.html + embed_scope: source.stylus.embedded.html + captures: + 1: comment.block.html punctuation.definition.comment.begin.html + pop: 1 + embed: scope:source.stylus + escape: '{{style_content_end}}' - tag-generic-attribute-meta - tag-generic-attribute-value - match: (?i)(?=postcss\?parser=sugarss{{unquoted_attribute_break}}|\'postcss\?parser=sugarss\'|"postcss\?parser=sugarss") @@ -143,11 +244,19 @@ contexts: - match: '>' scope: punctuation.definition.tag.end.html set: - - include: style-close-tag - - embed_scope: source.sss.embedded.html - match: '' - embed: scope:source.sss - escape: (?i)(?=(?:-->\s*)?</style{{tag_name_break_char}}) + - - include: style-close-tag + - - match: '{{style_content_begin}}' + escape_captures: + 1: source.sss.embedded.html + 2: comment.block.html punctuation.definition.comment.end.html + 3: source.sss.embedded.html + 4: comment.block.html punctuation.definition.comment.end.html + embed_scope: source.sss.embedded.html + captures: + 1: comment.block.html punctuation.definition.comment.begin.html + pop: 1 + embed: scope:source.sss + escape: '{{style_content_end}}' - tag-generic-attribute-meta - tag-generic-attribute-value - match: (?i)(?=postcss{{unquoted_attribute_break}}|\'postcss\'|"postcss") @@ -157,11 +266,19 @@ contexts: - match: '>' scope: punctuation.definition.tag.end.html set: - - include: style-close-tag - - embed_scope: source.postcss.embedded.html - match: '' - embed: scope:source.postcss - escape: (?i)(?=(?:-->\s*)?</style{{tag_name_break_char}}) + - - include: style-close-tag + - - match: '{{style_content_begin}}' + escape_captures: + 1: source.postcss.embedded.html + 2: comment.block.html punctuation.definition.comment.end.html + 3: source.postcss.embedded.html + 4: comment.block.html punctuation.definition.comment.end.html + embed_scope: source.postcss.embedded.html + captures: + 1: comment.block.html punctuation.definition.comment.begin.html + pop: 1 + embed: scope:source.postcss + escape: '{{style_content_end}}' - tag-generic-attribute-meta - tag-generic-attribute-value - match: (?i)(?=less{{unquoted_attribute_break}}|\'less\'|"less") @@ -171,11 +288,19 @@ contexts: - match: '>' scope: punctuation.definition.tag.end.html set: - - include: style-close-tag - - embed_scope: source.less.embedded.html - match: '' - embed: scope:source.less - escape: (?i)(?=(?:-->\s*)?</style{{tag_name_break_char}}) + - - include: style-close-tag + - - match: '{{style_content_begin}}' + escape_captures: + 1: source.less.embedded.html + 2: comment.block.html punctuation.definition.comment.end.html + 3: source.less.embedded.html + 4: comment.block.html punctuation.definition.comment.end.html + embed_scope: source.less.embedded.html + captures: + 1: comment.block.html punctuation.definition.comment.begin.html + pop: 1 + embed: scope:source.less + escape: '{{style_content_end}}' - tag-generic-attribute-meta - tag-generic-attribute-value - match: (?=\S) @@ -184,15 +309,45 @@ contexts: - tag-generic-attribute-meta - tag-generic-attribute-value + script-close-tag: + # for compatibility with ST builds before 4114 + - match: (</)((?i:script){{tag_name_break}}) + captures: + 1: punctuation.definition.tag.begin.html + 2: entity.name.tag.script.html + set: + - meta_scope: meta.tag.script.end.html + - include: tag-end + script-common: - meta_prepend: true - include: script-lang-attribute + script-javascript: + # for compatibility with ST builds before 4114 + - meta_scope: meta.tag.script.begin.html + - include: script-common + - match: '>' + scope: punctuation.definition.tag.end.html + set: + - script-close-tag + - script-javascript-content + script-javascript-content: - - match: (?=\S) + # for compatibility with ST builds before 4114 + - meta_include_prototype: false + - match: '{{script_content_begin}}' + captures: + 1: comment.block.html punctuation.definition.comment.begin.html + pop: 1 # make sure to match only once embed: scope:source.js embed_scope: source.js.embedded.html - escape: '{{script_close_lookahead}}' + escape: '{{script_content_end}}' + escape_captures: + 1: source.js.embedded.html + 2: comment.block.html punctuation.definition.comment.end.html + 3: source.js.embedded.html + 4: comment.block.html punctuation.definition.comment.end.html script-lang-attribute: - match: (?i:lang){{attribute_name_break}} @@ -215,11 +370,19 @@ contexts: - match: '>' scope: punctuation.definition.tag.end.html set: - - include: script-close-tag - - embed_scope: source.coffee.embedded.html - match: '' - embed: scope:source.coffee - escape: (?i)(?=(?:-->\s*)?</script{{tag_name_break_char}}) + - - include: script-close-tag + - - match: '{{script_content_begin}}' + escape_captures: + 1: source.coffee.embedded.html + 2: comment.block.html punctuation.definition.comment.end.html + 3: source.coffee.embedded.html + 4: comment.block.html punctuation.definition.comment.end.html + embed_scope: source.coffee.embedded.html + captures: + 1: comment.block.html punctuation.definition.comment.begin.html + pop: 1 + embed: scope:source.coffee + escape: '{{script_content_end}}' - tag-generic-attribute-meta - tag-generic-attribute-value - match: (?i)(?=livescript{{unquoted_attribute_break}}|\'livescript\'|"livescript") @@ -229,11 +392,19 @@ contexts: - match: '>' scope: punctuation.definition.tag.end.html set: - - include: script-close-tag - - embed_scope: source.livescript.embedded.html - match: '' - embed: scope:source.livescript - escape: (?i)(?=(?:-->\s*)?</script{{tag_name_break_char}}) + - - include: script-close-tag + - - match: '{{script_content_begin}}' + escape_captures: + 1: source.livescript.embedded.html + 2: comment.block.html punctuation.definition.comment.end.html + 3: source.livescript.embedded.html + 4: comment.block.html punctuation.definition.comment.end.html + embed_scope: source.livescript.embedded.html + captures: + 1: comment.block.html punctuation.definition.comment.begin.html + pop: 1 + embed: scope:source.livescript + escape: '{{script_content_end}}' - tag-generic-attribute-meta - tag-generic-attribute-value - match: (?i)(?=ts{{unquoted_attribute_break}}|\'ts\'|"ts") @@ -243,11 +414,19 @@ contexts: - match: '>' scope: punctuation.definition.tag.end.html set: - - include: script-close-tag - - embed_scope: source.ts.embedded.html - match: '' - embed: scope:source.ts - escape: (?i)(?=(?:-->\s*)?</script{{tag_name_break_char}}) + - - include: script-close-tag + - - match: '{{script_content_begin}}' + escape_captures: + 1: source.ts.embedded.html + 2: comment.block.html punctuation.definition.comment.end.html + 3: source.ts.embedded.html + 4: comment.block.html punctuation.definition.comment.end.html + embed_scope: source.ts.embedded.html + captures: + 1: comment.block.html punctuation.definition.comment.begin.html + pop: 1 + embed: scope:source.ts + escape: '{{script_content_end}}' - tag-generic-attribute-meta - tag-generic-attribute-value - match: (?=\S) @@ -303,11 +482,19 @@ contexts: - match: '>' scope: punctuation.definition.tag.end.html set: - - include: template-close-tag - - embed_scope: text.jade.embedded.html - match: '' - embed: scope:text.jade - escape: (?i)(?=(?:-->\s*)?</template{{tag_name_break_char}}) + - - include: template-close-tag + - - match: '{{template_content_begin}}' + escape_captures: + 1: text.jade.embedded.html + 2: comment.block.html punctuation.definition.comment.end.html + 3: text.jade.embedded.html + 4: comment.block.html punctuation.definition.comment.end.html + embed_scope: text.jade.embedded.html + captures: + 1: comment.block.html punctuation.definition.comment.begin.html + pop: 1 + embed: scope:text.jade + escape: '{{template_content_end}}' - tag-generic-attribute-meta - tag-generic-attribute-value - match: (?i)(?=pug{{unquoted_attribute_break}}|\'pug\'|"pug") @@ -317,11 +504,19 @@ contexts: - match: '>' scope: punctuation.definition.tag.end.html set: - - include: template-close-tag - - embed_scope: text.pug.embedded.html - match: '' - embed: scope:text.pug - escape: (?i)(?=(?:-->\s*)?</template{{tag_name_break_char}}) + - - include: template-close-tag + - - match: '{{template_content_begin}}' + escape_captures: + 1: text.pug.embedded.html + 2: comment.block.html punctuation.definition.comment.end.html + 3: text.pug.embedded.html + 4: comment.block.html punctuation.definition.comment.end.html + embed_scope: text.pug.embedded.html + captures: + 1: comment.block.html punctuation.definition.comment.begin.html + pop: 1 + embed: scope:text.pug + escape: '{{template_content_end}}' - tag-generic-attribute-meta - tag-generic-attribute-value - match: (?i)(?=slm{{unquoted_attribute_break}}|\'slm\'|"slm") @@ -331,11 +526,19 @@ contexts: - match: '>' scope: punctuation.definition.tag.end.html set: - - include: template-close-tag - - embed_scope: text.slm.embedded.html - match: '' - embed: scope:text.slm - escape: (?i)(?=(?:-->\s*)?</template{{tag_name_break_char}}) + - - include: template-close-tag + - - match: '{{template_content_begin}}' + escape_captures: + 1: text.slm.embedded.html + 2: comment.block.html punctuation.definition.comment.end.html + 3: text.slm.embedded.html + 4: comment.block.html punctuation.definition.comment.end.html + embed_scope: text.slm.embedded.html + captures: + 1: comment.block.html punctuation.definition.comment.begin.html + pop: 1 + embed: scope:text.slm + escape: '{{template_content_end}}' - tag-generic-attribute-meta - tag-generic-attribute-value - match: (?=\S) diff --git a/Vue Component.sublime-syntax.yaml-macros b/Vue Component.sublime-syntax.yaml-macros index 5e95bb5..e9193ba 100644 --- a/Vue Component.sublime-syntax.yaml-macros +++ b/Vue Component.sublime-syntax.yaml-macros @@ -8,6 +8,48 @@ scope: text.html.vue file_extensions: - vue +variables: + # Embedded script and style syntaxes may be wrapped into html comments for + # historical reasons. The following patterns match them, while maintaining + # correct boundaries of embedded source scopes. That's required to enable + # embedded syntax's comment toggling in the first and last line. + # + # see: + # - https://github.com/sublimehq/Packages/issues/2322 + # - https://github.com/sublimehq/sublime_text/issues/4701 + script_content_begin: |- + (?x: + # whitespace followed by opening html comment begin punctuation + \s*(<!--) + # or any other non-whitespace character ahead + | (?=\s*(?!<!--)\S) + # or beginning of a line + | ^ + ) + script_content_end: |- + (?x: + # optional html comment end punctuation followed by </script> tag + (?: (\s*) (-->) \s* )? (?=</(?i:script){{tag_name_break_char}}) + # or standalone html comment end punctuation in a line + | ^ (\s*) (-->) \s* $ + ) + style_content_begin: '{{script_content_begin}}' + style_content_end: |- + (?x: + # optional html comment end punctuation followed by </style> tag + (?: (\s*) (-->) \s* )? (?=</(?i:style){{tag_name_break_char}}) + # or standalone html comment end punctuation in a line + | ^ (\s*) (-->) \s* $ + ) + template_content_begin: '{{script_content_begin}}' + template_content_end: |- + (?x: + # optional html comment end punctuation followed by </template> tag + (?: (\s*) (-->) \s* )? (?=</(?i:template){{tag_name_break_char}}) + # or standalone html comment end punctuation in a line + | ^ (\s*) (-->) \s* $ + ) + contexts: main: - meta_prepend: true @@ -82,13 +124,48 @@ contexts: 0: meta.string.html string.quoted.single.html punctuation.definition.string.end.html - - include: else-pop + style-close-tag: + # for compatibility with ST builds before 4114 + - match: (</)((?i:style){{tag_name_break}}) + captures: + 1: punctuation.definition.tag.begin.html + 2: entity.name.tag.style.html + set: + - meta_scope: meta.tag.style.end.html + - include: tag-end + style-common: - meta_prepend: true - include: style-lang-attribute + style-css: + # for compatibility with ST builds before 4114 + - meta_scope: meta.tag.style.begin.html + - include: style-common + - match: '>' + scope: punctuation.definition.tag.end.html + set: + - style-close-tag + - style-css-content + + style-css-content: + # for compatibility with ST builds before 4114 + - meta_include_prototype: false + - match: '{{style_content_begin}}' + captures: + 1: comment.block.html punctuation.definition.comment.begin.html + pop: 1 # make sure to match only once + embed: scope:source.css + embed_scope: source.css.embedded.html + escape: '{{style_content_end}}' + escape_captures: + 1: source.css.embedded.html + 2: comment.block.html punctuation.definition.comment.end.html + 3: source.css.embedded.html + 4: comment.block.html punctuation.definition.comment.end.html + style-lang-attribute: - match: (?i:lang){{attribute_name_break}} scope: meta.attribute-with-value.html entity.other.attribute-name.html @@ -115,15 +192,45 @@ contexts: - tag-generic-attribute-meta - tag-generic-attribute-value + script-close-tag: + # for compatibility with ST builds before 4114 + - match: (</)((?i:script){{tag_name_break}}) + captures: + 1: punctuation.definition.tag.begin.html + 2: entity.name.tag.script.html + set: + - meta_scope: meta.tag.script.end.html + - include: tag-end + script-common: - meta_prepend: true - include: script-lang-attribute + script-javascript: + # for compatibility with ST builds before 4114 + - meta_scope: meta.tag.script.begin.html + - include: script-common + - match: '>' + scope: punctuation.definition.tag.end.html + set: + - script-close-tag + - script-javascript-content + script-javascript-content: - - match: (?=\S) + # for compatibility with ST builds before 4114 + - meta_include_prototype: false + - match: '{{script_content_begin}}' + captures: + 1: comment.block.html punctuation.definition.comment.begin.html + pop: 1 # make sure to match only once embed: scope:source.js embed_scope: source.js.embedded.html - escape: '{{script_close_lookahead}}' + escape: '{{script_content_end}}' + escape_captures: + 1: source.js.embedded.html + 2: comment.block.html punctuation.definition.comment.end.html + 3: source.js.embedded.html + 4: comment.block.html punctuation.definition.comment.end.html script-lang-attribute: - match: (?i:lang){{attribute_name_break}} diff --git a/src/macros.py b/src/macros.py index cac2f31..4674d24 100644 --- a/src/macros.py +++ b/src/macros.py @@ -20,13 +20,27 @@ def embed_language_in_tag(tag, match, embed): match='>', scope='punctuation.definition.tag.end.html', set=[ - _rule(include='%s-close-tag' % tag), - _rule( - match=r'', - embed=('scope:%s' % embed), - embed_scope=('%s.embedded.html' % embed), - escape=r'(?i)(?=(?:-->\s*)?</%s{{tag_name_break_char}})' % tag, - ) + [ + _rule(include='%s-close-tag' % tag) + ], + [ + _rule( + match=r'{{%s_content_begin}}' % tag, + captures={ + 1: 'comment.block.html punctuation.definition.comment.begin.html', + }, + pop=1, + embed=('scope:%s' % embed), + embed_scope=('%s.embedded.html' % embed), + escape='{{%s_content_end}}' % tag, + escape_captures={ + 1: ('%s.embedded.html' % embed), + 2: 'comment.block.html punctuation.definition.comment.end.html', + 3: ('%s.embedded.html' % embed), + 4: 'comment.block.html punctuation.definition.comment.end.html', + }, + ) + ] ] ), ], From b09b909c40765b6562c32690955c3da217b09f0b Mon Sep 17 00:00:00 2001 From: DeathAxe <deathaxe82@googlemail.com> Date: Wed, 8 Sep 2021 18:15:20 +0200 Subject: [PATCH 2/9] Add tests for script/style tags --- tests/syntax_test_script.vue | 200 +++++++++++++++++++++++++++++ tests/syntax_test_style.vue | 240 +++++++++++++++++++++++++++++++++++ 2 files changed, 440 insertions(+) create mode 100644 tests/syntax_test_script.vue create mode 100644 tests/syntax_test_style.vue diff --git a/tests/syntax_test_script.vue b/tests/syntax_test_script.vue new file mode 100644 index 0000000..be81601 --- /dev/null +++ b/tests/syntax_test_script.vue @@ -0,0 +1,200 @@ +// SYNTAX TEST "Packages/Vue/Vue Component.sublime-syntax" + + + <script> var i = 0; </script> +// ^^^^^^^^ meta.tag - source +// ^^^^^^^^^^^^ source.js.embedded.html - meta.tag +// ^^^^^^^^^ meta.tag - source + + <script> var i = 0; --> </script> +// ^^^^^^^^ meta.tag - source +// ^^^^^^^^^^^^ source.js.embedded.html - meta.tag +// ^^^^ - meta.tag - source +// ^^^ comment.block.html punctuation.definition.comment.end.html +// ^^^^^^^^^ meta.tag - source + + <script> <!-- var i = 0; </script> +// ^^^^^^^^ meta.tag - source +// ^^^^^ - meta.tag - source +// ^^^^^^^^^^^^ source.js.embedded.html - meta.tag +// ^^^^^^^^^ meta.tag - source +// ^^^^ punctuation.definition.comment.begin.html + + <script> <!-- var i = 0; --> </script> +// ^^^^^^^^ meta.tag - source +// ^^^^^ - meta.tag - source +// ^^^^ punctuation.definition.comment.begin.html +// ^^^^^^^^^^^^ source.js.embedded.html - meta.tag +// ^^^^ - meta.tag - source +// ^^^ comment.block.html punctuation.definition.comment.end.html +// ^^^^^^^^^ meta.tag - source + + + <script> + +// <- source.js.embedded.html + var i = 0; +// ^^^^^^^^^^^^ source.js.embedded.html - source source + </script> +// <- source.js.embedded.html - source source +// ^ source.js.embedded.html - source source +// ^^^^^^^^^ meta.tag - source + + + <script> + <!-- +//^^^^^^ - meta.tag - source +// ^^^^ comment.block.html punctuation.definition.comment.begin.html +// ^ source.js.embedded.html - source source - meta.tag - comment + var i = 0; +// ^^^^^^^^^^^^ source.js.embedded.html - source source - meta.tag + --> +//^^ source.js.embedded.html - meta.tag - comment +// ^^^^ - source - meta.tag +// ^^^ comment.block.html punctuation.definition.comment.end.html + var i = 0; +// ^^^^^^^^^^^^ - source + </script> +// ^^^^^^^^^ meta.tag - source + + + <script> <!-- +// ^^^^^^^^^^^^^ - source +// ^^^^^^^^ meta.tag +// ^ punctuation.definition.tag.begin.html +// ^^^^^^ entity.name.tag +// ^ punctuation.definition.tag.end.html +// ^ - meta.tag - comment +// ^^^^ comment.block.html punctuation.definition.comment.begin.html +// ^ source.js.embedded.html - source source + + var foo = 100; +// <- source.js.embedded.html - source source + + (a --> b); +// ^^^ source.js.embedded.html keyword.operator - comment + + --> </script> +// ^ source.js.embedded.html - source source +// ^^^^^^^^^^^^^^ - source +// ^ - meta.tag - comment +// ^^^^^^^^^ meta.tag +// ^ - meta.tag +// ^^^ comment.block.html punctuation.definition.comment.end.html +// ^^ punctuation.definition.tag.begin.html +// ^^^^^^ entity.name.tag +// ^ punctuation.definition.tag.end.html + + + <script type="text/javascript"> <!-- +// ^^^^^^^^ meta.tag - meta.tag meta.tag - meta.attribute-with-value - source +// ^^^^^^^^^^^^^^^^^^^^^^ meta.tag meta.attribute-with-value.html - meta.tag meta.tag - meta.attribute-with-value meta.attribute-with-value - source +// ^ meta.tag - meta.tag meta.tag - meta.attribute-with-value - source +// ^^^^^ - meta.tag - source +// ^^^^^^ entity.name.tag +// ^^^^ entity.other.attribute-name.html +// ^ punctuation.separator.key-value.html +// ^^^^^^^^^^^^^^^^^ string.quoted.double.html +// ^^^^ comment.block.html punctuation.definition.comment.begin.html +// ^ source.js.embedded.html + + var foo = 100; +// <- source.js.embedded.html - source source + + (a --> b); +// ^^^ source.js.embedded.html keyword.operator - comment + + --> </script> +// ^ source.js.embedded.html - source source +// ^^^^^^^^^^^^^^ - source +// ^ - meta.tag - comment +// ^^^^^^^^^ meta.tag +// ^ - meta.tag +// ^^^ comment.block.html punctuation.definition.comment.end.html +// ^^ punctuation.definition.tag.begin.html +// ^^^^^^ entity.name.tag +// ^ punctuation.definition.tag.end.html + + + <script + type +// ^^^^ meta.tag meta.attribute-with-value.html - meta.tag meta.tag - meta.attribute-with-value meta.attribute-with-value + = + application/jAvAsCrIpT> +// ^^^^^^^^^^^^^^^^^^^^^^ meta.tag meta.attribute-with-value.html - meta.tag meta.tag - meta.attribute-with-value meta.attribute-with-value + var foo = 100; +// <- source.js.embedded.html - source source +// ^^^^^^^^^^^^^^^^ source.js.embedded.html - source source + </script> +// <- source.js.embedded.html - source source +// ^ source.js.embedded.html - source source +// ^^^^^^^^^ meta.tag - source + + + <script lang="coffee"> + +// <- source.coffee.embedded.html - source source + </script> +// <- source.coffee.embedded.html - source source +//^^ source.coffee.embedded.html - source source +// ^^^^^^^^^ meta.tag - source + + <script lang="coffee"> + <!-- +// ^^^^^^^^^ - source +// ^^^^ comment.block.html punctuation.definition.comment.begin.html +// ^ source.coffee.embedded.html - source source + --> +// ^^^^^ source.coffee.embedded.html - source source +// ^^^ comment.block.html punctuation.definition.comment.end.html - source +// ^ - source - comment - meta.tag + </script> +// <- - source - comment - meta.tag +//^^ - source - comment - meta.tag +// ^^^^^^^^^ meta.tag - source + + + <script lang="livescript"> + +// <- source.livescript.embedded.html - source source + </script> +// <- source.livescript.embedded.html - source source +//^^ source.livescript.embedded.html - source source +// ^^^^^^^^^ meta.tag - source + + <script lang="livescript"> + <!-- +// ^^^^^^^^^ - source +// ^^^^ comment.block.html punctuation.definition.comment.begin.html +// ^ source.livescript.embedded.html - source source + --> +// ^^^^^ source.livescript.embedded.html - source source +// ^^^ comment.block.html punctuation.definition.comment.end.html - source +// ^ - source - comment - meta.tag + </script> +// <- - source - comment - meta.tag +//^^ - source - comment - meta.tag +// ^^^^^^^^^ meta.tag - source + + + <script lang="ts"> + +// <- source.ts.embedded.html - source source + </script> +// <- source.ts.embedded.html - source source +//^^ source.ts.embedded.html - source source +// ^^^^^^^^^ meta.tag - source + + <script lang="ts"> + <!-- +// ^^^^^^^^^ - source +// ^^^^ comment.block.html punctuation.definition.comment.begin.html +// ^ source.ts.embedded.html - source source + --> +// ^^^^^ source.ts.embedded.html - source source +// ^^^ comment.block.html punctuation.definition.comment.end.html - source +// ^ - source - comment - meta.tag + </script> +// <- - source - comment - meta.tag +//^^ - source - comment - meta.tag +// ^^^^^^^^^ meta.tag - source diff --git a/tests/syntax_test_style.vue b/tests/syntax_test_style.vue new file mode 100644 index 0000000..b7f3d8f --- /dev/null +++ b/tests/syntax_test_style.vue @@ -0,0 +1,240 @@ +// SYNTAX TEST "Packages/Vue/Vue Component.sublime-syntax" + + + <style> h1 {} </style> +// ^^^^^^^ meta.tag - source +// ^^^^^^^ source.css.embedded.html - meta.tag +// ^^^^^^^^ meta.tag - source + + <style> h1 {} --> </style> +// ^^^^^^^ meta.tag - source +// ^^^^^^^ source.css.embedded.html - meta.tag +// ^^^^ - meta.tag - source +// ^^^ comment.block.html punctuation.definition.comment.end.html +// ^^^^^^^^ meta.tag - source + + <style> <!-- h1 {} </style> +// ^^^^^^^ meta.tag - source +// ^^^^^ - meta.tag - source +// ^^^^^^^ source.css.embedded.html - meta.tag +// ^^^^^^^^ meta.tag - source +// ^^^^ punctuation.definition.comment.begin.html + + <style> <!-- h1 {} --> </style> +// ^^^^^^^ meta.tag - source +// ^^^^^ - meta.tag - source +// ^^^^ punctuation.definition.comment.begin.html +// ^^^^^^^ source.css.embedded.html - meta.tag +// ^^^^ - meta.tag - source +// ^^^ comment.block.html punctuation.definition.comment.end.html +// ^^^^^^^^ meta.tag - source + + + <style> + +// <- source.css.embedded.html + + </style> +// <- source.css.embedded.html - source source +// ^ source.css.embedded.html - source source +// ^^^^^^^^ meta.tag - source + + + <style> + <!-- +//^^^^^^ - meta.tag - source +// ^^^^ comment.block.html punctuation.definition.comment.begin.html +// ^ source.css.embedded.html - source source - meta.tag - comment + h1 {} +// ^^^^^^^ source.css.embedded.html - source source - meta.tag + --> +//^^ source.css.embedded.html - meta.tag - comment +// ^^^^ - source - meta.tag +// ^^^ comment.block.html punctuation.definition.comment.end.html + var i = 0; +// ^^^^^^^^^^^^ - source + </style> +// ^^^^^^^^ meta.tag - source + + + <style> <!-- +// ^^^^^^^^^^^^ - source +// ^^^^^^^ meta.tag +// ^ punctuation.definition.tag.begin.html +// ^^^^^ entity.name.tag +// ^ punctuation.definition.tag.end.html +// ^ - meta.tag - comment +// ^^^^ comment.block.html punctuation.definition.comment.begin.html +// ^ source.css.embedded.html - source source + + h1 {} +// <- source.css.embedded.html - source source + + --> </style> +// ^ source.css.embedded.html - source source +// ^^^^^^^^^^^^^ - source +// ^ - meta.tag - comment +// ^^^^^^^^ meta.tag +// ^ - meta.tag +// ^^^ comment.block.html punctuation.definition.comment.end.html +// ^^ punctuation.definition.tag.begin.html +// ^^^^^ entity.name.tag +// ^ punctuation.definition.tag.end.html + + + <style type="text/css"> <!-- +// ^^^^^^^ meta.tag - meta.tag meta.tag - meta.attribute-with-value - source +// ^^^^^^^^^^^^^^^ meta.tag meta.attribute-with-value.html - meta.tag meta.tag - meta.attribute-with-value meta.attribute-with-value - source +// ^ meta.tag - meta.tag meta.tag - meta.attribute-with-value - source +// ^^^^^ - meta.tag - source +// ^^^^^ entity.name.tag +// ^^^^ entity.other.attribute-name.html +// ^ punctuation.separator.key-value.html +// ^^^^^^^^^^ string.quoted.double.html +// ^^^^ comment.block.html punctuation.definition.comment.begin.html +// ^ source.css.embedded.html + + h1 {} +// <- source.css.embedded.html - source source + + --> </style> +// ^ source.css.embedded.html - source source +// ^^^^^^^^^^^^^ - source +// ^ - meta.tag - comment +// ^^^^^^^^ meta.tag +// ^ - meta.tag +// ^^^ comment.block.html punctuation.definition.comment.end.html +// ^^ punctuation.definition.tag.begin.html +// ^^^^^ entity.name.tag +// ^ punctuation.definition.tag.end.html + + + <style + type +// ^^^^ meta.tag meta.attribute-with-value.html - meta.tag meta.tag - meta.attribute-with-value meta.attribute-with-value + = + tExT/cSs> +// ^^^^^^^^ meta.tag meta.attribute-with-value.html - meta.tag meta.tag - meta.attribute-with-value meta.attribute-with-value + + h1 {} +// <- source.css.embedded.html - source source + + </style> +// <- source.css.embedded.html - source source +// ^ source.css.embedded.html - source source +// ^^^^^^^^ meta.tag - source + + + <style lang="less"> + +// <- source.less.embedded.html - source source + </style> +// <- source.less.embedded.html - source source +//^^ source.less.embedded.html - source source +// ^^^^^^^^ meta.tag - source + + <style lang="less"> + <!-- +// ^^^^^^^^^ - source +// ^^^^ comment.block.html punctuation.definition.comment.begin.html +// ^ source.less.embedded.html - source source + --> +// ^^^^^ source.less.embedded.html - source source +// ^^^ comment.block.html punctuation.definition.comment.end.html - source +// ^ - source - comment - meta.tag + </style> +// <- - source - comment - meta.tag +//^^ - source - comment - meta.tag +// ^^^^^^^^ meta.tag - source + + + <style lang="postcss"> + +// <- source.postcss.embedded.html - source source + </style> +// <- source.postcss.embedded.html - source source +//^^ source.postcss.embedded.html - source source +// ^^^^^^^^ meta.tag - source + + <style lang="postcss"> + <!-- +// ^^^^^^^^^ - source +// ^^^^ comment.block.html punctuation.definition.comment.begin.html +// ^ source.postcss.embedded.html - source source + --> +// ^^^^^ source.postcss.embedded.html - source source +// ^^^ comment.block.html punctuation.definition.comment.end.html - source +// ^ - source - comment - meta.tag + </style> +// <- - source - comment - meta.tag +//^^ - source - comment - meta.tag +// ^^^^^^^^ meta.tag - source + + + <style lang="postcss?parser=sugarss"> + +// <- source.sss.embedded.html - source source + </style> +// <- source.sss.embedded.html - source source +//^^ source.sss.embedded.html - source source +// ^^^^^^^^ meta.tag - source + + <style lang="postcss?parser=sugarss"> + <!-- +// ^^^^^^^^^ - source +// ^^^^ comment.block.html punctuation.definition.comment.begin.html +// ^ source.sss.embedded.html - source source + --> +// ^^^^^ source.sss.embedded.html - source source +// ^^^ comment.block.html punctuation.definition.comment.end.html - source +// ^ - source - comment - meta.tag + </style> +// <- - source - comment - meta.tag +//^^ - source - comment - meta.tag +// ^^^^^^^^ meta.tag - source + + + <style lang="sass"> + +// <- source.sass.embedded.html - source source + </style> +// <- source.sass.embedded.html - source source +//^^ source.sass.embedded.html - source source +// ^^^^^^^^ meta.tag - source + + <style lang="sass"> + <!-- +// ^^^^^^^^^ - source +// ^^^^ comment.block.html punctuation.definition.comment.begin.html +// ^ source.sass.embedded.html - source source + --> +// ^^^^^ source.sass.embedded.html - source source +// ^^^ comment.block.html punctuation.definition.comment.end.html - source +// ^ - source - comment - meta.tag + </style> +// <- - source - comment - meta.tag +//^^ - source - comment - meta.tag +// ^^^^^^^^ meta.tag - source + + + <style lang="scss"> + +// <- source.scss.embedded.html - source source + </style> +// <- source.scss.embedded.html - source source +//^^ source.scss.embedded.html - source source +// ^^^^^^^^ meta.tag - source + + <style lang="scss"> + <!-- +// ^^^^^^^^^ - source +// ^^^^ comment.block.html punctuation.definition.comment.begin.html +// ^ source.scss.embedded.html - source source + --> +// ^^^^^ source.scss.embedded.html - source source +// ^^^ comment.block.html punctuation.definition.comment.end.html - source +// ^ - source - comment - meta.tag + </style> +// <- - source - comment - meta.tag +//^^ - source - comment - meta.tag +// ^^^^^^^^ meta.tag - source From 5072d8ee4d0950596ae030d1a37a5f6ec32a0402 Mon Sep 17 00:00:00 2001 From: DeathAxe <deathaxe82@googlemail.com> Date: Wed, 8 Sep 2021 18:51:01 +0200 Subject: [PATCH 3/9] Add Github Actions for automated syntax tests --- .github/workflows/ci-syntax-tests.yml | 38 +++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 .github/workflows/ci-syntax-tests.yml diff --git a/.github/workflows/ci-syntax-tests.yml b/.github/workflows/ci-syntax-tests.yml new file mode 100644 index 0000000..bf8afc1 --- /dev/null +++ b/.github/workflows/ci-syntax-tests.yml @@ -0,0 +1,38 @@ +name: CI Syntax Tests + +on: + push: + branches: + - 'master' + paths: + - '.github/workflows/ci-syntax-tests.yml' + - '**.sublime-syntax' + - '**/syntax_test_*' + - '**.tmPreferences' + pull_request: + branches: + - '**' + paths: + - '.github/workflows/ci-syntax-tests.yml' + - '**.sublime-syntax' + - '**/syntax_test_*' + - '**.tmPreferences' + workflow_dispatch: + +jobs: + syntax_tests: + name: Sublime Text ${{ matrix.build }} + strategy: + matrix: + include: + - build: 4107 + packages: a147e3eb6210de480d0d9a6bd6bf54931a8ba7e9 + - build: latest + packages: master + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: SublimeText/syntax-test-action@v2 + with: + build: ${{ matrix.build }} + default_packages: ${{ matrix.packages }} From a1884fad8bdee8cbb0cd7b8b01182ae97b267c28 Mon Sep 17 00:00:00 2001 From: DeathAxe <deathaxe82@googlemail.com> Date: Wed, 8 Sep 2021 19:41:59 +0200 Subject: [PATCH 4/9] Fix meta.tag and meta.attribute-with-value scope boundaries This commit adds another fix introduced with ST4114, which addresses the mentioned meta scopes not being applied correctly. They were missing at attribute assignment operators and closing `>` sign. --- Vue Component.sublime-syntax | 78 ++++++++++++------------ Vue Component.sublime-syntax.yaml-macros | 6 +- src/macros.py | 2 +- tests/syntax_test_script.vue | 6 ++ tests/syntax_test_style.vue | 7 +++ 5 files changed, 56 insertions(+), 43 deletions(-) diff --git a/Vue Component.sublime-syntax b/Vue Component.sublime-syntax index 89dc5e7..6c464ca 100644 --- a/Vue Component.sublime-syntax +++ b/Vue Component.sublime-syntax @@ -165,7 +165,7 @@ contexts: - match: = scope: punctuation.separator.key-value.html set: - - meta_content_scope: meta.tag.style.begin.html meta.attribute-with-value.html + - meta_scope: meta.tag.style.begin.html meta.attribute-with-value.html - include: style-lang-decider - match: (?=\S) set: style-css @@ -173,19 +173,19 @@ contexts: style-lang-decider: - match: (?i)(?=sass{{unquoted_attribute_break}}|\'sass\'|"sass") set: - - - meta_content_scope: meta.tag.style.begin.html + - - meta_scope: meta.tag.style.begin.html - include: style-common - match: '>' scope: punctuation.definition.tag.end.html set: - - include: style-close-tag - - - match: '{{style_content_begin}}' + - - embed_scope: source.sass.embedded.html escape_captures: 1: source.sass.embedded.html 2: comment.block.html punctuation.definition.comment.end.html 3: source.sass.embedded.html 4: comment.block.html punctuation.definition.comment.end.html - embed_scope: source.sass.embedded.html + match: '{{style_content_begin}}' captures: 1: comment.block.html punctuation.definition.comment.begin.html pop: 1 @@ -195,19 +195,19 @@ contexts: - tag-generic-attribute-value - match: (?i)(?=scss{{unquoted_attribute_break}}|\'scss\'|"scss") set: - - - meta_content_scope: meta.tag.style.begin.html + - - meta_scope: meta.tag.style.begin.html - include: style-common - match: '>' scope: punctuation.definition.tag.end.html set: - - include: style-close-tag - - - match: '{{style_content_begin}}' + - - embed_scope: source.scss.embedded.html escape_captures: 1: source.scss.embedded.html 2: comment.block.html punctuation.definition.comment.end.html 3: source.scss.embedded.html 4: comment.block.html punctuation.definition.comment.end.html - embed_scope: source.scss.embedded.html + match: '{{style_content_begin}}' captures: 1: comment.block.html punctuation.definition.comment.begin.html pop: 1 @@ -217,19 +217,19 @@ contexts: - tag-generic-attribute-value - match: (?i)(?=stylus{{unquoted_attribute_break}}|\'stylus\'|"stylus") set: - - - meta_content_scope: meta.tag.style.begin.html + - - meta_scope: meta.tag.style.begin.html - include: style-common - match: '>' scope: punctuation.definition.tag.end.html set: - - include: style-close-tag - - - match: '{{style_content_begin}}' + - - embed_scope: source.stylus.embedded.html escape_captures: 1: source.stylus.embedded.html 2: comment.block.html punctuation.definition.comment.end.html 3: source.stylus.embedded.html 4: comment.block.html punctuation.definition.comment.end.html - embed_scope: source.stylus.embedded.html + match: '{{style_content_begin}}' captures: 1: comment.block.html punctuation.definition.comment.begin.html pop: 1 @@ -239,19 +239,19 @@ contexts: - tag-generic-attribute-value - match: (?i)(?=postcss\?parser=sugarss{{unquoted_attribute_break}}|\'postcss\?parser=sugarss\'|"postcss\?parser=sugarss") set: - - - meta_content_scope: meta.tag.style.begin.html + - - meta_scope: meta.tag.style.begin.html - include: style-common - match: '>' scope: punctuation.definition.tag.end.html set: - - include: style-close-tag - - - match: '{{style_content_begin}}' + - - embed_scope: source.sss.embedded.html escape_captures: 1: source.sss.embedded.html 2: comment.block.html punctuation.definition.comment.end.html 3: source.sss.embedded.html 4: comment.block.html punctuation.definition.comment.end.html - embed_scope: source.sss.embedded.html + match: '{{style_content_begin}}' captures: 1: comment.block.html punctuation.definition.comment.begin.html pop: 1 @@ -261,19 +261,19 @@ contexts: - tag-generic-attribute-value - match: (?i)(?=postcss{{unquoted_attribute_break}}|\'postcss\'|"postcss") set: - - - meta_content_scope: meta.tag.style.begin.html + - - meta_scope: meta.tag.style.begin.html - include: style-common - match: '>' scope: punctuation.definition.tag.end.html set: - - include: style-close-tag - - - match: '{{style_content_begin}}' + - - embed_scope: source.postcss.embedded.html escape_captures: 1: source.postcss.embedded.html 2: comment.block.html punctuation.definition.comment.end.html 3: source.postcss.embedded.html 4: comment.block.html punctuation.definition.comment.end.html - embed_scope: source.postcss.embedded.html + match: '{{style_content_begin}}' captures: 1: comment.block.html punctuation.definition.comment.begin.html pop: 1 @@ -283,19 +283,19 @@ contexts: - tag-generic-attribute-value - match: (?i)(?=less{{unquoted_attribute_break}}|\'less\'|"less") set: - - - meta_content_scope: meta.tag.style.begin.html + - - meta_scope: meta.tag.style.begin.html - include: style-common - match: '>' scope: punctuation.definition.tag.end.html set: - - include: style-close-tag - - - match: '{{style_content_begin}}' + - - embed_scope: source.less.embedded.html escape_captures: 1: source.less.embedded.html 2: comment.block.html punctuation.definition.comment.end.html 3: source.less.embedded.html 4: comment.block.html punctuation.definition.comment.end.html - embed_scope: source.less.embedded.html + match: '{{style_content_begin}}' captures: 1: comment.block.html punctuation.definition.comment.begin.html pop: 1 @@ -357,7 +357,7 @@ contexts: - match: = scope: punctuation.separator.key-value.html set: - - meta_content_scope: meta.tag.script.begin.html meta.attribute-with-value.html + - meta_scope: meta.tag.script.begin.html meta.attribute-with-value.html - include: script-lang-decider - match: (?=\S) set: script-javascript @@ -365,19 +365,19 @@ contexts: script-lang-decider: - match: (?i)(?=coffee{{unquoted_attribute_break}}|\'coffee\'|"coffee") set: - - - meta_content_scope: meta.tag.script.begin.html + - - meta_scope: meta.tag.script.begin.html - include: script-common - match: '>' scope: punctuation.definition.tag.end.html set: - - include: script-close-tag - - - match: '{{script_content_begin}}' + - - embed_scope: source.coffee.embedded.html escape_captures: 1: source.coffee.embedded.html 2: comment.block.html punctuation.definition.comment.end.html 3: source.coffee.embedded.html 4: comment.block.html punctuation.definition.comment.end.html - embed_scope: source.coffee.embedded.html + match: '{{script_content_begin}}' captures: 1: comment.block.html punctuation.definition.comment.begin.html pop: 1 @@ -387,19 +387,19 @@ contexts: - tag-generic-attribute-value - match: (?i)(?=livescript{{unquoted_attribute_break}}|\'livescript\'|"livescript") set: - - - meta_content_scope: meta.tag.script.begin.html + - - meta_scope: meta.tag.script.begin.html - include: script-common - match: '>' scope: punctuation.definition.tag.end.html set: - - include: script-close-tag - - - match: '{{script_content_begin}}' + - - embed_scope: source.livescript.embedded.html escape_captures: 1: source.livescript.embedded.html 2: comment.block.html punctuation.definition.comment.end.html 3: source.livescript.embedded.html 4: comment.block.html punctuation.definition.comment.end.html - embed_scope: source.livescript.embedded.html + match: '{{script_content_begin}}' captures: 1: comment.block.html punctuation.definition.comment.begin.html pop: 1 @@ -409,19 +409,19 @@ contexts: - tag-generic-attribute-value - match: (?i)(?=ts{{unquoted_attribute_break}}|\'ts\'|"ts") set: - - - meta_content_scope: meta.tag.script.begin.html + - - meta_scope: meta.tag.script.begin.html - include: script-common - match: '>' scope: punctuation.definition.tag.end.html set: - - include: script-close-tag - - - match: '{{script_content_begin}}' + - - embed_scope: source.ts.embedded.html escape_captures: 1: source.ts.embedded.html 2: comment.block.html punctuation.definition.comment.end.html 3: source.ts.embedded.html 4: comment.block.html punctuation.definition.comment.end.html - embed_scope: source.ts.embedded.html + match: '{{script_content_begin}}' captures: 1: comment.block.html punctuation.definition.comment.begin.html pop: 1 @@ -469,7 +469,7 @@ contexts: - match: = scope: punctuation.separator.key-value.html set: - - meta_content_scope: meta.tag.template.begin.html meta.attribute-with-value.html + - meta_scope: meta.tag.template.begin.html meta.attribute-with-value.html - include: template-lang-decider - match: (?=\S) set: template-mustache @@ -477,19 +477,19 @@ contexts: template-lang-decider: - match: (?i)(?=jade{{unquoted_attribute_break}}|\'jade\'|"jade") set: - - - meta_content_scope: meta.tag.template.begin.html + - - meta_scope: meta.tag.template.begin.html - include: template-common - match: '>' scope: punctuation.definition.tag.end.html set: - - include: template-close-tag - - - match: '{{template_content_begin}}' + - - embed_scope: text.jade.embedded.html escape_captures: 1: text.jade.embedded.html 2: comment.block.html punctuation.definition.comment.end.html 3: text.jade.embedded.html 4: comment.block.html punctuation.definition.comment.end.html - embed_scope: text.jade.embedded.html + match: '{{template_content_begin}}' captures: 1: comment.block.html punctuation.definition.comment.begin.html pop: 1 @@ -499,19 +499,19 @@ contexts: - tag-generic-attribute-value - match: (?i)(?=pug{{unquoted_attribute_break}}|\'pug\'|"pug") set: - - - meta_content_scope: meta.tag.template.begin.html + - - meta_scope: meta.tag.template.begin.html - include: template-common - match: '>' scope: punctuation.definition.tag.end.html set: - - include: template-close-tag - - - match: '{{template_content_begin}}' + - - embed_scope: text.pug.embedded.html escape_captures: 1: text.pug.embedded.html 2: comment.block.html punctuation.definition.comment.end.html 3: text.pug.embedded.html 4: comment.block.html punctuation.definition.comment.end.html - embed_scope: text.pug.embedded.html + match: '{{template_content_begin}}' captures: 1: comment.block.html punctuation.definition.comment.begin.html pop: 1 @@ -521,19 +521,19 @@ contexts: - tag-generic-attribute-value - match: (?i)(?=slm{{unquoted_attribute_break}}|\'slm\'|"slm") set: - - - meta_content_scope: meta.tag.template.begin.html + - - meta_scope: meta.tag.template.begin.html - include: template-common - match: '>' scope: punctuation.definition.tag.end.html set: - - include: template-close-tag - - - match: '{{template_content_begin}}' + - - embed_scope: text.slm.embedded.html escape_captures: 1: text.slm.embedded.html 2: comment.block.html punctuation.definition.comment.end.html 3: text.slm.embedded.html 4: comment.block.html punctuation.definition.comment.end.html - embed_scope: text.slm.embedded.html + match: '{{template_content_begin}}' captures: 1: comment.block.html punctuation.definition.comment.begin.html pop: 1 diff --git a/Vue Component.sublime-syntax.yaml-macros b/Vue Component.sublime-syntax.yaml-macros index e9193ba..3eaa0fe 100644 --- a/Vue Component.sublime-syntax.yaml-macros +++ b/Vue Component.sublime-syntax.yaml-macros @@ -174,7 +174,7 @@ contexts: - match: = scope: punctuation.separator.key-value.html set: - - meta_content_scope: meta.tag.style.begin.html meta.attribute-with-value.html + - meta_scope: meta.tag.style.begin.html meta.attribute-with-value.html - include: style-lang-decider - match: (?=\S) set: style-css @@ -240,7 +240,7 @@ contexts: - match: = scope: punctuation.separator.key-value.html set: - - meta_content_scope: meta.tag.script.begin.html meta.attribute-with-value.html + - meta_scope: meta.tag.script.begin.html meta.attribute-with-value.html - include: script-lang-decider - match: (?=\S) set: script-javascript @@ -289,7 +289,7 @@ contexts: - match: = scope: punctuation.separator.key-value.html set: - - meta_content_scope: meta.tag.template.begin.html meta.attribute-with-value.html + - meta_scope: meta.tag.template.begin.html meta.attribute-with-value.html - include: template-lang-decider - match: (?=\S) set: template-mustache diff --git a/src/macros.py b/src/macros.py index 4674d24..3f727a6 100644 --- a/src/macros.py +++ b/src/macros.py @@ -14,7 +14,7 @@ def embed_language_in_tag(tag, match, embed): match=r'(?i)(?={0}{{{{unquoted_attribute_break}}}}|\'{0}\'|"{0}")'.format(match), set=[ [ - _rule(meta_content_scope='meta.tag.%s.begin.html' % tag), + _rule(meta_scope='meta.tag.%s.begin.html' % tag), _rule(include='%s-common' % tag), _rule( match='>', diff --git a/tests/syntax_test_script.vue b/tests/syntax_test_script.vue index be81601..ef50d4b 100644 --- a/tests/syntax_test_script.vue +++ b/tests/syntax_test_script.vue @@ -131,6 +131,12 @@ // ^^^^^^^^^ meta.tag - source + <script lang="coffee"> </script> +// ^^^^^^^^^^^^^^^^^^^^^^ meta.tag - meta.tag meta.tag - source +// ^^^^^^^^^^^^^ meta.attribute-with-value.html - meta.attribute-with-value meta.attribute-with-value +// ^^ source.coffee.embedded.html - meta.tag +// ^^^^^^^^^ meta.tag - source + <script lang="coffee"> // <- source.coffee.embedded.html - source source diff --git a/tests/syntax_test_style.vue b/tests/syntax_test_style.vue index b7f3d8f..e8bd37a 100644 --- a/tests/syntax_test_style.vue +++ b/tests/syntax_test_style.vue @@ -125,6 +125,13 @@ // ^^^^^^^^ meta.tag - source + <style lang="less"> </style> +// ^^^^^^^^^^^^^^^^^^^ meta.tag - meta.tag meta.tag - source +// ^^^^^^^^^^^ meta.attribute-with-value.html - meta.attribute-with-value meta.attribute-with-value +// ^^ source.less.embedded.html - meta.tag +// ^^^^^^^^ meta.tag - source + + <style lang="less"> // <- source.less.embedded.html - source source From 91b9e503b2ae903c0c71221093fb6ae3eb37842d Mon Sep 17 00:00:00 2001 From: DeathAxe <deathaxe82@googlemail.com> Date: Wed, 8 Sep 2021 19:44:30 +0200 Subject: [PATCH 5/9] Reorganize lang-attribute contexts This commit applies a structural change from HTML.sublime-syntax, which turns various "lang" attribute related anonymous contexts into named contexts as those help debugging syntax errors when using ST's new scope name popup. They also help inheriting syntaxes more fine grained. --- Vue Component.sublime-syntax | 69 ++++++++++++++---------- Vue Component.sublime-syntax.yaml-macros | 69 ++++++++++++++---------- 2 files changed, 84 insertions(+), 54 deletions(-) diff --git a/Vue Component.sublime-syntax b/Vue Component.sublime-syntax index 6c464ca..4ee8e79 100644 --- a/Vue Component.sublime-syntax +++ b/Vue Component.sublime-syntax @@ -160,15 +160,20 @@ contexts: style-lang-attribute: - match: (?i:lang){{attribute_name_break}} scope: meta.attribute-with-value.html entity.other.attribute-name.html - set: - - meta_content_scope: meta.tag.style.begin.html meta.attribute-with-value.html - - match: = - scope: punctuation.separator.key-value.html - set: - - meta_scope: meta.tag.style.begin.html meta.attribute-with-value.html - - include: style-lang-decider - - match: (?=\S) - set: style-css + set: style-lang-attribute-assignment + + style-lang-attribute-assignment: + - meta_content_scope: meta.tag.style.begin.html meta.attribute-with-value.html + - match: = + scope: punctuation.separator.key-value.html + set: style-lang-attribute-value + - match: (?=\S) + set: style-css + + style-lang-attribute-value: + - meta_include_prototype: false + - meta_scope: meta.tag.style.begin.html meta.attribute-with-value.html + - include: style-lang-decider style-lang-decider: - match: (?i)(?=sass{{unquoted_attribute_break}}|\'sass\'|"sass") @@ -352,15 +357,20 @@ contexts: script-lang-attribute: - match: (?i:lang){{attribute_name_break}} scope: meta.attribute-with-value.html entity.other.attribute-name.html - set: - - meta_content_scope: meta.tag.script.begin.html meta.attribute-with-value.html - - match: = - scope: punctuation.separator.key-value.html - set: - - meta_scope: meta.tag.script.begin.html meta.attribute-with-value.html - - include: script-lang-decider - - match: (?=\S) - set: script-javascript + set: script-lang-attribute-assignment + + script-lang-attribute-assignment: + - meta_content_scope: meta.tag.script.begin.html meta.attribute-with-value.html + - match: = + scope: punctuation.separator.key-value.html + set: script-lang-attribute-value + - match: (?=\S) + set: script-javascript + + script-lang-attribute-value: + - meta_include_prototype: false + - meta_scope: meta.tag.script.begin.html meta.attribute-with-value.html + - include: script-lang-decider script-lang-decider: - match: (?i)(?=coffee{{unquoted_attribute_break}}|\'coffee\'|"coffee") @@ -464,15 +474,20 @@ contexts: template-lang-attribute: - match: (?i:lang){{attribute_name_break}} scope: meta.attribute-with-value.html entity.other.attribute-name.html - set: - - meta_content_scope: meta.tag.template.begin.html meta.attribute-with-value.html - - match: = - scope: punctuation.separator.key-value.html - set: - - meta_scope: meta.tag.template.begin.html meta.attribute-with-value.html - - include: template-lang-decider - - match: (?=\S) - set: template-mustache + set: template-lang-attribute-assignment + + template-lang-attribute-assignment: + - meta_content_scope: meta.tag.template.begin.html meta.attribute-with-value.html + - match: = + scope: punctuation.separator.key-value.html + set: template-lang-attribute-value + - match: (?=\S) + set: template-mustache + + template-lang-attribute-value: + - meta_include_prototype: false + - meta_scope: meta.tag.template.begin.html meta.attribute-with-value.html + - include: template-lang-decider template-lang-decider: - match: (?i)(?=jade{{unquoted_attribute_break}}|\'jade\'|"jade") diff --git a/Vue Component.sublime-syntax.yaml-macros b/Vue Component.sublime-syntax.yaml-macros index 3eaa0fe..1f56464 100644 --- a/Vue Component.sublime-syntax.yaml-macros +++ b/Vue Component.sublime-syntax.yaml-macros @@ -169,15 +169,20 @@ contexts: style-lang-attribute: - match: (?i:lang){{attribute_name_break}} scope: meta.attribute-with-value.html entity.other.attribute-name.html - set: - - meta_content_scope: meta.tag.style.begin.html meta.attribute-with-value.html - - match: = - scope: punctuation.separator.key-value.html - set: - - meta_scope: meta.tag.style.begin.html meta.attribute-with-value.html - - include: style-lang-decider - - match: (?=\S) - set: style-css + set: style-lang-attribute-assignment + + style-lang-attribute-assignment: + - meta_content_scope: meta.tag.style.begin.html meta.attribute-with-value.html + - match: = + scope: punctuation.separator.key-value.html + set: style-lang-attribute-value + - match: (?=\S) + set: style-css + + style-lang-attribute-value: + - meta_include_prototype: false + - meta_scope: meta.tag.style.begin.html meta.attribute-with-value.html + - include: style-lang-decider style-lang-decider: - !style_language [ sass, source.sass ] @@ -235,15 +240,20 @@ contexts: script-lang-attribute: - match: (?i:lang){{attribute_name_break}} scope: meta.attribute-with-value.html entity.other.attribute-name.html - set: - - meta_content_scope: meta.tag.script.begin.html meta.attribute-with-value.html - - match: = - scope: punctuation.separator.key-value.html - set: - - meta_scope: meta.tag.script.begin.html meta.attribute-with-value.html - - include: script-lang-decider - - match: (?=\S) - set: script-javascript + set: script-lang-attribute-assignment + + script-lang-attribute-assignment: + - meta_content_scope: meta.tag.script.begin.html meta.attribute-with-value.html + - match: = + scope: punctuation.separator.key-value.html + set: script-lang-attribute-value + - match: (?=\S) + set: script-javascript + + script-lang-attribute-value: + - meta_include_prototype: false + - meta_scope: meta.tag.script.begin.html meta.attribute-with-value.html + - include: script-lang-decider script-lang-decider: - !script_language [ coffee, source.coffee ] @@ -284,15 +294,20 @@ contexts: template-lang-attribute: - match: (?i:lang){{attribute_name_break}} scope: meta.attribute-with-value.html entity.other.attribute-name.html - set: - - meta_content_scope: meta.tag.template.begin.html meta.attribute-with-value.html - - match: = - scope: punctuation.separator.key-value.html - set: - - meta_scope: meta.tag.template.begin.html meta.attribute-with-value.html - - include: template-lang-decider - - match: (?=\S) - set: template-mustache + set: template-lang-attribute-assignment + + template-lang-attribute-assignment: + - meta_content_scope: meta.tag.template.begin.html meta.attribute-with-value.html + - match: = + scope: punctuation.separator.key-value.html + set: template-lang-attribute-value + - match: (?=\S) + set: template-mustache + + template-lang-attribute-value: + - meta_include_prototype: false + - meta_scope: meta.tag.template.begin.html meta.attribute-with-value.html + - include: template-lang-decider template-lang-decider: - !template_language [ jade, text.jade ] From 616140b43e0d4bc0c8aff25e2d282c309adee1a0 Mon Sep 17 00:00:00 2001 From: DeathAxe <deathaxe82@googlemail.com> Date: Wed, 8 Sep 2021 20:13:58 +0200 Subject: [PATCH 6/9] Relax test cases to avoid failure with ST <4114 The relaxed test cases would fail on <ST4114 as the related fix to avoid duplicated meta scopes was introduced recently. It's basically the same fix as for `lang-attribute` in previous commit, but I don't think we should try to fix all kinds of issues of older HTML.sublime-syntax. This commit ensures to pass CI syntax tests. --- tests/syntax_test_script.vue | 10 +++++----- tests/syntax_test_style.vue | 12 ++++++------ 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/tests/syntax_test_script.vue b/tests/syntax_test_script.vue index ef50d4b..82e0f89 100644 --- a/tests/syntax_test_script.vue +++ b/tests/syntax_test_script.vue @@ -87,9 +87,9 @@ <script type="text/javascript"> <!-- -// ^^^^^^^^ meta.tag - meta.tag meta.tag - meta.attribute-with-value - source -// ^^^^^^^^^^^^^^^^^^^^^^ meta.tag meta.attribute-with-value.html - meta.tag meta.tag - meta.attribute-with-value meta.attribute-with-value - source -// ^ meta.tag - meta.tag meta.tag - meta.attribute-with-value - source +// ^^^^^^^^ meta.tag - meta.attribute-with-value - source +// ^^^^^^^^^^^^^^^^^^^^^^ meta.tag meta.attribute-with-value.html - meta.attribute-with-value meta.attribute-with-value - source +// ^ meta.tag - meta.attribute-with-value - source // ^^^^^ - meta.tag - source // ^^^^^^ entity.name.tag // ^^^^ entity.other.attribute-name.html @@ -118,10 +118,10 @@ <script type -// ^^^^ meta.tag meta.attribute-with-value.html - meta.tag meta.tag - meta.attribute-with-value meta.attribute-with-value +// ^^^^ meta.tag meta.attribute-with-value.html - meta.attribute-with-value meta.attribute-with-value = application/jAvAsCrIpT> -// ^^^^^^^^^^^^^^^^^^^^^^ meta.tag meta.attribute-with-value.html - meta.tag meta.tag - meta.attribute-with-value meta.attribute-with-value +// ^^^^^^^^^^^^^^^^^^^^^^ meta.tag meta.attribute-with-value.html - meta.attribute-with-value meta.attribute-with-value var foo = 100; // <- source.js.embedded.html - source source // ^^^^^^^^^^^^^^^^ source.js.embedded.html - source source diff --git a/tests/syntax_test_style.vue b/tests/syntax_test_style.vue index e8bd37a..900aa11 100644 --- a/tests/syntax_test_style.vue +++ b/tests/syntax_test_style.vue @@ -83,9 +83,9 @@ <style type="text/css"> <!-- -// ^^^^^^^ meta.tag - meta.tag meta.tag - meta.attribute-with-value - source -// ^^^^^^^^^^^^^^^ meta.tag meta.attribute-with-value.html - meta.tag meta.tag - meta.attribute-with-value meta.attribute-with-value - source -// ^ meta.tag - meta.tag meta.tag - meta.attribute-with-value - source +// ^^^^^^^ meta.tag - meta.attribute-with-value - source +// ^^^^^^^^^^^^^^^ meta.tag meta.attribute-with-value.html - meta.attribute-with-value meta.attribute-with-value - source +// ^ meta.tag - meta.attribute-with-value - source // ^^^^^ - meta.tag - source // ^^^^^ entity.name.tag // ^^^^ entity.other.attribute-name.html @@ -111,10 +111,10 @@ <style type -// ^^^^ meta.tag meta.attribute-with-value.html - meta.tag meta.tag - meta.attribute-with-value meta.attribute-with-value +// ^^^^ meta.tag meta.attribute-with-value.html - meta.attribute-with-value meta.attribute-with-value = tExT/cSs> -// ^^^^^^^^ meta.tag meta.attribute-with-value.html - meta.tag meta.tag - meta.attribute-with-value meta.attribute-with-value +// ^^^^^^^^ meta.tag meta.attribute-with-value.html - meta.attribute-with-value meta.attribute-with-value h1 {} // <- source.css.embedded.html - source source @@ -126,7 +126,7 @@ <style lang="less"> </style> -// ^^^^^^^^^^^^^^^^^^^ meta.tag - meta.tag meta.tag - source +// ^^^^^^^^^^^^^^^^^^^ meta.tag - source // ^^^^^^^^^^^ meta.attribute-with-value.html - meta.attribute-with-value meta.attribute-with-value // ^^ source.less.embedded.html - meta.tag // ^^^^^^^^ meta.tag - source From 3f59c91e7d5518c36700f962b44621c5d8527201 Mon Sep 17 00:00:00 2001 From: DeathAxe <deathaxe82@googlemail.com> Date: Wed, 8 Sep 2021 21:32:18 +0200 Subject: [PATCH 7/9] Update CI target branch for tests on push --- .github/workflows/ci-syntax-tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci-syntax-tests.yml b/.github/workflows/ci-syntax-tests.yml index bf8afc1..f05110e 100644 --- a/.github/workflows/ci-syntax-tests.yml +++ b/.github/workflows/ci-syntax-tests.yml @@ -3,7 +3,7 @@ name: CI Syntax Tests on: push: branches: - - 'master' + - 'st4' paths: - '.github/workflows/ci-syntax-tests.yml' - '**.sublime-syntax' From cd2fe311de57a73ba8cc25eb2bc3793c7cb47aec Mon Sep 17 00:00:00 2001 From: DeathAxe <deathaxe82@googlemail.com> Date: Wed, 8 Sep 2021 21:56:33 +0200 Subject: [PATCH 8/9] Fix package name in syntax tests --- tests/syntax_test_script.vue | 2 +- tests/syntax_test_style.vue | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/syntax_test_script.vue b/tests/syntax_test_script.vue index 82e0f89..05c8ac0 100644 --- a/tests/syntax_test_script.vue +++ b/tests/syntax_test_script.vue @@ -1,4 +1,4 @@ -// SYNTAX TEST "Packages/Vue/Vue Component.sublime-syntax" +// SYNTAX TEST "Vue Component.sublime-syntax" <script> var i = 0; </script> diff --git a/tests/syntax_test_style.vue b/tests/syntax_test_style.vue index 900aa11..8b88d44 100644 --- a/tests/syntax_test_style.vue +++ b/tests/syntax_test_style.vue @@ -1,4 +1,4 @@ -// SYNTAX TEST "Packages/Vue/Vue Component.sublime-syntax" +// SYNTAX TEST "Vue Component.sublime-syntax" <style> h1 {} </style> From c99a4a9651f3613bb62521feac16b14d067ef25d Mon Sep 17 00:00:00 2001 From: DeathAxe <deathaxe82@googlemail.com> Date: Wed, 8 Sep 2021 22:18:06 +0200 Subject: [PATCH 9/9] Remove Github Actions Syntax test runner fails due to missing embedded syntax packages. This is an issue for another PR. --- .github/workflows/ci-syntax-tests.yml | 38 --------------------------- 1 file changed, 38 deletions(-) delete mode 100644 .github/workflows/ci-syntax-tests.yml diff --git a/.github/workflows/ci-syntax-tests.yml b/.github/workflows/ci-syntax-tests.yml deleted file mode 100644 index f05110e..0000000 --- a/.github/workflows/ci-syntax-tests.yml +++ /dev/null @@ -1,38 +0,0 @@ -name: CI Syntax Tests - -on: - push: - branches: - - 'st4' - paths: - - '.github/workflows/ci-syntax-tests.yml' - - '**.sublime-syntax' - - '**/syntax_test_*' - - '**.tmPreferences' - pull_request: - branches: - - '**' - paths: - - '.github/workflows/ci-syntax-tests.yml' - - '**.sublime-syntax' - - '**/syntax_test_*' - - '**.tmPreferences' - workflow_dispatch: - -jobs: - syntax_tests: - name: Sublime Text ${{ matrix.build }} - strategy: - matrix: - include: - - build: 4107 - packages: a147e3eb6210de480d0d9a6bd6bf54931a8ba7e9 - - build: latest - packages: master - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - uses: SublimeText/syntax-test-action@v2 - with: - build: ${{ matrix.build }} - default_packages: ${{ matrix.packages }}