Skip to content

Commit 6e3dd59

Browse files
authored
Merge pull request #27 from SublimeText/aws_templates
initial support for AWS templates
2 parents 8b3b33e + 5155a90 commit 6e3dd59

File tree

4 files changed

+170
-1
lines changed

4 files changed

+170
-1
lines changed

AWSTemplate.sublime-syntax

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
%YAML 1.2
2+
---
3+
name: AWS YAML Template
4+
scope: source.yaml.pipeline.aws
5+
version: 2
6+
7+
extends: Packages/YamlPipelines/YamlPipeline.sublime-syntax
8+
9+
file_extensions:
10+
- cron.yaml
11+
- fargate.yaml
12+
- predeploy.yaml
13+
14+
first_line_match: '^AWSTemplateFormatVersion:'
15+
16+
variables:
17+
variable_interpolation: |-
18+
(?x)(?:
19+
(\$\{)((?:AWS::)?\w+)(\})
20+
)
21+
22+
23+
contexts:
24+
flow-scalar-plain-out-body:
25+
- meta_prepend: true
26+
- include: variable-interpolation
27+
28+
flow-scalar-single-quoted-body:
29+
- meta_prepend: true
30+
- include: variable-interpolation
31+
32+
flow-scalar-double-quoted-body:
33+
- meta_prepend: true
34+
- include: variable-interpolation
35+
36+
variable-interpolation:
37+
- match: '{{variable_interpolation}}'
38+
captures:
39+
1: punctuation.section.interpolation.begin.aws
40+
2: variable.other.constant.aws
41+
3: punctuation.section.interpolation.end.aws
42+
43+
node:
44+
- meta_prepend: true
45+
- match: ^(\s+)(Command)\s*(:)(?=\s|$)
46+
captures:
47+
2: string.unquoted.plain.out.yaml keyword.control.flow.script.pipeline
48+
3: punctuation.separator.key-value.yaml
49+
push: script-block-sequence
50+
51+
script-block-sequence:
52+
- match: |-
53+
(?x)^(\s+)(-)[ \t]+(?="CMD-SHELL"|'CMD-SHELL'|CMD-SHELL\b)
54+
(["'])?
55+
(CMD-SHELL)
56+
(["'])?
57+
captures:
58+
2: punctuation.definition.block.sequence.item.yaml
59+
3: punctuation.definition.string.begin.yaml
60+
4: variable.language.aws
61+
5: punctuation.definition.string.end.yaml
62+
set:
63+
- expect-script-block-node
64+
- pop-at-bol
65+
- include: expect-script-block-node
66+
67+
pop-if-not-sequence-at-same-or-deeper-indentation:
68+
- match: ^(?!\1\s*-)
69+
pop: 1
70+
71+
pop-at-bol:
72+
- match: ^
73+
pop: 1
74+
75+
expect-script-block-node:
76+
- match: (-)[ \t]+(?=\S)(["'])?
77+
captures:
78+
1: punctuation.definition.block.sequence.item.yaml
79+
2: punctuation.definition.string.begin.yaml
80+
push: script-block-node
81+
- include: pop-if-not-sequence-at-same-or-deeper-indentation
82+
83+
script-block-node:
84+
- meta_prepend: true
85+
- include: flow-alias
86+
- match: '{{_flow_scalar_end_plain_out}}'
87+
pop: 1
88+
89+
embedded-bash:
90+
- meta_include_prototype: false
91+
- meta_scope: source.shell.bash.embedded
92+
- include: scope:source.shell.bash.aws
93+

Bash (AWS).sublime-syntax

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
%YAML 1.2
2+
---
3+
# See http://www.sublimetext.com/docs/3/syntax.html
4+
scope: source.shell.bash.aws
5+
version: 2
6+
hidden: true
7+
8+
extends: Packages/ShellScript/Bash.sublime-syntax
9+
10+
# NOTE: this syntax is designed to handle YAML sequence delimited Bash
11+
12+
contexts:
13+
prototype:
14+
- meta_prepend: true
15+
- match: ^\s*(-)[ \t]+(?=\S)(["'])?
16+
captures:
17+
1: punctuation.definition.block.sequence.item.yaml
18+
2: punctuation.definition.string.begin.yaml
19+
- match: (["'])$
20+
captures:
21+
1: punctuation.definition.string.end.yaml
22+
23+
variables:
24+
# lazy escaping from heredoc as shell maybe indented
25+
no_indent: ^\s*
26+
tab_indent: ^\s*

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Yaml Pipelines for Sublime Text
22

3-
Syntax highlighting definitions for YAML pipeline files, like GitHub Actions and AzureDevops, Drone CI, GitLab CICD etc.
3+
Syntax highlighting definitions for YAML pipeline files, like GitHub Actions and AzureDevops, Drone CI, GitLab CICD, AWS templates etc.
44
Includes a small plugin to automatically apply the GitHub Actions filetype when loading or saving a YAML file in a `.github/workflows` folder.
55

66
Why not just use the default YAML syntax definition? Because it doesn't highlight conditions, variables or embedded Bash or PowerShell scripts!

tests/syntax_test_aws.fargate.yaml

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# SYNTAX TEST "Packages/YamlPipelines/AWSTemplate.sublime-syntax"
2+
3+
Resources:
4+
SomeTask:
5+
Properties:
6+
ContainerDefinitions:
7+
- Name: "some_name"
8+
Image: !Sub "${AWS::AccountId}.dkr.ecr.${AWS::Region}.amazonaws.com/some_path:${DockerImageVersion}"
9+
# ^^ meta.string.yaml string.quoted.double.yaml punctuation.section.interpolation.begin.aws
10+
# ^^^^^^^^^^^^^^ meta.string.yaml string.quoted.double.yaml variable.other.constant.aws
11+
# ^ meta.string.yaml string.quoted.double.yaml punctuation.section.interpolation.end.aws
12+
Command:
13+
# ^^^^^^^ string.unquoted.plain.out.yaml keyword.control.flow.script.pipeline
14+
# ^ punctuation.separator.key-value.yaml
15+
- "bin/console"
16+
# ^ meta.block.script.pipeline punctuation.definition.block.sequence.item.yaml
17+
# ^ meta.block.script.pipeline punctuation.definition.string.begin.yaml - source.shell
18+
# ^^^^^^^^^^^ source.shell.bash.embedded meta.function-call.identifier.shell variable.function.shell
19+
# ^ source.shell.bash.embedded meta.function-call.identifier.shell punctuation.definition.string.end.yaml
20+
- "messenger:consume"
21+
- "--quiet"
22+
- "--memory-limit=120M"
23+
- "clearing-payouts-executed"
24+
- "--no-debug"
25+
Cpu: 128
26+
MemoryReservation: 256
27+
HealthCheck:
28+
Command:
29+
# ^^^^^^^ string.unquoted.plain.out.yaml keyword.control.flow.script.pipeline
30+
# ^ punctuation.separator.key-value.yaml
31+
- "CMD-SHELL"
32+
# ^ punctuation.definition.block.sequence.item.yaml
33+
# ^ punctuation.definition.string.begin.yaml
34+
# ^^^^^^^^^ variable.language.aws
35+
# ^ punctuation.definition.string.end.yaml
36+
- "agent health || exit 1"
37+
# ^ meta.block.script.pipeline punctuation.definition.block.sequence.item.yaml
38+
# ^ meta.block.script.pipeline punctuation.definition.string.begin.yaml
39+
# ^^^^^ source.shell.bash.embedded meta.function-call.identifier.shell variable.function.shell
40+
# ^^^^^^ source.shell.bash.embedded meta.function-call.arguments.shell
41+
# ^^ source.shell.bash.embedded keyword.operator.logical.shell
42+
# ^^^^ source.shell.bash.embedded keyword.control.flow.exit.shell
43+
# ^ source.shell.bash.embedded meta.number.integer.decimal.shell constant.numeric.value.shell
44+
# ^ source.shell.bash.embedded punctuation.definition.string.end.yaml
45+
Timeout: 5
46+
# ^^^^^^^ meta.mapping.key.yaml meta.string.yaml string.unquoted.plain.out.yaml - source.shell
47+
# ^ meta.mapping.yaml punctuation.separator.key-value.mapping.yaml
48+
Interval: 30
49+
StartPeriod: 15
50+
Retries: 3

0 commit comments

Comments
 (0)