diff --git a/Go/Go.sublime-syntax b/Go/Go.sublime-syntax index 163eccb988..4942a53e2f 100644 --- a/Go/Go.sublime-syntax +++ b/Go/Go.sublime-syntax @@ -747,8 +747,24 @@ contexts: - match: \%(?:\[\d+\])?[ .\d*#+-]*[A-Za-z] scope: constant.other.placeholder.go + match-block-string-templates: + # This context is used for interpolation within quoted or unquoted multiline strings. + # Doesn't check for closing `}}` as it might be located on a sub-sequent line. + # It clears the `string` scope of the owning context. + # Note: used by YAML (Go).sublime-syntax + - match: ({{)(-?) + captures: + 1: punctuation.section.interpolation.begin.go + 2: keyword.operator.template.trim.left.go + push: + - pop-now-clear-scope + - match-template-inner + - match-template-function + - match-template-keyword + match-string-templates: # This context is used for interpolation within quoted or unquoted strings. + # Matchs only if closing `}}` is found on same line to avoid false positives. # It clears the `string` scope of the owning context. - match: ({{)(-?)(?=.*?}}) captures: diff --git a/Go/YAML (Go).sublime-syntax b/Go/YAML (Go).sublime-syntax index 08c8aadcdf..c6e7199081 100644 --- a/Go/YAML (Go).sublime-syntax +++ b/Go/YAML (Go).sublime-syntax @@ -37,23 +37,23 @@ contexts: block-scalar-body: - meta_prepend: true - - include: scope:source.go#match-string-templates + - include: scope:source.go#match-block-string-templates flow-scalar-plain-in-body: - meta_prepend: true - - include: scope:source.go#match-string-templates + - include: scope:source.go#match-block-string-templates flow-scalar-plain-out-body: - meta_prepend: true - - include: scope:source.go#match-string-templates + - include: scope:source.go#match-block-string-templates flow-scalar-double-quoted-body: - meta_prepend: true - - include: scope:source.go#match-string-templates + - include: scope:source.go#match-block-string-templates flow-scalar-single-quoted-body: - meta_prepend: true - - include: scope:source.go#match-string-templates + - include: scope:source.go#match-block-string-templates flow-mapping: - match: \{(?![{%#]) diff --git a/Go/tests/syntax_test_template.html b/Go/tests/syntax_test_template.html index bcd2aefd1f..8819882e98 100644 --- a/Go/tests/syntax_test_template.html +++ b/Go/tests/syntax_test_template.html @@ -67,6 +67,18 @@ + + {{/* +| ^ - meta.interpolation +| ^^ meta.interpolation.go punctuation.section.interpolation.begin.go +| ^^ meta.interpolation.go source.go.template comment.block.go punctuation.definition.comment.begin.go + Spread a key-value map into the "env" list +| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.interpolation.go source.go.template comment.block.go + */}} +| ^^ meta.interpolation.go source.go.template comment.block.go punctuation.definition.comment.end.go +| ^^ meta.interpolation.go punctuation.section.interpolation.end.go +| ^ - meta.interpolation + {{ block "main" . }} | ^^^^^^^^^^^^^^^^^^^^ meta.interpolation.go | ^^ punctuation.section.interpolation.begin.go diff --git a/Go/tests/syntax_test_template.md b/Go/tests/syntax_test_template.md index 79f4f373aa..ba92a958f6 100644 --- a/Go/tests/syntax_test_template.md +++ b/Go/tests/syntax_test_template.md @@ -21,6 +21,16 @@ | ^ keyword.operator.template.trim.right.go | ^^ punctuation.section.interpolation.end.go - source.go + {{/* +|^ meta.paragraph.markdown - meta.interpolation +| ^^ meta.paragraph.markdown meta.interpolation.go punctuation.section.interpolation.begin.go +| ^^ meta.paragraph.markdown meta.interpolation.go source.go.template comment.block.go punctuation.definition.comment.begin.go + Spread a key-value map into the "env" list +| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.paragraph.markdown meta.interpolation.go source.go.template comment.block.go + */}} +| ^^ meta.paragraph.markdown meta.interpolation.go source.go.template comment.block.go punctuation.definition.comment.end.go +| ^^ meta.paragraph.markdown meta.interpolation.go punctuation.section.interpolation.end.go +| ^ meta.paragraph.markdown - meta.interpolation # My {{ .Site.Title }} homepage | <- markup.heading.1.markdown punctuation.definition.heading.begin.markdown diff --git a/Go/tests/syntax_test_template.yaml b/Go/tests/syntax_test_template.yaml index 6a8a76425e..d980082324 100644 --- a/Go/tests/syntax_test_template.yaml +++ b/Go/tests/syntax_test_template.yaml @@ -1,5 +1,18 @@ # SYNTAX TEST "Packages/Go/YAML (Go).sublime-syntax" + {{/* +#^ - meta.string - meta.interpolation +# ^^ meta.string.yaml meta.interpolation.go punctuation.section.interpolation.begin.go +# ^^ meta.string.yaml meta.interpolation.go source.go.template comment.block.go punctuation.definition.comment.begin.go + Spread a key-value map into the "env" list +# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.string.yaml meta.interpolation.go source.go.template comment.block.go + */}} +# <- meta.string.yaml meta.interpolation.go source.go.template comment.block.go +#^ meta.string.yaml meta.interpolation.go source.go.template comment.block.go - punctuation +# ^^ meta.string.yaml meta.interpolation.go source.go.template comment.block.go punctuation.definition.comment.end.go +# ^^ meta.string.yaml meta.interpolation.go punctuation.section.interpolation.end.go +# ^ - meta.string - meta.interpolation + key: {{ /*comment*/ }} # ^^^^^^^^^^^^^^^^^ meta.string.yaml meta.interpolation.go - string # ^^ punctuation.section.interpolation.begin.go @@ -36,33 +49,46 @@ key: {{ /*comment*/ }} # ^^^^^^^^^^ source.go.template # ^^ punctuation.section.interpolation.end.go # ^ punctuation.separator.key-value.mapping.yaml - - Val{{ $ue }} + - Multi{{ printf # ^ punctuation.definition.block.sequence.item.yaml -# ^^^ meta.string.yaml string.unquoted.plain.out.yaml -# ^^^^^^^^^ meta.template.go meta.string.yaml meta.interpolation.go -# ^^ punctuation.section.interpolation.begin.go -# ^^^ variable.other.template.go -# ^^ punctuation.section.interpolation.end.go +# ^^^^^ meta.string.yaml string.unquoted.plain.out.yaml +# ^^^^^^^^^^ meta.string.yaml meta.interpolation.go - string +# ^^ punctuation.section.interpolation.begin.go +# ^^^^^^ support.function.builtin.go + $line }} string +# ^^^^^^^^^ meta.string.yaml meta.interpolation.go - string +# ^^^^^ variable.other.template.go +# ^^ punctuation.section.interpolation.end.go +# ^^^^^^^ meta.string.yaml string.unquoted.plain.out.yaml - meta.interpolation - - 'Val{{ $ue }}' + - 'Multi{{ printf # ^ punctuation.definition.block.sequence.item.yaml -# ^^^^ meta.template.go meta.string.yaml string.quoted.single.yaml +# ^^^^^^ meta.string.yaml string.quoted.single.yaml # ^ punctuation.definition.string.begin.yaml -# ^^^^^^^^^ meta.template.go meta.string.yaml meta.interpolation.go -# ^^ punctuation.section.interpolation.begin.go -# ^^^ variable.other.template.go -# ^^ punctuation.section.interpolation.end.go -# ^ punctuation.definition.string.end.yaml +# ^^^^^^^^^^ meta.string.yaml meta.interpolation.go - string +# ^^ punctuation.section.interpolation.begin.go +# ^^^^^^ support.function.builtin.go + $line }} string' +# ^^^^^^^^^ meta.string.yaml meta.interpolation.go - string +# ^^^^^ variable.other.template.go +# ^^ punctuation.section.interpolation.end.go +# ^^^^^^^^ meta.string.yaml string.quoted.single.yaml - meta.interpolation +# ^ punctuation.definition.string.end.yaml - - "Val{{ $ue }}" + - "Multi{{ printf # ^ punctuation.definition.block.sequence.item.yaml -# ^^^^ meta.template.go meta.string.yaml string.quoted.double.yaml +# ^^^^^^ meta.string.yaml string.quoted.double.yaml # ^ punctuation.definition.string.begin.yaml -# ^^^^^^^^^ meta.template.go meta.string.yaml meta.interpolation.go -# ^^ punctuation.section.interpolation.begin.go -# ^^^ variable.other.template.go -# ^^ punctuation.section.interpolation.end.go -# ^ punctuation.definition.string.end.yaml +# ^^^^^^^^^^ meta.string.yaml meta.interpolation.go - string +# ^^ punctuation.section.interpolation.begin.go +# ^^^^^^ support.function.builtin.go + + $line }} string" +# ^^^^^^^^^ meta.string.yaml meta.interpolation.go - string +# ^^^^^ variable.other.template.go +# ^^ punctuation.section.interpolation.end.go +# ^^^^^^^^ meta.string.yaml string.quoted.double.yaml - meta.interpolation +# ^ punctuation.definition.string.end.yaml {{ end }} # <- meta.string.yaml meta.interpolation.go punctuation.section.interpolation.begin.go