Skip to content

Commit

Permalink
support block scalar ifs
Browse files Browse the repository at this point in the history
  • Loading branch information
keith-hall committed Sep 18, 2023
1 parent fad273c commit 5566779
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 1 deletion.
49 changes: 48 additions & 1 deletion Github Actions.sublime-syntax
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,20 @@ contexts:
1: string.unquoted.plain.out.yaml keyword.control.flow.script.pipeline
2: punctuation.separator.key-value.yaml
push: script-block-node
- match: \s+(if)\s*(:)(?=\s+(?!\$\{\{)) # TODO: be smarter in case | is used etc.
- match: \s+(if)\s*(:)(?=\s+\|)
captures:
1: string.unquoted.plain.out.yaml keyword.control.flow.condition.pipeline
2: punctuation.separator.key-value.yaml
push: if-block-scalar
- match: \s+(if)\s*(:)(?=\s+(?!\$\{\{))
captures:
1: string.unquoted.plain.out.yaml keyword.control.flow.condition.pipeline
2: punctuation.separator.key-value.yaml
push: inside-if
- match: \s+(if)\s*(:)(?=\s+(?=\$\{\{))
captures:
1: string.unquoted.plain.out.yaml keyword.control.flow.condition.pipeline
2: punctuation.separator.key-value.yaml
- match: \s+(needs)\s*(:)(?=\s|$)
captures:
1: string.unquoted.plain.out.yaml keyword.control.conditional.dependencies.pipeline
Expand Down Expand Up @@ -100,3 +109,41 @@ contexts:
captures:
0: variable.language.github-actions
1: punctuation.definition.variable.github-actions

if-block-scalar:
# http://www.yaml.org/spec/1.2/spec.html#style/block/scalar
# c-l+literal(n) | c-l+folded(n)
- match: (?:(\|)|(>))(?:([1-9])([-+])|([-+])?([1-9])?) # c-b-block-header(m,t)
captures:
1: keyword.control.flow.block-scalar.literal.yaml
2: keyword.control.flow.block-scalar.folded.yaml
3: constant.numeric.indentation-indicator.yaml
4: storage.modifier.chomping-indicator.yaml
5: storage.modifier.chomping-indicator.yaml
6: constant.numeric.indentation-indicator.yaml
set: if-block-scalar-begin

if-block-scalar-begin:
- meta_include_prototype: false
- match: ^([ ]+)(?! ) # match first non-empty line to determine indentation level
# note that we do not check if indentation is enough
set: if-block-scalar-body
- match: ^(?=\S) # the block is empty
pop: true
- include: comment # include comments but not properties
- match: .+
scope: invalid.illegal.expected-comment-or-newline.yaml

if-block-scalar-body:
- meta_include_prototype: false
- meta_scope: meta.block.if.github-actions
- include: inside-expression
- include: comment
- match: ^(?!\1|\s*$)
pop: true

variable-access:
- meta_prepend: true
- match: \*
scope: constant.other.wildcard.github-actions
set: possible-accessor
12 changes: 12 additions & 0 deletions tests/syntax_test_github_actions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ jobs:
with:
path: st_syntax_tests/Data/Packages
if: ${{github.repository == 'example-user/cascade-repo'}}
# ^^ string.unquoted.plain.out.yaml keyword.control.flow.condition.pipeline
# ^^^ punctuation.section.block.begin
# ^^^^^^ constant.language.context
# ^ punctuation.accessor.dot
Expand All @@ -109,6 +110,17 @@ jobs:
# ^ punctuation.definition.string.begin
# ^^^^^^^^^^^^^^^^^^^^^^^^^ string.quoted.single
# ^ punctuation.definition.string.end
if: |
# ^ keyword.control.flow.block-scalar.literal.yaml
github.event.inputs.some_input == 'true'
#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.block.if.github-actions
|| contains(github.event.pull_request.labels.*.name, 'some_label')
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.block.if.github-actions
# ^ punctuation.accessor.dot.pipeline
# ^ constant.other.wildcard.github-actions
# ^ punctuation.accessor.dot.pipeline
# ^^^^ variable.other.member.pipeline
# <- keyword.operator.logical.github-actions
- name: "Get binary for ${{ matrix.sublime-channel }} build ${{ matrix.sublime-build }}"
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.string.yaml
Expand Down

0 comments on commit 5566779

Please sign in to comment.