Skip to content
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

[YAML] Replace entity.name.tag with meta.mapping.key #2564

Merged
merged 15 commits into from
Feb 28, 2022
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions PHP/tests/syntax_test_php.php
Original file line number Diff line number Diff line change
Expand Up @@ -1935,12 +1935,12 @@ function generate2()
// ^^^ entity.name.tag.heredoc
one: two
//^^^^^^ meta.embedded.yaml source.yaml
//^ string.unquoted.plain.out entity.name.tag
//^ meta.mapping.key string
keith-hall marked this conversation as resolved.
Show resolved Hide resolved
// ^ punctuation.separator.key-value.mapping
// ^^^ string.unquoted.plain.out
// ^^^ string
three: "$four"
//^^^^^^^^^^^^ meta.embedded.yaml source.yaml
//^^^ string.unquoted.plain.out entity.name.tag
//^^^ meta.mapping.key string
// ^ punctuation.separator.key-value.mapping
deathaxe marked this conversation as resolved.
Show resolved Hide resolved
// ^^^^^^^ string.quoted.double
// ^^^^^ variable.other.php
Expand Down
227 changes: 144 additions & 83 deletions YAML/YAML.sublime-syntax
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
---
name: YAML
scope: source.yaml
version: 2

file_extensions:
- yaml
Expand Down Expand Up @@ -110,12 +111,40 @@ variables:
)
)

_flow_key_in_lookahead: |-
(?x:
(?=
{{ns_plain_first_plain_in}}
( [^\s:{{c_flow_indicator}}]
| : [^\s{{c_flow_indicator}}]
| \s+ (?![#\s])
)*
\s*
:
(\s|$)
)
)

_flow_key_out_lookahead: |-
(?x:
(?=
{{ns_plain_first_plain_out}}
( [^\s:]
| : \S
| \s+ (?![#\s])
)*
\s*
:
(\s|$)
)
)

# patterns for plain scalars of implicit different types
# (for the Core Schema: http://www.yaml.org/spec/1.2/spec.html#schema/core/)

# http://yaml.org/type/null.html
_type_null: (?:null|Null|NULL|~)

# http://yaml.org/type/bool.html
_type_bool_11: |-
(?x:
Expand Down Expand Up @@ -266,23 +295,23 @@ contexts:
# http://yaml.org/spec/1.2/spec.html#node/property/
- match: (?=!|&)
push:
- meta_scope: meta.property.yaml
# &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: true
# !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: true
- match: \S+
scope: invalid.illegal.tag-handle.yaml
pop: true
- meta_scope: meta.property.yaml
# &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: true
# !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: true
- match: \S+
scope: invalid.illegal.tag-handle.yaml
pop: true

flow-alias:
# http://yaml.org/spec/1.2/spec.html#alias//
Expand Down Expand Up @@ -506,80 +535,121 @@ contexts:
- match: '{{_flow_scalar_end_plain_in}}'
pop: true

flow-scalar-plain-in-12:
# http://yaml.org/spec/1.2/spec.html#style/flow/plain
# ns-plain(n,c) (c=flow-in, c=flow-key)
- include: flow-scalar-plain-in-implicit-type-12
- match: (?={{ns_plain_first_plain_in}})
push:
- meta_scope: string.unquoted.plain.in.yaml
- meta_include_prototype: false
- match: '{{_flow_scalar_end_plain_in}}'
pop: true

flow-sequence:
# http://yaml.org/spec/1.2/spec.html#style/flow/sequence
# c-flow-sequence(n,c)
- match: \[
scope: punctuation.definition.sequence.begin.yaml
push:
- meta_scope: meta.flow-sequence.yaml
- meta_scope: meta.sequence.flow.yaml
- match: \]
scope: punctuation.definition.sequence.end.yaml
pop: true
- match: ','
scope: punctuation.separator.sequence.yaml
- include: flow-pair
- include: flow-pair-no-clear
- include: flow-node

flow-mapping:
- match: \{
scope: punctuation.definition.mapping.begin.yaml
push:
- meta_scope: meta.flow-mapping.yaml
- meta_scope: meta.mapping.yaml
- match: \}
scope: punctuation.definition.mapping.end.yaml
pop: true
- match: ','
scope: punctuation.separator.mapping.yaml
- include: flow-pair
- include: flow-node # for sets

flow-pair:
- match: \?
scope: punctuation.definition.key-value.begin.yaml
scope: meta.mapping.key.yaml punctuation.definition.key.begin.yaml
push:
- meta_scope: meta.flow-pair.explicit.yaml
- match: (?=[},\]]) # Empty mapping keys & values are allowed
pop: true
- include: flow-pair
- include: flow-node
- match: :(?=\s|$|{{c_flow_indicator}})
scope: punctuation.separator.key-value.mapping.yaml
set: flow-pair-value
# Attempt to match plain-in scalars and highlight as "entity.name.tag",
# if followed by a colon
- match: |
(?x)
(?=
{{ns_plain_first_plain_in}}
(
[^\s:{{c_flow_indicator}}]
| : [^\s{{c_flow_indicator}}]
| \s+ (?![#\s])
)*
\s*
:
(\s|$)
)
- flow-pair-value-set
- flow-pair-key
# Attempt to match plain-in scalars followed by a colon
- match: '{{_flow_key_in_lookahead}}'
push:
# TODO Use a merge type here and add "pop: true" and "scope: entity.name.tag.yaml";
# https://github.com/SublimeTextIssues/Core/issues/966
- meta_scope: meta.flow-pair.key.yaml
- include: flow-scalar-plain-in-implicit-type-12
- match: '{{_flow_scalar_end_plain_in}}'
pop: true
- match: (?={{ns_plain_first_plain_in}})
set:
- meta_scope: meta.flow-pair.key.yaml string.unquoted.plain.in.yaml entity.name.tag.yaml
- meta_include_prototype: false
- match: '{{_flow_scalar_end_plain_in}}'
pop: true
- include: flow-node
- flow-pair-value-set
- flow-pair-key-12
- match: :(?=\s|$|{{c_flow_indicator}}) # Empty mapping keys allowed
scope: meta.flow-pair.yaml punctuation.separator.key-value.mapping.yaml
scope: meta.mapping.yaml punctuation.separator.key-value.mapping.yaml
push: flow-pair-value

# Variant without clearing the parent scope for pairs in a sequence
flow-pair-no-clear:
- match: \?
scope: meta.mapping.key.yaml punctuation.definition.key.begin.yaml
push:
- flow-pair-value-set-no-clear
- flow-pair-key-no-clear
- match: '{{_flow_key_in_lookahead}}'
push:
- flow-pair-value-set-no-clear
- flow-pair-key-no-clear
- match: :(?=\s|$|{{c_flow_indicator}})
scope: meta.mapping.yaml punctuation.separator.key-value.mapping.yaml
push: flow-pair-value-no-clear

flow-pair-key:
- clear_scopes: 1
- meta_content_scope: meta.mapping.key.yaml
- match: (?=[},\]]) # Empty mapping keys & values are allowed
pop: true
- match: :(?=\s|$|{{c_flow_indicator}})
scope: meta.mapping.yaml punctuation.separator.key-value.mapping.yaml
pop: true
FichteFoll marked this conversation as resolved.
Show resolved Hide resolved
- include: flow-node

flow-pair-key-12:
- clear_scopes: 1
- meta_content_scope: meta.mapping.key.yaml
- match: (?=[},\]]) # Empty mapping keys & values are allowed
pop: true
- match: :(?=\s|$|{{c_flow_indicator}})
scope: meta.mapping.yaml punctuation.separator.key-value.mapping.yaml
pop: true
- include: flow-scalar-plain-in-12

flow-pair-key-no-clear:
- meta_content_scope: meta.mapping.key.yaml
- match: (?=[},\]])
pop: true
- match: :(?=\s|$|{{c_flow_indicator}})
scope: meta.mapping.yaml punctuation.separator.key-value.mapping.yaml
pop: true
- include: flow-node

flow-pair-value-set:
- match: ''
set: flow-pair-value

flow-pair-value:
- meta_content_scope: meta.flow-pair.value.yaml
- clear_scopes: 1
- meta_content_scope: meta.mapping.value.yaml
- include: flow-node
- match: (?=[},\]])
pop: true

flow-pair-value-set-no-clear:
- match: ''
set: flow-pair-value-no-clear

flow-pair-value-no-clear:
- meta_content_scope: meta.mapping.value.yaml
- include: flow-node
- match: (?=[},\]])
pop: true
Expand Down Expand Up @@ -621,46 +691,37 @@ contexts:

block-pair:
- match: \?
scope: punctuation.definition.key-value.begin.yaml
scope: meta.mapping.yaml punctuation.definition.key-value.begin.yaml
push:
- meta_scope: meta.block-mapping.yaml
- meta_content_scope: meta.mapping.key.yaml
- match: (?=\?) # Empty mapping keys & values are allowed
pop: true
- match: ^ *(:)
scope: meta.mapping.yaml
captures:
1: punctuation.separator.key-value.mapping.yaml
pop: true
- match: ':'
scope: invalid.illegal.expected-newline.yaml
scope: meta.mapping.yaml invalid.illegal.expected-newline.yaml
pop: true
- include: block-node
# Attempt to match plain-out scalars and highlight as "entity.name.tag",
# Attempt to match plain-out scalars and highlight as "meta.mapping.key",
# if followed by a colon
- match: |
(?x)
(?=
{{ns_plain_first_plain_out}}
(
[^\s:]
| : \S
| \s+ (?![#\s])
)*
\s*
:
(\s|$)
)
# TODO rewrite with branching
deathaxe marked this conversation as resolved.
Show resolved Hide resolved
- match: '{{_flow_key_out_lookahead}}'
push:
- meta_scope: meta.mapping.key.yaml
- include: flow-scalar-plain-out-implicit-type-12
- match: '{{_flow_scalar_end_plain_out}}'
pop: true
- match: (?={{ns_plain_first_plain_out}})
set:
- meta_scope: string.unquoted.plain.out.yaml entity.name.tag.yaml
- meta_scope: meta.mapping.key.yaml string.unquoted.plain.out.yaml
- meta_include_prototype: false
- match: '{{_flow_scalar_end_plain_out}}'
pop: true
- match: :(?=\s|$)
scope: punctuation.separator.key-value.mapping.yaml
scope: meta.mapping.yaml punctuation.separator.key-value.mapping.yaml

comment:
# http://www.yaml.org/spec/1.2/spec.html#comment//
Expand All @@ -673,7 +734,7 @@ contexts:
- match: '#'
scope: punctuation.definition.comment.line.number-sign.yaml
set:
- meta_scope: comment.line.number-sign.yaml
- match: \n|\z
pop: true
- meta_scope: comment.line.number-sign.yaml
- match: \n|\z
pop: true
...
Loading