-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathYAML (esphome).sublime-syntax
More file actions
107 lines (97 loc) · 3.41 KB
/
Copy pathYAML (esphome).sublime-syntax
File metadata and controls
107 lines (97 loc) · 3.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
%YAML 1.2
# Extends built-in YAML syntax with support for embedded c++ blocks.
# The blocks can either be specified using a "lambda" key or "!lambda" tag.
# See https://esphome.io/guides/yaml/ and https://esphome.io/automations/templates/#config-lambda
# for more details.
#
# Notes:
# - Single and double-quoted "lambda" keys are not supported.
# - Code between "yaml-esphome begin" and "yaml-esphome end" tags are additions
# relative to the orignal YAML syntax. The rest of the code is copied from
# YAML syntax.
---
# http://www.sublimetext.com/docs/syntax.html
name: YAML (esphome)
scope: source.yaml-esphome
version: 2
extends: Packages/YAML/YAML.sublime-syntax
contexts:
block-pair:
- match: ( *)(\?)(?=\s)
captures:
2: meta.mapping.yaml punctuation.definition.key-value.begin.yaml
push: block-key-explicit
# --- yaml-esphome begin ---
- match: (lambda)\s*(:)(?=\s+|$)
captures:
1: meta.mapping.key.yaml meta.string.yaml string.unquoted.plain.out.yaml
2: meta.mapping.yaml punctuation.separator.key-value.mapping.yaml
push: lambda-body
# --- yaml-esphome end ---
# Attempt to match plain-out scalars and highlight as "meta.mapping.key",
# if followed by a colon
- match: '{{_flow_key_out_lookahead}}'
push: block-key-implicit
- match: :(?=\s)
scope: meta.mapping.yaml punctuation.separator.key-value.mapping.yaml
property-body:
- meta_scope: meta.property.yaml
# --- yaml-esphome begin ---
- match: (?=!lambda)\s*
set: lambda-body
# --- yaml-esphome end ---
# &Anchor
# http://yaml.org/spec/1.2/spec.html#&%20anchor//
- match: (&)({{ns_anchor_name}})(\S+)?
captures:
1: keyword.control.property.anchor.yaml punctuation.definition.anchor.yaml
2: entity.name.other.anchor.yaml
3: invalid.illegal.character.anchor.yaml
pop: 1
# !Tag Handle
# http://yaml.org/spec/1.2/spec.html#tag/property/
- match: '{{c_ns_tag_property}}(?=\ |\t|$)'
scope: storage.type.tag-handle.yaml
pop: 1
- match: \S+
scope: invalid.illegal.tag-handle.yaml
pop: 1
# --- yaml-esphome begin ---
lambda-body:
- meta_include_prototype: false
- match: (!lambda)\s*
captures:
1: meta.property.yaml keyword.control.directive.tag.yaml
- include: block-scalar-lambda
- match: (["'])
pop: 1
embed: scope:source.c++
embed_scope: source.c++.embedded.yaml
escape: \1
- match: (?=[^\s]|$)
pop: 1
embed: scope:source.c++
embed_scope: source.c++.embedded.yaml
escape: $
block-scalar-lambda:
- 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: block-scalar-body-lambda
block-scalar-body-lambda:
- meta_include_prototype: false
- match: ^([ ]+)(?! )
pop: 1
embed: scope:source.c++
embed_scope: source.c++.embedded.yaml
escape: ^(?!\1|\s*$)
- match: ^(?=\S) # the block is empty
pop: 1
- match: .+
scope: invalid.illegal.expected-comment-or-newline.yaml
# --- yaml-esphome end ---