-
Notifications
You must be signed in to change notification settings - Fork 0
Add initial syntax #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Changes from 1 commit
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
9b41d7c
Add initial syntax
rchl beb5128
change scope to source.yaml.esphome and remove unneeded files
rchl 75afdae
Use meta_prepend
rchl 2ba4ab0
Use meta_prepend
rchl 8ce1a77
Look for word boundary instead of whitespace
rchl 7db986b
inline lambda-block-scalar-body instead of include
rchl 7972774
separate $ match
rchl cd0a2a6
avoid backreferences
rchl 5b34c99
update readme
rchl 8b40cc4
grammar
rchl baf5347
no need for markers anymore
rchl 3199591
Update .gitattributes
rchl 5816fa2
Add meta.string.yaml consistently in embed
rchl d17d364
extend test with meta.string.yaml check
rchl 6aa5f62
embed c++ statements only
rchl 900448a
add installation information
deathaxe cff50de
add release script and adjust CI
deathaxe 6b87a28
extend syntax tests
deathaxe File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| tests/ export-ignore | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| name: CI Syntax Tests | ||
|
|
||
| on: | ||
| push: | ||
| branches: | ||
| - 'main' | ||
| tags-ignore: | ||
| - '**' | ||
| paths: | ||
| - '.github/workflows/ci-syntax-tests.yml' | ||
| - '**.sublime-syntax' | ||
| - '**/syntax_test_*' | ||
| - '**.tmPreferences' | ||
| pull_request: | ||
| branches: | ||
| - '**' | ||
| paths: | ||
| - '.github/workflows/ci-syntax-tests.yml' | ||
| - '**.sublime-syntax' | ||
| - '**/syntax_test_*' | ||
| - '**.tmPreferences' | ||
| workflow_dispatch: | ||
|
|
||
| jobs: | ||
| syntax_tests: | ||
| name: Sublime Text ${{ matrix.build }} | ||
| runs-on: ubuntu-latest | ||
| timeout-minutes: 15 # default is 6 hours! | ||
| strategy: | ||
| matrix: | ||
| include: | ||
| - build: 4180 | ||
| default_packages: v4180 | ||
| - build: 4200 | ||
| default_packages: v4200 | ||
| - build: latest | ||
| default_packages: master | ||
| steps: | ||
| - name: Checkout Default Packages | ||
| uses: actions/checkout@v4 | ||
| with: | ||
| repository: sublimehq/Packages | ||
| ref: ${{ matrix.default_packages }} | ||
| path: st_syntax_tests/Data/Packages | ||
|
|
||
| - name: Delete default package tests | ||
| run: | | ||
| find st_syntax_tests/Data/Packages/*/ -type f -name 'syntax_test*' -exec rm -v '{}' \; | ||
|
|
||
| - name: Checkout ESPHome | ||
| uses: actions/checkout@v4 | ||
| with: | ||
| path: st_syntax_tests/Data/Packages/ESPHome | ||
|
|
||
| - name: Run Syntax Tests for Sublime Text ${{ matrix.build }} | ||
| run: | | ||
| if [[ "${{ matrix.build }}" == "latest" ]]; then | ||
| wget -O st_syntax_tests.tar.xz https://download.sublimetext.com/latest/dev/linux/x64/syntax_tests | ||
| else | ||
| wget -O st_syntax_tests.tar.xz https://download.sublimetext.com/st_syntax_tests_build_${{ matrix.build }}_x64.tar.xz | ||
| fi | ||
| tar xf st_syntax_tests.tar.xz | ||
| cd st_syntax_tests | ||
| ./syntax_tests |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| 3.8 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| # ESPHome | ||
|
|
||
| ESPHome YAML configuration file syntax. | ||
|
|
||
| See [ESPHome YAML configuration documentation](https://esphome.io/guides/yaml/). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <plist version="1.0"> | ||
| <dict> | ||
| <key>scope</key> | ||
| <string>source.yaml-esphome</string> | ||
|
rchl marked this conversation as resolved.
Outdated
|
||
| <key>settings</key> | ||
| <dict> | ||
| <key>shellVariables</key> | ||
| <array> | ||
| <dict> | ||
| <key>name</key> | ||
| <string>TM_COMMENT_START</string> | ||
| <key>value</key> | ||
| <string># </string> | ||
| </dict> | ||
| </array> | ||
| </dict> | ||
| </dict> | ||
| </plist> | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <plist version="1.0"> | ||
| <dict> | ||
| <key>scope</key> | ||
| <string>source.yaml-esphome - string - comment</string> | ||
| <key>settings</key> | ||
| <dict> | ||
| <key>increaseIndentPattern</key> | ||
| <string>^.*[:\[{]\s*$</string> | ||
| <key>decreaseIndentPattern</key> | ||
| <string>^\s*[\]}]</string> | ||
| </dict> | ||
| </dict> | ||
| </plist> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| { | ||
| // YAML mandates that tabs aren't used for indentation | ||
| "translate_tabs_to_spaces": true, | ||
|
|
||
| // In practice, editing YAML files with anything other than two space | ||
| // indentation is tedious, due to the "- " list prefix | ||
| "tab_size": 2, | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,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 | ||
|
rchl marked this conversation as resolved.
Outdated
|
||
|
|
||
| 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 | ||
|
rchl marked this conversation as resolved.
Outdated
|
||
|
|
||
| # --- yaml-esphome begin --- | ||
| lambda-body: | ||
| - meta_include_prototype: false | ||
| - match: (!lambda)\s* | ||
| captures: | ||
| 1: meta.property.yaml keyword.control.directive.tag.yaml | ||
|
rchl marked this conversation as resolved.
Outdated
|
||
| - include: block-scalar-lambda | ||
|
deathaxe marked this conversation as resolved.
Outdated
|
||
| - match: (["']) | ||
| pop: 1 | ||
| embed: scope:source.c++ | ||
| embed_scope: source.c++.embedded.yaml | ||
| escape: \1 | ||
|
rchl marked this conversation as resolved.
Outdated
|
||
| - match: (?=[^\s]|$) | ||
| pop: 1 | ||
| embed: scope:source.c++ | ||
| embed_scope: source.c++.embedded.yaml | ||
| escape: $ | ||
|
rchl marked this conversation as resolved.
Outdated
|
||
|
|
||
| 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 | ||
|
deathaxe marked this conversation as resolved.
Outdated
|
||
|
|
||
| block-scalar-body-lambda: | ||
|
deathaxe marked this conversation as resolved.
Outdated
|
||
| - meta_include_prototype: false | ||
| - match: ^([ ]+)(?! ) | ||
| pop: 1 | ||
| embed: scope:source.c++ | ||
| embed_scope: source.c++.embedded.yaml | ||
|
rchl marked this conversation as resolved.
Outdated
|
||
| escape: ^(?!\1|\s*$) | ||
| - match: ^(?=\S) # the block is empty | ||
| pop: 1 | ||
| - match: .+ | ||
| scope: invalid.illegal.expected-comment-or-newline.yaml | ||
| # --- yaml-esphome end --- | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,102 @@ | ||
| # SYNTAX TEST "Packages/ESPHome/YAML (esphome).sublime-syntax" | ||
| # <- source.yaml-esphome comment | ||
|
|
||
|
|
||
| ## Lambda mappings | ||
|
|
||
| lambda: return id(uri) == ""; | ||
| # <- meta.mapping.key meta.string string.unquoted.plain.out | ||
| #^^^^^ meta.mapping.key meta.string string.unquoted.plain.out | ||
| # ^ - source.c++ | ||
| # ^^^^^^^^^^^^^^^^^^^^^ source.c++ | ||
|
|
||
| lambda: 'return id(uri) == "";' | ||
| # <- meta.mapping.key meta.string string.unquoted.plain.out | ||
| #^^^^^ meta.mapping.key meta.string string.unquoted.plain.out | ||
| # ^^ - source.c++ | ||
| # ^^^^^^^^^^^^^^^^^^^^^ source.c++ | ||
| # ^ - source.c++ | ||
|
|
||
| lambda: "return id(uri);" | ||
| # <- meta.mapping.key meta.string string.unquoted.plain.out | ||
| #^^^^^ meta.mapping.key meta.string string.unquoted.plain.out | ||
| # ^^ - source.c++ | ||
| # ^^^^^^^^^^^^^^^ source.c++ | ||
| # ^ - source.c++ | ||
|
|
||
| lambda: |- | ||
| # ^ keyword.control.flow.block-scalar.literal | ||
| # ^ storage.modifier.chomping-indicator | ||
| return id(uri); | ||
| #^^^^^^^^^^^^^^ source.c++ | ||
| foo: 1 | ||
| # <- - source.c++ | ||
|
|
||
|
|
||
| ## Lambda tags | ||
|
|
||
| foo: !lambda return id(uri) | ||
| # ^^^^^^^ meta.property keyword.control.directive.tag | ||
| # ^^^^^^^^^^^^^^ source.c++ | ||
|
|
||
| foo: !lambda 'return id(uri)' | ||
| # ^^^^^^^ meta.property keyword.control.directive.tag | ||
| # ^ - source.c++ | ||
| # ^^^^^^^^^^^^^^ source.c++ | ||
| # ^ - source.c++ | ||
|
|
||
| foo: !lambda "return id(uri)" | ||
| # ^^^^^^^ meta.property keyword.control.directive.tag | ||
| # ^ - source.c++ | ||
| # ^^^^^^^^^^^^^^ source.c++ | ||
| # ^ - source.c++ | ||
|
|
||
| foo: !lambda |- | ||
| # ^^^^^^^ meta.property keyword.control.directive.tag | ||
| # ^ keyword.control.flow.block-scalar.literal | ||
| # ^ storage.modifier.chomping-indicator | ||
| const id = id(uri); | ||
| #^^^^^^^^^^^^^^^^^^^ source.c++ | ||
| return id; | ||
| #^^^^^^^^^^ source.c++ | ||
| foo: 1 | ||
| # <- - source.c++ | ||
|
|
||
|
|
||
| ## Lambda key with lambda tag | ||
|
|
||
| lambda: !lambda return id(uri); | ||
| # ^^^^^^^ meta.property keyword.control.directive.tag | ||
| # ^^^^^^^^^^^^^^^ source.c++ | ||
|
|
||
| lambda: !lambda "return id(uri);" | ||
| # ^^^^^^^ meta.property keyword.control.directive.tag | ||
| # ^ - source.c++ | ||
| # ^^^^^^^^^^^^^^^ source.c++ | ||
| # ^ - source.c++ | ||
|
|
||
| lambda: !lambda 'return id(uri);' | ||
| # ^^^^^^^ meta.property keyword.control.directive.tag | ||
| # ^ - source.c++ | ||
| # ^^^^^^^^^^^^^^^ source.c++ | ||
| # ^ - source.c++ | ||
|
|
||
| lambda: !lambda |- | ||
| # ^^^^^^^ meta.property keyword.control.directive.tag | ||
| # ^ keyword.control.flow.block-scalar.literal | ||
| # ^ storage.modifier.chomping-indicator | ||
| return id(uri); | ||
| #^^^^^^^^^^^^^^^ source.c++ | ||
| foo: 1 | ||
| # <- - source.c++ | ||
|
|
||
|
|
||
| ## Unterminated | ||
|
|
||
| lambda: | ||
| foo: 1 | ||
| # <- - source.c++ | ||
|
|
||
| foo: !lambda | ||
| foo: 1 | ||
| # <- - source.c++ |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.