Skip to content

Commit 9c58554

Browse files
rchldeathaxe
andauthored
Add initial syntax (#1)
This commit adds initial syntax, tests and installation instructions. --- Co-authored-by: deathaxe <[email protected]>
1 parent 8c42bd1 commit 9c58554

11 files changed

Lines changed: 388 additions & 0 deletions

.gitattributes

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# git
2+
.github/ export-ignore
3+
.git export-ignore
4+
.gitattributes export-ignore
5+
.gitignore export-ignore
6+
# development
7+
tests/ export-ignore
8+
*.cmd export-ignore
9+
# other
10+
preview.* export-ignore
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
name: CI Syntax Tests
2+
3+
on:
4+
push:
5+
branches:
6+
- 'main'
7+
tags-ignore:
8+
- '**'
9+
paths:
10+
- '.github/workflows/ci-syntax-tests.yml'
11+
- '**.sublime-syntax'
12+
- '**/syntax_test_*'
13+
- '**.tmPreferences'
14+
pull_request:
15+
branches:
16+
- '**'
17+
paths:
18+
- '.github/workflows/ci-syntax-tests.yml'
19+
- '**.sublime-syntax'
20+
- '**/syntax_test_*'
21+
- '**.tmPreferences'
22+
workflow_dispatch:
23+
24+
jobs:
25+
syntax_tests:
26+
name: Sublime Text ${{ matrix.build }}
27+
runs-on: ubuntu-latest
28+
timeout-minutes: 15 # default is 6 hours!
29+
strategy:
30+
matrix:
31+
include:
32+
- build: 4143
33+
default_packages: v4143
34+
- build: 4180
35+
default_packages: v4180
36+
- build: 4200
37+
default_packages: v4200
38+
- build: latest
39+
default_packages: master
40+
steps:
41+
- name: Checkout Default Packages
42+
uses: actions/checkout@v6
43+
with:
44+
repository: sublimehq/Packages
45+
ref: ${{ matrix.default_packages }}
46+
path: st_syntax_tests/Data/Packages
47+
48+
- name: Delete default package tests
49+
run: |
50+
find st_syntax_tests/Data/Packages/*/ -type f -name 'syntax_test*' -exec rm -v '{}' \;
51+
52+
- name: Checkout ESPHome
53+
uses: actions/checkout@v6
54+
with:
55+
path: st_syntax_tests/Data/Packages/ESPHome
56+
57+
- name: Run Syntax Tests for Sublime Text ${{ matrix.build }}
58+
run: |
59+
if [[ "${{ matrix.build }}" == "latest" ]]; then
60+
wget -O st_syntax_tests.tar.xz https://download.sublimetext.com/latest/dev/linux/x64/syntax_tests
61+
else
62+
wget -O st_syntax_tests.tar.xz https://download.sublimetext.com/st_syntax_tests_build_${{ matrix.build }}_x64.tar.xz
63+
fi
64+
tar xf st_syntax_tests.tar.xz
65+
cd st_syntax_tests
66+
./syntax_tests

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.DS_Store

.python-version

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
3.8

README.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# <img src="https://avatars.githubusercontent.com/u/45919759" height="32pt"> ESPHome
2+
3+
[ESPHome YAML configuration file](https://esphome.io/guides/yaml/) syntax for [Sublime Text](https://www.sublimetext.com) based on its YAML syntax.
4+
5+
![preview](preview.png)
6+
7+
## Installation
8+
9+
### Package Control
10+
11+
The easiest way to install is using [Package Control](https://packagecontrol.io). It's listed as `ESPHome`.
12+
13+
1. Open `Command Palette` using <kbd>ctrl+shift+P</kbd> or menu item `Tools → Command Palette...`
14+
2. Choose `Package Control: Install Package`
15+
3. Find `ESPHome` and hit <kbd>Enter</kbd>
16+
17+
### Manual Install
18+
19+
1. Download appropriate [ESPHome.sublime-package](https://github.com/SublimeText/ESPHome/releases) for your Sublime Text build.
20+
2. Copy it into _Installed Packages_ directory
21+
22+
> [!NOTE]
23+
>
24+
> To find _Installed Packages_...
25+
>
26+
> 1. call _Menu > Preferences > Browse Packages.._
27+
> 2. Navigate to parent folder
28+
29+
> [!WARNING]
30+
>
31+
> Manually installed packages are not automatically updated by Package Control.
32+
33+
## Usage
34+
35+
To apply the syntax, select `YAML (esphome)` from the Command Palette or from the syntax selector in the status bar.
36+
37+
Since ESPHome configuration files use the `.yml`/`.yaml` extension and do not differ much from standard YAML files, there is no easy way to automatically assign it to all ESPHome configuration files (unless you want to use this syntax for all YAML files, which could introduce its own problems). Therefore, it is recommended to use the [ApplySyntax](https://packages.sublimetext.io/packages/ApplySyntax) or [AutoSetSyntax](https://packages.sublimetext.io/packages/AutoSetSyntax) package to assign this syntax based on the file path - most likely on a per-project basis since there is nothing inherently unique about the file names or paths of these configuration files.

YAML (esphome).sublime-settings

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
// YAML mandates that tabs aren't used for indentation
3+
"translate_tabs_to_spaces": true,
4+
5+
// In practice, editing YAML files with anything other than two space
6+
// indentation is tedious, due to the "- " list prefix
7+
"tab_size": 2,
8+
}

YAML (esphome).sublime-syntax

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
%YAML 1.2
2+
# Extends built-in YAML syntax with support for embedded c++ blocks.
3+
# The blocks can either be specified using a "lambda" key or "!lambda" tag.
4+
# See https://esphome.io/guides/yaml/ and https://esphome.io/automations/templates/#config-lambda
5+
# for more details.
6+
#
7+
# Notes:
8+
# - Single and double-quoted "lambda" keys are not supported.
9+
---
10+
# http://www.sublimetext.com/docs/syntax.html
11+
name: YAML (esphome)
12+
scope: source.yaml.esphome
13+
version: 2
14+
15+
extends: Packages/YAML/YAML.sublime-syntax
16+
17+
contexts:
18+
block-pair:
19+
- meta_prepend: true
20+
- match: (lambda)\s*(:)(?=\s+|$)
21+
captures:
22+
1: meta.mapping.key.yaml meta.string.yaml string.unquoted.plain.out.yaml
23+
2: meta.mapping.yaml punctuation.separator.key-value.mapping.yaml
24+
push: lambda-body
25+
26+
property-body:
27+
- meta_prepend: true
28+
- match: (?=!lambda\b)
29+
set: lambda-body
30+
31+
lambda-body:
32+
- meta_include_prototype: false
33+
- match: \!lambda\b
34+
scope: meta.property.yaml keyword.control.directive.tag.yaml
35+
- match: (?:(\|)|(>))(?:([1-9])([-+])|([-+])?([1-9])?) # c-b-block-header(m,t)
36+
captures:
37+
1: keyword.control.flow.block-scalar.literal.yaml
38+
2: keyword.control.flow.block-scalar.folded.yaml
39+
3: constant.numeric.indentation-indicator.yaml
40+
4: storage.modifier.chomping-indicator.yaml
41+
5: storage.modifier.chomping-indicator.yaml
42+
6: constant.numeric.indentation-indicator.yaml
43+
set: lambda-block-scalar-body
44+
- match: \"
45+
scope: meta.string.yaml string.quoted.double.yaml punctuation.definition.string.begin.yaml
46+
pop: 1
47+
embed: scope:source.c++#statements
48+
embed_scope: meta.string.yaml source.c++.embedded.yaml
49+
escape: \"
50+
escape_captures:
51+
0: meta.string.yaml string.quoted.double.yaml punctuation.definition.string.end.yaml
52+
- match: \'
53+
scope: meta.string.yaml string.quoted.single.yaml punctuation.definition.string.begin.yaml
54+
pop: 1
55+
embed: scope:source.c++#statements
56+
embed_scope: meta.string.yaml source.c++.embedded.yaml
57+
escape: \'
58+
escape_captures:
59+
0: meta.string.yaml string.quoted.single.yaml punctuation.definition.string.end.yaml
60+
- match: (?=\S)
61+
pop: 1
62+
embed: scope:source.c++#statements
63+
embed_scope: meta.string.yaml source.c++.embedded.yaml
64+
escape: $
65+
- match: $
66+
pop: 1
67+
68+
lambda-block-scalar-body:
69+
- meta_include_prototype: false
70+
- match: ^([ ]+)(?! )
71+
pop: 1
72+
embed: scope:source.c++#statements
73+
embed_scope: meta.string.yaml source.c++.embedded.yaml
74+
escape: ^(?!\1|\s*$)
75+
- match: ^(?=\S) # the block is empty
76+
pop: 1
77+
- match: .+
78+
scope: invalid.illegal.expected-comment-or-newline.yaml

make.cmd

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
@echo off
2+
setlocal
3+
chcp 65001 >nul
4+
pushd %~dp0
5+
6+
if /i "%1" == "release" goto RELEASE
7+
goto :usage
8+
9+
:RELEASE
10+
if "%2"== "" goto :usage
11+
12+
for %%d in ("%~dp0.") do set package=%%~nxd
13+
14+
echo Createing assets for "%package%"...
15+
16+
set build=4143
17+
set archive=%package%.sublime-package
18+
call git archive --format zip -o "%archive%" main
19+
20+
:: create the release
21+
gh release create --target main -t "v%2" "%build%-%2" *.sublime-package
22+
del /f /q *.sublime-package
23+
git fetch
24+
goto :eof
25+
26+
:USAGE
27+
echo USAGE:
28+
echo.
29+
echo make ^[release^]
30+
echo.
31+
echo release ^<semver^> -- create and publish a release (e.g. 1.2.3)
32+
goto :eof

preview.png

54.2 KB
Loading

preview.yaml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
esphome:
2+
name: tinypico-plant-2
3+
friendly_name: tinypico-plant-2
4+
5+
esp32:
6+
board: tinypico
7+
8+
sensor:
9+
# derive battery percentage 3300mV=0%, 3950mV=100%
10+
- platform: template
11+
lambda: |-
12+
float x = id(vbatt).state;
13+
if (x < 3300) {
14+
x = 3300;
15+
}
16+
if (x > 3950) {
17+
x = 3950;
18+
}
19+
float y = (x - 3300) / 650 * 100;
20+
return y;
21+
name: "Battery Percentage"
22+
id: "pbatt"
23+
update_interval: never
24+
unit_of_measurement: "%"
25+
device_class: "battery"
26+
state_class: "measurement"
27+
icon: "mdi:battery"
28+
accuracy_decimals: 0

0 commit comments

Comments
 (0)