Skip to content

Commit

Permalink
Fix YAML key detection (#25)
Browse files Browse the repository at this point in the history
Ignore interpolation content within {{ .. }} within key detection lookaheads.
  • Loading branch information
deathaxe authored Jul 25, 2024
1 parent 98ad6f6 commit 0efd55a
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 3 deletions.
64 changes: 61 additions & 3 deletions Syntaxes/YAML/YAML (Jinja).sublime-syntax
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,78 @@ file_extensions:

variables:
ns_plain_first_plain_in: |- # c=plain-in
(?x:
{{yaml_ns_plain_first_plain_in}}
| (?:[?:-] )?{{ # begins with interpolation
)
# original value from YAML
yaml_ns_plain_first_plain_in: |- # c=plain-in
(?x:
[^\s{{c_indicator}}]
| [?:-] [^\s{{c_flow_indicator}}]
| (?:[?:-] )?{{ # begins with jinja interpolation
)
ns_plain_first_plain_out: |- # c=plain-out
(?x:
{{yaml_ns_plain_first_plain_out}}
| (?:[?:-] )?{{ # begins with interpolation
)
# original value from YAML
yaml_ns_plain_first_plain_out: |- # c=plain-out
(?x:
[^\s{{c_indicator}}]
| [?:-] \S
| (?:[?:-] )?{{ # begins with jinja interpolation
)
_flow_key_in_lookahead: |-
(?x:
(?=
(
(?:
{{yaml_ns_plain_first_plain_in}}
| {{jinja_interpolation}} # begins with interpolation
)
( [^\s:{{c_flow_indicator}}]
| : [^\s{{c_flow_indicator}}]
| \s+ (?![#\s])
| {{jinja_interpolation}} # ignore interpolation
)*
| \".*\" # simplified
| \'.*\'
)
\s*
:
(?:\s|$)
)
)
_flow_key_out_lookahead: |-
(?x:
(?=
(
(?:
{{yaml_ns_plain_first_plain_out}}
| {{jinja_interpolation}} # begins with interpolation
)
( [^\s:]
| : \S
| \s+ (?![#\s])
| {{jinja_interpolation}} # ignore interpolation
)*
| \".*\" # simplified
| \'.*\'
)
\s*
:
(?:\s|$)
)
)
jinja_interpolation: '{{.*?}}'

contexts:

main:
Expand Down
16 changes: 16 additions & 0 deletions Syntaxes/YAML/syntax_test_scopes.jinja.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,22 @@ my-{{key}}: {{value}}
# ^ meta.mapping.yaml punctuation.separator.key-value.mapping.yaml
# ^^^^^^^^^ meta.string.yaml meta.embedded.expression.jinja

{{ key }}: {{ value }}
# <- meta.mapping.key.yaml meta.string.yaml meta.embedded.expression.jinja punctuation.section.embedded.begin.jinja
#^^^^^^^^ meta.mapping.key.yaml meta.string.yaml meta.embedded.expression.jinja
# ^ meta.mapping.yaml punctuation.separator.key-value.mapping.yaml
# ^^^^^^^^^^^ meta.string.yaml meta.embedded.expression.jinja - meta.mapping.key

{{ key: }}: {{ value: }}
# <- meta.mapping.key.yaml meta.string.yaml meta.embedded.expression.jinja punctuation.section.embedded.begin.jinja
#^^^^^^^^^ meta.mapping.key.yaml meta.string.yaml meta.embedded.expression.jinja
# ^ meta.mapping.yaml punctuation.separator.key-value.mapping.yaml
# ^^^^^^^^^^^^ meta.string.yaml meta.embedded.expression.jinja - meta.mapping.key

{{ no_key: }}
# <- meta.string.yaml meta.embedded.expression.jinja punctuation.section.embedded.begin.jinja
#^^^^^^^^^^^^ meta.string.yaml meta.embedded.expression.jinja - meta.mapping.key

{% if true %}
# <- meta.embedded.statement.jinja punctuation.section.embedded.begin.jinja
#^^^^^^^^^^^^ meta.embedded.statement.jinja
Expand Down

0 comments on commit 0efd55a

Please sign in to comment.