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/Snippets/Template/block-end.sublime-snippet b/Go/Snippets/Template/block-end.sublime-snippet index bc5fe9eec2..f14c952f2f 100644 --- a/Go/Snippets/Template/block-end.sublime-snippet +++ b/Go/Snippets/Template/block-end.sublime-snippet @@ -3,6 +3,6 @@ $0 ${TM_TEMPLATE_START}end${TM_TEMPLATE_END}]]> tblockend -(text.html.go | text.html.markdown.go | source.css.go | source.js.go | source.go string) - source.go.template +(text.html.go | text.html.markdown.go | source.css.go | source.js.go | source.json.go | source.yaml.go | source.go string) - source.go.template {{block "name"}} ... {{end}} \ No newline at end of file diff --git a/Go/Snippets/Template/block.sublime-snippet b/Go/Snippets/Template/block.sublime-snippet index 0b66eae942..c830736e9d 100644 --- a/Go/Snippets/Template/block.sublime-snippet +++ b/Go/Snippets/Template/block.sublime-snippet @@ -1,6 +1,6 @@ tblock -(text.html.go | text.html.markdown.go | source.css.go | source.js.go | source.go string) - source.go.template +(text.html.go | text.html.markdown.go | source.css.go | source.js.go | source.json.go | source.yaml.go | source.go string) - source.go.template {{block "name"}} \ No newline at end of file diff --git a/Go/Snippets/Template/break.sublime-snippet b/Go/Snippets/Template/break.sublime-snippet index 21ac3f2ada..bf8741c575 100644 --- a/Go/Snippets/Template/break.sublime-snippet +++ b/Go/Snippets/Template/break.sublime-snippet @@ -1,6 +1,6 @@ tbreak -(text.html.go | text.html.markdown.go | source.css.go | source.js.go | source.go string) - source.go.template +(text.html.go | text.html.markdown.go | source.css.go | source.js.go | source.json.go | source.yaml.go | source.go string) - source.go.template {{break}} \ No newline at end of file diff --git a/Go/Snippets/Template/continue.sublime-snippet b/Go/Snippets/Template/continue.sublime-snippet index 00462852a4..fd8349453c 100644 --- a/Go/Snippets/Template/continue.sublime-snippet +++ b/Go/Snippets/Template/continue.sublime-snippet @@ -1,6 +1,6 @@ tcontinue -(text.html.go | text.html.markdown.go | source.css.go | source.js.go | source.go string) - source.go.template +(text.html.go | text.html.markdown.go | source.css.go | source.js.go | source.json.go | source.yaml.go | source.go string) - source.go.template {{continue}} \ No newline at end of file diff --git a/Go/Snippets/Template/define.sublime-snippet b/Go/Snippets/Template/define.sublime-snippet index c60e4b67a4..98e5354116 100644 --- a/Go/Snippets/Template/define.sublime-snippet +++ b/Go/Snippets/Template/define.sublime-snippet @@ -1,6 +1,6 @@ tdefine -(text.html.go | text.html.markdown.go | source.css.go | source.js.go | source.go string) - source.go.template +(text.html.go | text.html.markdown.go | source.css.go | source.js.go | source.json.go | source.yaml.go | source.go string) - source.go.template {{define "name"}} \ No newline at end of file diff --git a/Go/Snippets/Template/else if.sublime-snippet b/Go/Snippets/Template/else if.sublime-snippet index e0993fee73..441db83075 100644 --- a/Go/Snippets/Template/else if.sublime-snippet +++ b/Go/Snippets/Template/else if.sublime-snippet @@ -1,6 +1,6 @@ telseif -(text.html.go | text.html.markdown.go | source.css.go | source.js.go | source.go string) - source.go.template +(text.html.go | text.html.markdown.go | source.css.go | source.js.go | source.json.go | source.yaml.go | source.go string) - source.go.template {{else if ...}} \ No newline at end of file diff --git a/Go/Snippets/Template/else.sublime-snippet b/Go/Snippets/Template/else.sublime-snippet index b009690b4c..cf00e897ce 100644 --- a/Go/Snippets/Template/else.sublime-snippet +++ b/Go/Snippets/Template/else.sublime-snippet @@ -1,6 +1,6 @@ telse -(text.html.go | text.html.markdown.go | source.css.go | source.js.go | source.go string) - source.go.template +(text.html.go | text.html.markdown.go | source.css.go | source.js.go | source.json.go | source.yaml.go | source.go string) - source.go.template {{else}} \ No newline at end of file diff --git a/Go/Snippets/Template/end.sublime-snippet b/Go/Snippets/Template/end.sublime-snippet index f1d8f4cb07..166ab9dbbf 100644 --- a/Go/Snippets/Template/end.sublime-snippet +++ b/Go/Snippets/Template/end.sublime-snippet @@ -1,6 +1,6 @@ tend -(text.html.go | text.html.markdown.go | source.css.go | source.js.go | source.go string) - source.go.template +(text.html.go | text.html.markdown.go | source.css.go | source.js.go | source.json.go | source.yaml.go | source.go string) - source.go.template {{end}} \ No newline at end of file diff --git a/Go/Snippets/Template/if-end.sublime-snippet b/Go/Snippets/Template/if-end.sublime-snippet index fadf03e08c..d9cb5b423d 100644 --- a/Go/Snippets/Template/if-end.sublime-snippet +++ b/Go/Snippets/Template/if-end.sublime-snippet @@ -3,6 +3,6 @@ $0 ${TM_TEMPLATE_START}end${TM_TEMPLATE_END}]]> tifend -(text.html.go | text.html.markdown.go | source.css.go | source.js.go | source.go string) - source.go.template +(text.html.go | text.html.markdown.go | source.css.go | source.js.go | source.json.go | source.yaml.go | source.go string) - source.go.template {{if ...}} ... {{end}} \ No newline at end of file diff --git a/Go/Snippets/Template/if.sublime-snippet b/Go/Snippets/Template/if.sublime-snippet index 36bf010075..26d40dbd39 100644 --- a/Go/Snippets/Template/if.sublime-snippet +++ b/Go/Snippets/Template/if.sublime-snippet @@ -1,6 +1,6 @@ tif -(text.html.go | text.html.markdown.go | source.css.go | source.js.go | source.go string) - source.go.template +(text.html.go | text.html.markdown.go | source.css.go | source.js.go | source.json.go | source.yaml.go | source.go string) - source.go.template {{if ...}} \ No newline at end of file diff --git a/Go/Snippets/Template/partial.sublime-snippet b/Go/Snippets/Template/partial.sublime-snippet index c59164927b..7c08e45609 100644 --- a/Go/Snippets/Template/partial.sublime-snippet +++ b/Go/Snippets/Template/partial.sublime-snippet @@ -1,6 +1,6 @@ tpartial -(text.html.go | text.html.markdown.go | source.css.go | source.js.go | source.go string) - source.go.template +(text.html.go | text.html.markdown.go | source.css.go | source.js.go | source.json.go | source.yaml.go | source.go string) - source.go.template {{partial "name"}} \ No newline at end of file diff --git a/Go/Snippets/Template/range-end.sublime-snippet b/Go/Snippets/Template/range-end.sublime-snippet index b362851202..a1dd6afa91 100644 --- a/Go/Snippets/Template/range-end.sublime-snippet +++ b/Go/Snippets/Template/range-end.sublime-snippet @@ -3,6 +3,6 @@ $0 ${TM_TEMPLATE_START}end${TM_TEMPLATE_END}]]> trangeend -(text.html.go | text.html.markdown.go | source.css.go | source.js.go | source.go string) - source.go.template +(text.html.go | text.html.markdown.go | source.css.go | source.js.go | source.json.go | source.yaml.go | source.go string) - source.go.template {{range ...}}...{{end}} \ No newline at end of file diff --git a/Go/Snippets/Template/range.sublime-snippet b/Go/Snippets/Template/range.sublime-snippet index 79ef06b976..36abf38301 100644 --- a/Go/Snippets/Template/range.sublime-snippet +++ b/Go/Snippets/Template/range.sublime-snippet @@ -1,6 +1,6 @@ trange -(text.html.go | text.html.markdown.go | source.css.go | source.js.go | source.go string) - source.go.template +(text.html.go | text.html.markdown.go | source.css.go | source.js.go | source.json.go | source.yaml.go | source.go string) - source.go.template {{range ...}} \ No newline at end of file diff --git a/Go/Snippets/Template/template.sublime-snippet b/Go/Snippets/Template/template.sublime-snippet index 536d659c89..59b751188a 100644 --- a/Go/Snippets/Template/template.sublime-snippet +++ b/Go/Snippets/Template/template.sublime-snippet @@ -1,6 +1,6 @@ ttemplate -(text.html.go | text.html.markdown.go | source.css.go | source.js.go | source.go string) - source.go.template +(text.html.go | text.html.markdown.go | source.css.go | source.js.go | source.json.go | source.yaml.go | source.go string) - source.go.template {{template "name" .}} \ No newline at end of file diff --git a/Go/Snippets/Template/var.sublime-snippet b/Go/Snippets/Template/var.sublime-snippet index f083a8069b..417e71b675 100644 --- a/Go/Snippets/Template/var.sublime-snippet +++ b/Go/Snippets/Template/var.sublime-snippet @@ -1,6 +1,6 @@ tvar -(text.html.go | text.html.markdown.go | source.css.go | source.js.go | source.go string) - source.go.template +(text.html.go | text.html.markdown.go | source.css.go | source.js.go | source.json.go | source.yaml.go | source.go string) - source.go.template {{.Var}} \ No newline at end of file diff --git a/Go/Snippets/Template/with-end.sublime-snippet b/Go/Snippets/Template/with-end.sublime-snippet index 69de8515b0..99a3fefe88 100644 --- a/Go/Snippets/Template/with-end.sublime-snippet +++ b/Go/Snippets/Template/with-end.sublime-snippet @@ -3,6 +3,6 @@ $0 ${TM_TEMPLATE_START}end${TM_TEMPLATE_END}]]> twithend -(text.html.go | text.html.markdown.go | source.css.go | source.js.go | source.go string) - source.go.template +(text.html.go | text.html.markdown.go | source.css.go | source.js.go | source.json.go | source.yaml.go | source.go string) - source.go.template {{with ...}}...{{end}} \ No newline at end of file diff --git a/Go/Snippets/Template/with.sublime-snippet b/Go/Snippets/Template/with.sublime-snippet index 5857184b14..dba5dcdc81 100644 --- a/Go/Snippets/Template/with.sublime-snippet +++ b/Go/Snippets/Template/with.sublime-snippet @@ -1,6 +1,6 @@ twith -(text.html.go | text.html.markdown.go | source.css.go | source.js.go | source.go string) - source.go.template +(text.html.go | text.html.markdown.go | source.css.go | source.js.go | source.json.go | source.yaml.go | source.go string) - source.go.template {{with ...}} \ No newline at end of file diff --git a/Go/Template.tmPreferences b/Go/Template.tmPreferences index c79768c9b6..7f99049d08 100644 --- a/Go/Template.tmPreferences +++ b/Go/Template.tmPreferences @@ -10,7 +10,7 @@ whether templates are wrapped with whitespace. --> scope - (text.html.go | text.html.markdown.go | source.css.go | source.js.go | source.go string) - source.go.template + (text.html.go | text.html.markdown.go | source.css.go | source.js.go | source.json.go | source.yaml.go | source.go string) - source.go.template settings shellVariables diff --git a/Go/YAML (Go).sublime-syntax b/Go/YAML (Go).sublime-syntax new file mode 100644 index 0000000000..73245cd155 --- /dev/null +++ b/Go/YAML (Go).sublime-syntax @@ -0,0 +1,119 @@ +%YAML 1.2 +--- +# http://www.sublimetext.com/docs/syntax.html +name: YAML (Go) +scope: source.yaml.go +version: 2 + +extends: Packages/YAML/YAML.sublime-syntax + +file_extensions: + - goyaml + - go.yaml + - goyml + - go.yml + +variables: + ns_plain_first_plain_in: |- # c=plain-in + (?x: + {{yaml_ns_plain_first_plain_in}} + | (?:[?:-] )?{{ # begins with go interpolation + ) + + # original value from YAML + yaml_ns_plain_first_plain_in: |- # c=plain-in + (?x: + [^\s{{c_indicator}}] + | [?:-] [^\s{{c_flow_indicator}}] + ) + + ns_plain_first_plain_out: |- # c=plain-out + (?x: + {{yaml_ns_plain_first_plain_out}} + | (?:[?:-] )?{{ # begins with go interpolation + ) + + # original value from YAML + yaml_ns_plain_first_plain_out: |- # c=plain-out + (?x: + [^\s{{c_indicator}}] + | [?:-] \S + ) + + _flow_key_in_lookahead: |- + (?x: + (?= + ( + (?: + {{yaml_ns_plain_first_plain_in}} + | {{go_interpolation}} # begins with interpolation + ) + ( [^\s:{{c_flow_indicator}}] + | : [^\s{{c_flow_indicator}}] + | \s+ (?![#\s]) + | {{go_interpolation}} # ignore interpolation + )* + | \".*\" # simplified + | \'.*\' + ) + \s* + : + (?:\s|$) + ) + ) + + _flow_key_out_lookahead: |- + (?x: + (?= + + ( + (?: + {{yaml_ns_plain_first_plain_out}} + | {{go_interpolation}} # begins with interpolation + ) + ( [^\s:] + | : \S + | \s+ (?![#\s]) + | {{go_interpolation}} # ignore interpolation + )* + | \".*\" # simplified + | \'.*\' + ) + \s* + : + (?:\s|$) + ) + ) + + go_interpolation: '{{.*?}}' + +contexts: + + main: + - meta_prepend: true + - meta_scope: meta.template.go + + block-scalar-body: + - meta_prepend: true + - include: scope:source.go#match-block-string-templates + + flow-scalar-plain-in-body: + - meta_prepend: true + - include: scope:source.go#match-block-string-templates + + flow-scalar-plain-out-body: + - meta_prepend: true + - include: scope:source.go#match-block-string-templates + + flow-scalar-double-quoted-body: + - meta_prepend: true + - include: scope:source.go#match-block-string-templates + + flow-scalar-single-quoted-body: + - meta_prepend: true + - include: scope:source.go#match-block-string-templates + + flow-mapping: + - match: \{(?![{%#]) + scope: punctuation.definition.mapping.begin.yaml + push: flow-mapping-body 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 new file mode 100644 index 0000000000..d656ab8142 --- /dev/null +++ b/Go/tests/syntax_test_template.yaml @@ -0,0 +1,109 @@ +# 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 + +{{- printf "- name: %s" $key -}} +# <- meta.string.yaml meta.interpolation.go punctuation.section.interpolation.begin.go - meta.mapping +#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.string.yaml meta.interpolation.go - meta.mapping +# ^^ punctuation.section.interpolation.end.go + +{{- printf "- name: %s" $key -}}: +# <- meta.mapping.key.yaml meta.string.yaml meta.interpolation.go punctuation.section.interpolation.begin.go +#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.mapping.key.yaml meta.string.yaml meta.interpolation.go +# ^^ punctuation.section.interpolation.end.go +# ^ punctuation.separator.key-value.mapping.yaml + +key: {{ /*comment*/ }} +# ^^^^^^^^^^^^^^^^^ meta.string.yaml meta.interpolation.go - string +# ^^ punctuation.section.interpolation.begin.go +# ^^^^^^^^^^^^^ source.go.template +# ^^ punctuation.section.interpolation.end.go + +{{ if $var true }} +# <- meta.string.yaml meta.interpolation.go punctuation.section.interpolation.begin.go +#^^^^^^^^^^^^^^^^^ meta.string.yaml meta.interpolation.go +#^ punctuation.section.interpolation.begin.go +# ^^^^^^^^^^^^^^ meta.string.yaml meta.interpolation.go source.go.template +# ^^ punctuation.section.interpolation.end.go + + {{ .keyname }}: "String{{value}}" +# ^^^^^^^^^^^^^^ meta.mapping.key.yaml meta.string.yaml meta.interpolation.go +# ^^ punctuation.section.interpolation.begin.go +# ^^^^^^^^^^ source.go.template +# ^^ punctuation.section.interpolation.end.go +# ^ punctuation.separator.key-value.mapping.yaml +# ^^^^^^^ meta.string.yaml string.quoted.double.yaml +# ^^^^^^^^^ meta.string.yaml meta.interpolation.go +# ^ meta.string.yaml string.quoted.double.yaml punctuation.definition.string.end.yaml + +{{ else }} +# <- meta.string.yaml meta.interpolation.go punctuation.section.interpolation.begin.go +#^^^^^^^^^ meta.string.yaml meta.interpolation.go +#^ punctuation.section.interpolation.begin.go +# ^^^^^^ meta.string.yaml meta.interpolation.go source.go.template +# ^^ punctuation.section.interpolation.end.go + + {{ .keyname }}: +# ^^^^^^^^^^^^^^ meta.mapping.key.yaml meta.string.yaml meta.interpolation.go +# ^^ punctuation.section.interpolation.begin.go +# ^^^^^^^^^^ source.go.template +# ^^ punctuation.section.interpolation.end.go +# ^ punctuation.separator.key-value.mapping.yaml + - Multi{{ printf +# ^ punctuation.definition.block.sequence.item.yaml +# ^^^^^ 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 + + - 'Multi{{ printf +# ^ punctuation.definition.block.sequence.item.yaml +# ^^^^^^ meta.string.yaml string.quoted.single.yaml +# ^ punctuation.definition.string.begin.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 + + - "Multi{{ printf +# ^ punctuation.definition.block.sequence.item.yaml +# ^^^^^^ meta.string.yaml string.quoted.double.yaml +# ^ punctuation.definition.string.begin.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 +#^^^^^^^^ meta.string.yaml meta.interpolation.go +#^ punctuation.section.interpolation.begin.go +# ^^^^^ meta.string.yaml meta.interpolation.go source.go.template +# ^^ punctuation.section.interpolation.end.go