Add ansible syntax highlighting

This commit is contained in:
Anton Novojilov 2022-12-04 16:20:01 +03:00
commit e8ab9ee331
5 changed files with 102 additions and 11 deletions

View file

@ -416,17 +416,29 @@
"font_style": ""
},
{
"name": "Ansible Keyword",
"scope": "keyword.other.ansible",
"name": "Ansible Task Name",
"scope": "keyword.other.ansible.task.name",
"foreground": "var(function)",
"font_style": ""
},
{
"name": "Ansible Title",
"scope": "string.quoted.double.ansible",
"foreground": "var(string)",
"name": "Ansible Task Description",
"scope": "keyword.other.ansible.task.desc",
"foreground": "#65B0D8",
"font_style": "bold"
},
{
"name": "Ansible Block",
"scope": "keyword.other.ansible.block",
"foreground": "var(function)",
"font_style": "italic"
},
{
"name": "Ansible Action Name",
"scope": "keyword.other.ansible.action.name",
"foreground": "#B7AE89",
"font_style": ""
},
{
"scope": "entity.name.filename",
"foreground": "#DBC33F"

View file

@ -38,6 +38,7 @@ cd "$(bat --config-dir)/syntaxes"
curl -OL# -o "bibop-recipe.sublime-syntax" https://kaos.sh/blackhole-theme-sublime/bibop-recipe.sublime-syntax
curl -OL# -o "knf.sublime-syntax" https://kaos.sh/blackhole-theme-sublime/knf.sublime-syntax
curl -OL# -o "rpm-spec.sublime-syntax" https://kaos.sh/blackhole-theme-sublime/rpm-spec.sublime-syntax
curl -OL# -o "ansible.sublime-syntax" https://kaos.sh/blackhole-theme-sublime/ansible.sublime-syntax
bat cache --build
```

82
ansible.sublime-syntax Normal file
View file

@ -0,0 +1,82 @@
%YAML 1.2
---
# https://www.sublimetext.com/docs/syntax.html
name: Ansible
file_extensions:
- yml
- yaml
scope: source.ansible
contexts:
main:
- include: comments
- include: keywords
- include: jinja
- include: strings
- include: tasks
- include: conditionals
comments:
- match: ^[\t ]*#
scope: punctuation.definition.comment
push:
- meta_scope: comment.line
- include: pop-on-line-end
- match: ^[\-]{3}
scope: comment.line
keywords:
- match: \b(true|false)\b
scope: constant.language.boolean.yaml
- match: '\b([0-9]+\.[0-9]*|\.[0-9]+)([eE][+-]?\d+)?\b'
scope: constant.numeric.float
- match: '\b\d+\b'
scope: constant.numeric.integer
tasks:
- match: (\-) (name)(:)\ +(.*)
scope: keyword.other.ansible.task
captures:
1: punctuation.separator
2: keyword.other.ansible.task.name
3: keyword.operator.assignment
4: keyword.other.ansible.task.desc
- match: '[ ]{2,}block(:)'
scope: keyword.other.ansible.block
captures:
1: keyword.operator.assignment
- match: '[ ]{2,}([\w\d]+)(:)'
scope: keyword.other.ansible.action
captures:
1: keyword.other.ansible.action.name
2: keyword.operator.assignment
conditionals:
- match: \b(is|or|and|(or )?not|if|else|(((un)?defined)))\b
scope: constant.character
strings:
- match: '"'
scope: punctuation.definition.string.begin
push:
- meta_scope: string.quoted.double
- match: '"'
scope: punctuation.definition.string.end
pop: true
- include: jinja-variable
- match: "'"
scope: punctuation.definition.string.begin
push:
- meta_scope: string.quoted.single
- match: "'"
scope: punctuation.definition.string.end
pop: true
- include: jinja-variable
jinja-variable:
- match: (\{\{ *[^\{\}]+ *\}\})|(\$\{[^\{\}]+\})
scope: storage.type.ansible
pop-on-line-end:
- match: $
pop: true

View file

@ -1,6 +1,6 @@
%YAML 1.2
---
# http://www.sublimetext.com/docs/3/syntax.html
# https://www.sublimetext.com/docs/syntax.html
name: Bibop Recipe
file_extensions:
- recipe

View file

@ -1,6 +1,6 @@
%YAML 1.2
---
# http://www.sublimetext.com/docs/3/syntax.html
# https://www.sublimetext.com/docs/syntax.html
name: KNF
file_extensions:
- knf
@ -34,8 +34,6 @@ contexts:
- match: '"'
scope: punctuation.definition.string.end.knf
pop: true
- include: string-placeholder
- include: string-escaped-char
- match: "'"
scope: punctuation.definition.string.begin.knf
push:
@ -43,8 +41,6 @@ contexts:
- match: "'"
scope: punctuation.definition.string.end.knf
pop: true
- include: string-placeholder
- include: string-escaped-char
macroses:
- match: \{([A-Za-z0-9_-]{1,}):([A-Za-z0-9_-]{1,})\}