Skip to content

Commit

Permalink
Improve string interpolation (#5)
Browse files Browse the repository at this point in the history
* Reorder main keys

This commit applies main key sort order for syntax version 2

implements: sublimehq/Packages#2430

* Replace pop: true with pop: 1

This commit replaces pop: true to 

1. avoid mixed styles if multiple levels of pop may be added. 
2. as some statements use `pop: 1` already.
3. it makes it more clear to be a syntax version 2.

* Distinguish interpolation and string interpolation

This commit makes sure to clear `string` scopes where needed, so only
meta.string meta.interpolation is left.

* Add interpolation support for quoted strings
  • Loading branch information
deathaxe authored Feb 28, 2023
1 parent 32e3b3f commit 3479540
Show file tree
Hide file tree
Showing 7 changed files with 94 additions and 36 deletions.
35 changes: 30 additions & 5 deletions AzureDevops.sublime-syntax
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
---
# See http://www.sublimetext.com/docs/3/syntax.html
scope: source.yaml.pipeline.azure-devops
extends: Packages/YamlPipelines/YamlPipeline.sublime-syntax
version: 2

extends: Packages/YamlPipelines/YamlPipeline.sublime-syntax

file_extensions:
- azure-pipeline.yml

Expand Down Expand Up @@ -33,7 +35,28 @@ contexts:
- include: flow-scalar-plain-out-body
- include: inside-expression

expression-begin:
string-interpolations:
# https://learn.microsoft.com/en-us/azure/devops/pipelines/process/expressions?view=azure-devops
- meta_prepend: true
- match: \$\(
scope: punctuation.definition.variable.begin.pipeline
push: inside-ado-variable-reference-string-interpolation
- match: \$\[
scope: punctuation.section.block.begin.pipeline
push: inside-ado-runtime-expression-string-interpolations

inside-ado-variable-reference-string-interpolation:
- clear_scopes: 1 # clear string scope
- meta_scope: meta.interpolation.pipeline
- meta_content_scope: variable.other.constant.pipeline
- include: inside-ado-variable-reference

inside-ado-runtime-expression-string-interpolations:
- clear_scopes: 1 # clear string scope
- meta_scope: meta.interpolation.pipeline meta.block.pipeline
- include: inside-ado-runtime-expression

interpolations:
# https://learn.microsoft.com/en-us/azure/devops/pipelines/process/expressions?view=azure-devops
- meta_prepend: true
- match: \$\(
Expand All @@ -44,20 +67,22 @@ contexts:
push: inside-ado-runtime-expression

inside-ado-variable-reference:
- meta_scope: meta.interpolation.pipeline
- meta_content_scope: variable.other.constant.pipeline
- match: \)
scope: punctuation.definition.variable.end.pipeline
pop: true
pop: 1

inside-ado-runtime-expression:
- meta_scope: meta.interpolation.pipeline meta.block.pipeline
- match: \]
scope: punctuation.section.block.end.pipeline
pop: true
pop: 1
- include: inside-expression

inside-expression:
- meta_append: true
- include: expression-begin
- include: interpolations
- include: context
- match: \b(?i:true|false)\b
scope: constant.language.boolean.pipeline
Expand Down
12 changes: 7 additions & 5 deletions Bash (AzureDevops).sublime-syntax
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,17 @@
---
# See http://www.sublimetext.com/docs/3/syntax.html
scope: source.shell.bash.azure-devops
extends: Packages/ShellScript/Bash.sublime-syntax
version: 2
hidden: true

extends: Packages/ShellScript/Bash.sublime-syntax

contexts:
string-quoted-double-body:

expansions-parameter:
- meta_prepend: true
- include: scope:source.yaml.pipeline.azure-devops#expression-begin
- include: scope:source.yaml.pipeline.azure-devops#interpolations

string-quoted-single-body:
string-prototype:
- meta_prepend: true
- include: scope:source.yaml.pipeline.azure-devops#expression-begin
- include: scope:source.yaml.pipeline.azure-devops#string-interpolations
15 changes: 6 additions & 9 deletions Bash (Github Actions).sublime-syntax
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,19 @@
---
# See http://www.sublimetext.com/docs/3/syntax.html
scope: source.shell.bash.github-actions
extends: Packages/ShellScript/Bash.sublime-syntax
version: 2
hidden: true

contexts:
string-quoted-double-body:
- meta_prepend: true
- include: scope:source.yaml.pipeline.github-actions#expression-begin
extends: Packages/ShellScript/Bash.sublime-syntax

string-quoted-single-body:
contexts:
expansions-parameter:
- meta_prepend: true
- include: scope:source.yaml.pipeline.github-actions#expression-begin
- include: scope:source.yaml.pipeline.github-actions#interpolations

cmd-args:
string-prototype:
- meta_prepend: true
- include: scope:source.yaml.pipeline.github-actions#expression-begin
- include: scope:source.yaml.pipeline.github-actions#string-interpolations

heredocs-body:
- meta_prepend: true
Expand Down
4 changes: 2 additions & 2 deletions Github Actions.sublime-syntax
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
---
# See http://www.sublimetext.com/docs/3/syntax.html
scope: source.yaml.pipeline.github-actions
extends: Packages/YamlPipelines/YamlPipeline.sublime-syntax
version: 2

extends: Packages/YamlPipelines/YamlPipeline.sublime-syntax

contexts:
node:
- meta_prepend: true
Expand Down Expand Up @@ -35,7 +36,6 @@ contexts:
- include: inside-expression

inside-expression:
- meta_include_prototype: false
- meta_append: true
# https://docs.github.com/en/actions/learn-github-actions/expressions
- include: context
Expand Down
11 changes: 7 additions & 4 deletions Kong.sublime-syntax
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
%YAML 1.2
---
# See http://www.sublimetext.com/docs/syntax.html
file_extensions:
- kong.yml
scope: source.yaml.kong
extends: Packages/YAML/YAML.sublime-syntax
version: 2

extends: Packages/YAML/YAML.sublime-syntax

file_extensions:
- kong.yml

contexts:
main:
- meta_prepend: true
Expand All @@ -20,7 +23,7 @@ contexts:
- include: comment
- include: paths-block-sequence
- match: ^
pop: true
pop: 1

paths-block-sequence:
# http://www.yaml.org/spec/1.2/spec.html#style/block/sequence
Expand Down
41 changes: 31 additions & 10 deletions YamlPipeline.sublime-syntax
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,46 @@
---
# See http://www.sublimetext.com/docs/3/syntax.html
scope: source.yaml.pipeline
extends: Packages/YAML/YAML.sublime-syntax
version: 2
hidden: true

extends: Packages/YAML/YAML.sublime-syntax

contexts:
flow-scalar-double-quoted-body:
- meta_prepend: true
- include: string-interpolations

flow-scalar-single-quoted-body:
- meta_prepend: true
- include: string-interpolations

flow-scalar-plain-out-body:
- meta_prepend: true
- include: expression-begin
- include: string-interpolations

string-interpolations:
- match: \$\{\{
scope: punctuation.section.block.begin.pipeline
push: inside-string-interpolations

expression-begin:
inside-string-interpolations:
- clear_scopes: 1
- meta_include_prototype: false
- meta_scope: meta.interpolation.pipeline meta.block.pipeline
- include: inside-expression

interpolations:
- match: \$\{\{
scope: punctuation.section.block.begin.pipeline
push: inside-expression

inside-expression:
- meta_include_prototype: false
- meta_content_scope: meta.interpolation.pipeline
- meta_scope: meta.interpolation.pipeline meta.block.pipeline
- match: \}\}
scope: punctuation.section.block.end.pipeline
pop: true
pop: 1
- match: \b(?:true|false)\b
scope: constant.language.boolean.pipeline
- match: \b(\w+)\s*(\()
Expand Down Expand Up @@ -70,6 +90,7 @@ contexts:
pop: 1

embedded-bash:
- clear_scopes: 1
- meta_include_prototype: false

script-block-scalar-begin:
Expand All @@ -81,7 +102,7 @@ contexts:
escape: ^(?!\1|\s*$)
pop: 1
- match: ^(?=\S) # the block is empty
pop: true
pop: 1
- include: comment # include comments but not properties
- match: .+
scope: invalid.illegal.expected-comment-or-newline.yaml
Expand All @@ -94,12 +115,12 @@ contexts:
scope: punctuation.accessor.begin.pipeline
push: inside-property-index
- match: ''
pop: true
pop: 1

inside-property-index:
- match: \]
scope: punctuation.accessor.end.pipeline
pop: true
pop: 1
- include: variable-access
- include: strings
# TODO: use use inside-expression instead?
Expand All @@ -109,7 +130,7 @@ contexts:
scope: variable.other.member.pipeline
set: possible-accessor
# - match: ''
# pop: true
# pop: 1

strings:
- match: \'
Expand All @@ -124,5 +145,5 @@ contexts:
scope: constant.character.escape.pipeline
- match: \'
scope: punctuation.definition.string.end.pipeline
pop: true
pop: 1

12 changes: 11 additions & 1 deletion tests/syntax_test_github_actions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ jobs:
# ^^^^^^^^^^^^^^^^ entity.name.function.github-actions
# ^ punctuation.separator.key-value.yaml
name: Test on ${{ matrix.sublime-channel }} build
# ^^^^^^^^ meta.string.yaml string.unquoted.plain.out.yaml
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.string.yaml meta.interpolation.pipeline meta.block.pipeline - string
# ^^^^^^ meta.string.yaml string.unquoted.plain.out.yaml
# ^^^ punctuation.section.block.begin
# ^^^^^^ constant.language.context
# ^ punctuation.accessor.dot
Expand All @@ -46,6 +49,7 @@ jobs:
# ^^^^^^^^ meta.function-call.identifier support.function
# TODO: scope quotes correctly in `if` above
if: ${{ !contains(github.event.head_commit.message, 'SKIP SCRIPTS') }}
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.string.yaml meta.interpolation.pipeline meta.block.pipeline - string.unquoted
# ^^^ punctuation.section.block.begin
# ^ keyword.operator.logical
# ^^^^^^^^ meta.function-call.identifier support.function
Expand Down Expand Up @@ -106,7 +110,13 @@ jobs:
# ^^^^^^^^^^^^^^^^^^^^^^^^^ string.quoted.single
# ^ punctuation.definition.string.end

- name: Get binary for ${{ matrix.sublime-channel }} build ${{ matrix.sublime-build }}
- name: "Get binary for ${{ matrix.sublime-channel }} build ${{ matrix.sublime-build }}"
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.string.yaml
# ^^^^^^^^^^^^^^^^ string.quoted.double.yaml - meta.interpolation
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.interpolation.pipeline meta.block.pipeline - string
# ^^^^^^^ string.quoted.double.yaml - meta.interpolation
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.interpolation.pipeline meta.block.pipeline - string
# ^ string.quoted.double.yaml punctuation.definition.string.end.yaml - meta.interpolation
run: |
if [[ "${{ matrix.sublime-build }}" == "latest" ]]; then
# ^^ support.function.test.begin
Expand Down

0 comments on commit 3479540

Please sign in to comment.