From 90abfa98238bee1d5dab1ffdd38bed76805f7fbe Mon Sep 17 00:00:00 2001 From: FichteFoll Date: Fri, 9 Oct 2020 01:34:54 +0200 Subject: [PATCH 01/15] [YAML] Use meta.mapping scopes for flow mappings --- YAML/YAML.sublime-syntax | 60 +++++++++++------------ YAML/tests/syntax_test_flow.yaml | 84 +++++++++++++++++--------------- 2 files changed, 74 insertions(+), 70 deletions(-) diff --git a/YAML/YAML.sublime-syntax b/YAML/YAML.sublime-syntax index 4adfe72e4f..b8ba9b9e4d 100644 --- a/YAML/YAML.sublime-syntax +++ b/YAML/YAML.sublime-syntax @@ -512,6 +512,7 @@ contexts: - match: \[ scope: punctuation.definition.sequence.begin.yaml push: + # TODO use meta.sequence and adjust to flow-pair's clear_scopes - meta_scope: meta.flow-sequence.yaml - match: \] scope: punctuation.definition.sequence.end.yaml @@ -525,7 +526,7 @@ contexts: - 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 @@ -535,51 +536,48 @@ contexts: flow-pair: - match: \? - scope: punctuation.definition.key-value.begin.yaml + scope: meta.mapping.key.explicit.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: '' + set: flow-pair-value + - - clear_scopes: 1 + - meta_content_scope: meta.mapping.key.explicit.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-node + # Attempt to match plain-in scalars followed by a colon - match: | (?x) (?= {{ns_plain_first_plain_in}} - ( - [^\s:{{c_flow_indicator}}] - | : [^\s{{c_flow_indicator}}] - | \s+ (?![#\s]) + ( [^\s:{{c_flow_indicator}}] + | : [^\s{{c_flow_indicator}}] + | \s+ (?![#\s]) )* \s* : (\s|$) ) 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 + - - clear_scopes: 1 + - meta_scope: meta.mapping.key.yaml + - include: flow-scalar-plain-in-implicit-type-12 + - match: '' + pop: true + - - match: (?=\S) + pop: true - 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 + # TODO match as meta.mapping.key + - include: flow-node 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 diff --git a/YAML/tests/syntax_test_flow.yaml b/YAML/tests/syntax_test_flow.yaml index 7cf372544f..8562fdd03b 100644 --- a/YAML/tests/syntax_test_flow.yaml +++ b/YAML/tests/syntax_test_flow.yaml @@ -95,13 +95,13 @@ continuation" # ^ meta.flow-sequence punctuation.definition.sequence.end [a: b, c,'d', e: f, g:h] -#^ meta.flow-pair.key string.unquoted.plain.in entity.name.tag -# ^ meta.flow-pair punctuation.separator.key-value.mapping -meta.flow-pair.value -# ^ meta.flow-pair.value string.unquoted.plain.in -entity.name.tag +#^ meta.mapping.key string.unquoted.plain.in +# ^ meta.mapping punctuation.separator.key-value.mapping -meta.mapping.value +# ^ meta.mapping.value string.unquoted.plain.in # ^ string.unquoted.plain.in # ^ punctuation.separator.sequence # ^^^ string.quoted.single -# ^ string.unquoted.plain.in entity.name.tag +# ^ meta.mapping.key string.unquoted.plain.in # ^ punctuation.separator.key-value.mapping # ^ punctuation.separator.sequence # ^^^ string.unquoted.plain.in - entity.name.tag @@ -112,47 +112,53 @@ continuation" # http://yaml.org/spec/1.2/spec.html#style/flow/sequence {a: b, :c: :d, -#^ meta.flow-pair.key string.unquoted.plain.in entity.name.tag -# ^ meta.flow-pair punctuation.separator.key-value.mapping -# ^ meta.flow-pair.value string.unquoted.plain.in -entity.name.tag -# ^ punctuation.separator.mapping -# ^^ string.unquoted.plain.in entity.name.tag -# ^ punctuation.separator.key-value.mapping -# ^^ string.unquoted.plain.in, -entity.name.tag +#^^^^^^^^^^^^^^ meta.mapping - meta.mapping meta.mapping +#^ meta.mapping.key.yaml string.unquoted.plain.in.yaml +# ^ meta.mapping.yaml punctuation.separator.key-value.mapping.yaml +# ^ meta.mapping.value string.unquoted.plain.in -entity.name.tag +# ^ meta.mapping.yaml punctuation.separator.mapping +# ^^ meta.mapping.key.yaml string.unquoted.plain.in +# ^ meta.mapping.yaml punctuation.separator.key-value.mapping +# ^^ meta.mapping.value.yaml string.unquoted.plain.in # ^ punctuation.separator.mapping -# <- meta.flow-mapping punctuation.definition.mapping.begin -*alias, e : f } -#^^^^^ variable.other.alias -# ^ punctuation.separator.mapping -# ^ string.unquoted.plain.in entity.name.tag -# ^ -string -# ^ punctuation.separator.key-value.mapping -# ^ string.unquoted.plain.in, -entity.name.tag -# ^ meta.flow-mapping punctuation.definition.mapping.end +# <- meta.mapping.yaml punctuation.definition.mapping.begin +*alias, true : false } +#^^^^^^^^^^^^^^^^^^^^^ meta.mapping - meta.mapping meta.mapping +#^^^^^ variable.other.alias +# ^ punctuation.separator.mapping +# ^^^^ meta.mapping.key.yaml constant.language.boolean.yaml - string +# ^ punctuation.separator.key-value.mapping +# ^^^^^ meta.mapping.value.yaml constant.language.boolean.yaml +# ^ meta.mapping.yaml punctuation.definition.mapping.end + +{ 1: 2 } {? !!str 'key' : !!str value, -#^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.flow-pair.explicit -# ^^^^^^^^^^^^ meta.flow-pair.value -# ^ punctuation.separator.mapping -meta.flow-pair -#^ punctuation.definition.key-value.begin -# ^^^^^ storage -# ^^^^^ string -# ^ punctuation -# ^ punctuation -# ^ punctuation.separator.key-value.mapping -# ^^^^^ storage -# ^^^^^ string +# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.mapping - meta.mapping meta.mapping +# ^^^^^^^^^^^^ meta.mapping.value +# ^ punctuation.separator.mapping - meta.mapping.value +#^ punctuation.definition.key.begin.yaml +#^^^^^^^^^^^^^^ meta.mapping.key.explicit.yaml +# ^^^^^ storage +# ^^^^^ string +# ^ punctuation +# ^ punctuation +# ^ meta.mapping.yaml punctuation.separator.key-value.mapping +# ^^^^^ storage +# ^^^^^ string ? !!str foo : :bar -#^ punctuation.definition.key-value.begin +#^^^^^^^^^^^^ meta.mapping.key.explicit.yaml +#^ punctuation.definition.key.begin.yaml # ^^^^^ storage -# ^^^ string entity.name.tag -# ^ punctuation.separator.key-value.mapping -string -# ^ string.unquoted.plain.in +# ^^^ string.unquoted.plain.in.yaml +# ^ meta.mapping.yaml punctuation.separator.key-value.mapping.yaml +# ^^^^ meta.mapping.value.yaml string.unquoted.plain.in.yaml } +# TODO catch `!!set` and set meta.set scope !!set {this, is, a, set} # ^ storage -# ^ string -entity -# ^ string -entity -# ^ string -entity -# ^ string -entity +# ^ string - meta.mapping.key +# ^ string - meta.mapping.key +# ^ string - meta.mapping.key +# ^ string - meta.mapping.key From 6b0b119e7fc1fd5eb9cac9a4624a1eb3b428c66d Mon Sep 17 00:00:00 2001 From: FichteFoll Date: Sun, 25 Oct 2020 13:41:21 +0100 Subject: [PATCH 02/15] [YAML] Use meta.sequence for sequences --- YAML/YAML.sublime-syntax | 2 +- YAML/tests/syntax_test_flow.yaml | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/YAML/YAML.sublime-syntax b/YAML/YAML.sublime-syntax index b8ba9b9e4d..3f3bddd22a 100644 --- a/YAML/YAML.sublime-syntax +++ b/YAML/YAML.sublime-syntax @@ -513,7 +513,7 @@ contexts: scope: punctuation.definition.sequence.begin.yaml push: # TODO use meta.sequence and adjust to flow-pair's clear_scopes - - meta_scope: meta.flow-sequence.yaml + - meta_scope: meta.sequence.flow.yaml - match: \] scope: punctuation.definition.sequence.end.yaml pop: true diff --git a/YAML/tests/syntax_test_flow.yaml b/YAML/tests/syntax_test_flow.yaml index 8562fdd03b..ed3a98d10c 100644 --- a/YAML/tests/syntax_test_flow.yaml +++ b/YAML/tests/syntax_test_flow.yaml @@ -86,13 +86,13 @@ continuation" # http://yaml.org/spec/1.2/spec.html#style/flow/sequence [a, b, c, -# <- meta.flow-sequence punctuation.definition.sequence.begin +# <- meta.sequence.flow punctuation.definition.sequence.begin #^ string.unquoted.plain.in # ^ punctuation.separator.sequence # ^ punctuation.separator.sequence *alias] #^^^^^ variable.other.alias -# ^ meta.flow-sequence punctuation.definition.sequence.end +# ^ meta.sequence.flow punctuation.definition.sequence.end [a: b, c,'d', e: f, g:h] #^ meta.mapping.key string.unquoted.plain.in From dd5ee5d1a6f4bd7578ec185c7e0f04c631110d44 Mon Sep 17 00:00:00 2001 From: FichteFoll Date: Sun, 25 Oct 2020 13:44:31 +0100 Subject: [PATCH 03/15] [YAML] Work around meta.sequence being cleared in flow-pair This is just a workaround to not have a duplicate context that only differs in `clear_scopes` usage, but one that is simple and works for me. --- YAML/YAML.sublime-syntax | 5 +++-- YAML/tests/syntax_test_flow.yaml | 1 + 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/YAML/YAML.sublime-syntax b/YAML/YAML.sublime-syntax index 3f3bddd22a..571fbcf4d1 100644 --- a/YAML/YAML.sublime-syntax +++ b/YAML/YAML.sublime-syntax @@ -512,8 +512,9 @@ contexts: - match: \[ scope: punctuation.definition.sequence.begin.yaml push: - # TODO use meta.sequence and adjust to flow-pair's clear_scopes - - meta_scope: meta.sequence.flow.yaml + # Pushes an extra 'meta' on the scope stack that flow-pair can then clear, + # so we don't have to duplicate the context + - meta_scope: meta.sequence.flow.yaml meta.workaround.yaml - match: \] scope: punctuation.definition.sequence.end.yaml pop: true diff --git a/YAML/tests/syntax_test_flow.yaml b/YAML/tests/syntax_test_flow.yaml index ed3a98d10c..2fba46e214 100644 --- a/YAML/tests/syntax_test_flow.yaml +++ b/YAML/tests/syntax_test_flow.yaml @@ -95,6 +95,7 @@ continuation" # ^ meta.sequence.flow punctuation.definition.sequence.end [a: b, c,'d', e: f, g:h] +#^^^^^^^^^^^^^^^^^^^^^^^ meta.sequence.flow.yaml #^ meta.mapping.key string.unquoted.plain.in # ^ meta.mapping punctuation.separator.key-value.mapping -meta.mapping.value # ^ meta.mapping.value string.unquoted.plain.in From 538882a1c4a75223d77b0d4b01f1215a61793fea Mon Sep 17 00:00:00 2001 From: FichteFoll Date: Sun, 25 Oct 2020 13:45:41 +0100 Subject: [PATCH 04/15] [YAML] Some whitespace alignments --- YAML/YAML.sublime-syntax | 44 ++++++++++++++++++++-------------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/YAML/YAML.sublime-syntax b/YAML/YAML.sublime-syntax index 571fbcf4d1..043a658eb1 100644 --- a/YAML/YAML.sublime-syntax +++ b/YAML/YAML.sublime-syntax @@ -112,10 +112,10 @@ variables: # 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: @@ -266,23 +266,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// @@ -672,7 +672,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 ... From dfa88bc09a13748c79665dde3ffb949c456bf820 Mon Sep 17 00:00:00 2001 From: FichteFoll Date: Sun, 25 Oct 2020 13:50:12 +0100 Subject: [PATCH 05/15] [YAML] Use meta.mapping.key for explicit block keys --- YAML/YAML.sublime-syntax | 7 ++++--- YAML/tests/syntax_test_block.yaml | 14 +++++++------- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/YAML/YAML.sublime-syntax b/YAML/YAML.sublime-syntax index 043a658eb1..8c88762d1e 100644 --- a/YAML/YAML.sublime-syntax +++ b/YAML/YAML.sublime-syntax @@ -620,17 +620,18 @@ 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", diff --git a/YAML/tests/syntax_test_block.yaml b/YAML/tests/syntax_test_block.yaml index 8d3a3ead83..aca7f7b165 100644 --- a/YAML/tests/syntax_test_block.yaml +++ b/YAML/tests/syntax_test_block.yaml @@ -104,17 +104,17 @@ key on line one: value on line two ? explicit key # Empty value -#^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.block-mapping +#^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.mapping.key # ^^^^^^^^^^^^ string.unquoted.plain.out # ^^^^^^^^^^^^^ comment -# <- meta.block-mapping punctuation.definition.key-value.begin +# <- meta.mapping punctuation.definition.key-value.begin ? | block key -# ^^^^^^^^^ meta.block-mapping string.unquoted.block -# ^^^^^^^^^ -meta.block-mapping meta.block-mapping +# ^^^^^^^^^ meta.mapping string.unquoted.block +# ^^^^^^^^^ -meta.mapping meta.mapping : - one # Explicit compact -# <- meta.block-mapping punctuation.separator.key-value.mapping +# <- meta.mapping punctuation.separator.key-value.mapping - two: :three # block value # ^ punctuation.definition.block.sequence # ^^^ string.unquoted.plain.out entity.name.tag @@ -122,10 +122,10 @@ key on line one: # ^^^^^^ string.unquoted.plain.out ? a key : not a value -# ^ meta.block-mapping invalid.illegal.expected-newline +# ^ meta.mapping invalid.illegal.expected-newline scalar -# <- -meta.block-mapping +# <- -meta.mapping x: - #1 From d656465fbc6f6e44ea2c3388e21016a3924d2c6e Mon Sep 17 00:00:00 2001 From: FichteFoll Date: Sun, 25 Oct 2020 13:58:54 +0100 Subject: [PATCH 06/15] [YAML] Use meta.mapping.key for implicit block keys --- YAML/YAML.sublime-syntax | 26 +++++++++++++++----------- YAML/tests/syntax_test_block.yaml | 12 ++++++------ 2 files changed, 21 insertions(+), 17 deletions(-) diff --git a/YAML/YAML.sublime-syntax b/YAML/YAML.sublime-syntax index 8c88762d1e..f79c838d52 100644 --- a/YAML/YAML.sublime-syntax +++ b/YAML/YAML.sublime-syntax @@ -634,8 +634,9 @@ contexts: 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 + # TODO rewrite with branching - match: | (?x) (?= @@ -650,17 +651,20 @@ contexts: (\s|$) ) push: - - 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_include_prototype: false - - match: '{{_flow_scalar_end_plain_out}}' - pop: true + - - meta_scope: meta.mapping.key.yaml + - match: '' + pop: true + - - 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 + - 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// diff --git a/YAML/tests/syntax_test_block.yaml b/YAML/tests/syntax_test_block.yaml index aca7f7b165..239790713e 100644 --- a/YAML/tests/syntax_test_block.yaml +++ b/YAML/tests/syntax_test_block.yaml @@ -83,11 +83,11 @@ plain # http://yaml.org/spec/1.2/spec.html#style/block/mapping key: value -#^^ string.unquoted.plain.out entity.name.tag +#^^ meta.mapping.key string.unquoted.plain.out # ^ punctuation.separator.key-value.mapping, -entity # ^^^^^ string.unquoted.plain.out key# : value -#^^^ string.unquoted.plain.out entity.name.tag +#^^^ meta.mapping.key string.unquoted.plain.out # ^ -string # ^ punctuation.separator.key-value.mapping # ^^^^^ string.unquoted.plain.out @@ -95,12 +95,12 @@ key# : value # <- punctuation.separator.key-value.mapping _type_null: (?:null|Null|NULL|~) # http://yaml.org/type/null.html -#^^^^^^^^^ entity.name.tag -# ^^^^^^^^^^^^^^^^^^^^ -entity.name.tag +#^^^^^^^^^ meta.mapping.key +# ^^^^^^^^^^^^^^^^^^^^ -meta.mapping.key # ^ comment key on line one: -#^^^^^^^^^^^^^^ entity.name.tag +#^^^^^^^^^^^^^^ meta.mapping.key value on line two ? explicit key # Empty value @@ -117,7 +117,7 @@ key on line one: # <- meta.mapping punctuation.separator.key-value.mapping - two: :three # block value # ^ punctuation.definition.block.sequence -# ^^^ string.unquoted.plain.out entity.name.tag +# ^^^ meta.mapping.key string.unquoted.plain.out # ^ punctuation.separator.key-value.mapping # ^^^^^^ string.unquoted.plain.out From 496f2ee13b5b4e58e3fcb9af160cbdc67dbb0a33 Mon Sep 17 00:00:00 2001 From: FichteFoll Date: Sun, 25 Oct 2020 22:59:10 +0100 Subject: [PATCH 07/15] [YAML] Refactor meta.mapping matching Removes anonymous contexts and the `meta.workaround` workaround by factoring out complex patterns into variables and duplicating the `flow-pair` context to a `*-no-clear` variant for sequences. Also applies version: 2. --- YAML/YAML.sublime-syntax | 166 ++++++++++++++++++++----------- YAML/tests/syntax_test_flow.yaml | 4 +- 2 files changed, 108 insertions(+), 62 deletions(-) diff --git a/YAML/YAML.sublime-syntax b/YAML/YAML.sublime-syntax index f79c838d52..9b8ae1c817 100644 --- a/YAML/YAML.sublime-syntax +++ b/YAML/YAML.sublime-syntax @@ -37,6 +37,7 @@ --- name: YAML scope: source.yaml +version: 2 file_extensions: - yaml @@ -110,6 +111,34 @@ 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/) @@ -512,15 +541,13 @@ contexts: - match: \[ scope: punctuation.definition.sequence.begin.yaml push: - # Pushes an extra 'meta' on the scope stack that flow-pair can then clear, - # so we don't have to duplicate the context - - meta_scope: meta.sequence.flow.yaml meta.workaround.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: @@ -534,48 +561,71 @@ contexts: - match: ',' scope: punctuation.separator.mapping.yaml - include: flow-pair + - include: flow-node # for sets flow-pair: - match: \? - scope: meta.mapping.key.explicit.yaml punctuation.definition.key.begin.yaml + scope: meta.mapping.key.yaml punctuation.definition.key.begin.yaml push: - - - match: '' - set: flow-pair-value - - - clear_scopes: 1 - - meta_content_scope: meta.mapping.key.explicit.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-node + - flow-pair-value-set + - flow-pair-key # Attempt to match plain-in scalars followed by a colon - - match: | - (?x) - (?= - {{ns_plain_first_plain_in}} - ( [^\s:{{c_flow_indicator}}] - | : [^\s{{c_flow_indicator}}] - | \s+ (?![#\s]) - )* - \s* - : - (\s|$) - ) + - match: '{{_flow_key_in_lookahead}}' push: - - - clear_scopes: 1 - - meta_scope: meta.mapping.key.yaml - - include: flow-scalar-plain-in-implicit-type-12 - - match: '' - pop: true - - - match: (?=\S) - pop: true + - flow-pair-value-set + - flow-pair-key-12 - match: :(?=\s|$|{{c_flow_indicator}}) # Empty mapping keys allowed scope: meta.mapping.yaml punctuation.separator.key-value.mapping.yaml push: flow-pair-value - # TODO match as meta.mapping.key + + # 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 + - 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-implicit-type-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: - clear_scopes: 1 - meta_content_scope: meta.mapping.value.yaml @@ -583,6 +633,16 @@ contexts: - 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 + block-scalar: # http://www.yaml.org/spec/1.2/spec.html#style/block/scalar # c-l+literal(n) | c-l+folded(n) @@ -637,32 +697,18 @@ contexts: # Attempt to match plain-out scalars and highlight as "meta.mapping.key", # if followed by a colon # TODO rewrite with branching - - match: | - (?x) - (?= - {{ns_plain_first_plain_out}} - ( - [^\s:] - | : \S - | \s+ (?![#\s]) - )* - \s* - : - (\s|$) - ) + - match: '{{_flow_key_out_lookahead}}' push: - - - meta_scope: meta.mapping.key.yaml - - match: '' - pop: true - - - 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 - - meta_include_prototype: false - - match: '{{_flow_scalar_end_plain_out}}' - pop: true + - 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: meta.mapping.key.yaml string.unquoted.plain.out.yaml + - meta_include_prototype: false + - match: '{{_flow_scalar_end_plain_out}}' + pop: true - match: :(?=\s|$) scope: meta.mapping.yaml punctuation.separator.key-value.mapping.yaml diff --git a/YAML/tests/syntax_test_flow.yaml b/YAML/tests/syntax_test_flow.yaml index 2fba46e214..55dc56ebed 100644 --- a/YAML/tests/syntax_test_flow.yaml +++ b/YAML/tests/syntax_test_flow.yaml @@ -139,7 +139,7 @@ continuation" # ^^^^^^^^^^^^ meta.mapping.value # ^ punctuation.separator.mapping - meta.mapping.value #^ punctuation.definition.key.begin.yaml -#^^^^^^^^^^^^^^ meta.mapping.key.explicit.yaml +#^^^^^^^^^^^^^^ meta.mapping.key.yaml # ^^^^^ storage # ^^^^^ string # ^ punctuation @@ -148,7 +148,7 @@ continuation" # ^^^^^ storage # ^^^^^ string ? !!str foo : :bar -#^^^^^^^^^^^^ meta.mapping.key.explicit.yaml +#^^^^^^^^^^^^ meta.mapping.key.yaml #^ punctuation.definition.key.begin.yaml # ^^^^^ storage # ^^^ string.unquoted.plain.in.yaml From 6fbcdd18c71e52915a9b715900d0b1637f1aa784 Mon Sep 17 00:00:00 2001 From: FichteFoll Date: Wed, 19 Jan 2022 01:23:20 +0100 Subject: [PATCH 08/15] [YAML] Fix flow-pair keys after merge --- YAML/YAML.sublime-syntax | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/YAML/YAML.sublime-syntax b/YAML/YAML.sublime-syntax index 9b8ae1c817..cee25c148e 100644 --- a/YAML/YAML.sublime-syntax +++ b/YAML/YAML.sublime-syntax @@ -535,6 +535,17 @@ 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) @@ -611,7 +622,7 @@ contexts: - match: :(?=\s|$|{{c_flow_indicator}}) scope: meta.mapping.yaml punctuation.separator.key-value.mapping.yaml pop: true - - include: flow-scalar-plain-in-implicit-type-12 + - include: flow-scalar-plain-in-12 flow-pair-key-no-clear: - meta_content_scope: meta.mapping.key.yaml From cb42c61a9361c8fe1e651c08260ced748da2d36b Mon Sep 17 00:00:00 2001 From: FichteFoll Date: Wed, 19 Jan 2022 01:23:50 +0100 Subject: [PATCH 09/15] [YAML] Add scopes to test mapping without strings --- YAML/tests/syntax_test_flow.yaml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/YAML/tests/syntax_test_flow.yaml b/YAML/tests/syntax_test_flow.yaml index 55dc56ebed..30b72d33ca 100644 --- a/YAML/tests/syntax_test_flow.yaml +++ b/YAML/tests/syntax_test_flow.yaml @@ -132,7 +132,12 @@ continuation" # ^^^^^ meta.mapping.value.yaml constant.language.boolean.yaml # ^ meta.mapping.yaml punctuation.definition.mapping.end -{ 1: 2 } + { 1: 2 } +#^^^^^^^^ meta.mapping - meta.mapping meta.mapping - string +# ^ meta.mapping.key.yaml constant.numeric +# ^ meta.mapping.yaml punctuation.separator.key-value.mapping.yaml +# ^^^ meta.mapping.value.yaml +# ^ constant.numeric {? !!str 'key' : !!str value, # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.mapping - meta.mapping meta.mapping From 6614ab104cfd510e1b9547e43e1676b5d618b3fe Mon Sep 17 00:00:00 2001 From: FichteFoll Date: Wed, 19 Jan 2022 01:28:01 +0100 Subject: [PATCH 10/15] [PHP] Update tests with YAML scope changes --- PHP/tests/syntax_test_php.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/PHP/tests/syntax_test_php.php b/PHP/tests/syntax_test_php.php index d6d05371a2..3673a09b20 100644 --- a/PHP/tests/syntax_test_php.php +++ b/PHP/tests/syntax_test_php.php @@ -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 // ^ 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 // ^^^^^^^ string.quoted.double // ^^^^^ variable.other.php From 7a71f933164d9f66b86efb9dbd18b7931828ce83 Mon Sep 17 00:00:00 2001 From: DeathAxe Date: Fri, 11 Feb 2022 20:03:33 +0100 Subject: [PATCH 11/15] [YAML] Restructure scalar-flow-in contexts Introduce named contexts and explicitly distinguish yaml 1.1 and 1.2 --- YAML/YAML.sublime-syntax | 38 ++++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/YAML/YAML.sublime-syntax b/YAML/YAML.sublime-syntax index cee25c148e..697b5dc6d8 100644 --- a/YAML/YAML.sublime-syntax +++ b/YAML/YAML.sublime-syntax @@ -223,7 +223,7 @@ contexts: # http://yaml.org/spec/1.2/spec.html#style/flow/scalar - include: flow-scalar-double-quoted - include: flow-scalar-single-quoted - - include: flow-scalar-plain-in + - include: flow-scalar-plain-in-11 flow-collection: # http://yaml.org/spec/1.2/spec.html#style/flow/collection @@ -518,33 +518,35 @@ contexts: # ns-plain(n,c) (c=flow-out, c=block-key) - include: flow-scalar-plain-out-implicit-type-11 - match: (?={{ns_plain_first_plain_out}}) - push: - - meta_scope: string.unquoted.plain.out.yaml - - meta_include_prototype: false - - match: '{{_flow_scalar_end_plain_out}}' - pop: true + push: flow-scalar-plain-out-content - flow-scalar-plain-in: + flow-scalar-plain-out-content: + - meta_scope: string.unquoted.plain.out.yaml + - meta_include_prototype: false + - match: '{{_flow_scalar_end_plain_out}}' + pop: true + + flow-scalar-plain-in-11: # 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-11 - - 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 + - include: flow-scalar-plain-in-common 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 + - include: flow-scalar-plain-in-common + + flow-scalar-plain-in-common: - 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 + push: flow-scalar-plain-in-content + + flow-scalar-plain-in-content: + - 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 From 856de11d04dbf8bfcd2688e2af8b2d7284fc44f4 Mon Sep 17 00:00:00 2001 From: DeathAxe Date: Fri, 11 Feb 2022 20:08:56 +0100 Subject: [PATCH 12/15] [YAML] Move sclalar-flow-in Group all scalar-in.. and scalar-out... contexts. --- YAML/YAML.sublime-syntax | 44 ++++++++++++++++++++-------------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/YAML/YAML.sublime-syntax b/YAML/YAML.sublime-syntax index 697b5dc6d8..f98ca39964 100644 --- a/YAML/YAML.sublime-syntax +++ b/YAML/YAML.sublime-syntax @@ -433,6 +433,28 @@ contexts: 7: punctuation.separator.time.yaml 8: punctuation.separator.time.yaml + flow-scalar-plain-in-11: + # 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-11 + - include: flow-scalar-plain-in-common + + 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 + - include: flow-scalar-plain-in-common + + flow-scalar-plain-in-common: + - match: (?={{ns_plain_first_plain_in}}) + push: flow-scalar-plain-in-content + + flow-scalar-plain-in-content: + - meta_scope: string.unquoted.plain.in.yaml + - meta_include_prototype: false + - match: '{{_flow_scalar_end_plain_in}}' + pop: true + flow-scalar-plain-out-implicit-type-11: - match: '{{_type_bool_11}}{{_flow_scalar_end_plain_out}}' scope: constant.language.boolean.yaml @@ -526,28 +548,6 @@ contexts: - match: '{{_flow_scalar_end_plain_out}}' pop: true - flow-scalar-plain-in-11: - # 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-11 - - include: flow-scalar-plain-in-common - - 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 - - include: flow-scalar-plain-in-common - - flow-scalar-plain-in-common: - - match: (?={{ns_plain_first_plain_in}}) - push: flow-scalar-plain-in-content - - flow-scalar-plain-in-content: - - 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) From 71002d5e92aec3175965bfb36e9564d2e07eaf80 Mon Sep 17 00:00:00 2001 From: DeathAxe Date: Fri, 11 Feb 2022 19:09:14 +0100 Subject: [PATCH 13/15] [YAML] Fix double and single quoted keys' meta scopes Scope quoted keys `meta.mapping.key`. --- YAML/YAML.sublime-syntax | 94 ++++++++++++++------------------ YAML/tests/syntax_test_flow.yaml | 16 ++++++ 2 files changed, 57 insertions(+), 53 deletions(-) diff --git a/YAML/YAML.sublime-syntax b/YAML/YAML.sublime-syntax index f98ca39964..00a2ccf651 100644 --- a/YAML/YAML.sublime-syntax +++ b/YAML/YAML.sublime-syntax @@ -114,11 +114,15 @@ variables: _flow_key_in_lookahead: |- (?x: (?= - {{ns_plain_first_plain_in}} - ( [^\s:{{c_flow_indicator}}] - | : [^\s{{c_flow_indicator}}] - | \s+ (?![#\s]) - )* + ( + {{ns_plain_first_plain_in}} + ( [^\s:{{c_flow_indicator}}] + | : [^\s{{c_flow_indicator}}] + | \s+ (?![#\s]) + )* + | \".*\" + | \'.*\' + ) \s* : (\s|$) @@ -217,14 +221,27 @@ contexts: # ns-flow-yaml-node(n,c) - include: flow-alias - include: flow-collection - - include: flow-scalar + - include: flow-scalar-11 + + flow-node-12: + # http://yaml.org/spec/1.2/spec.html#style/flow/ + # ns-flow-yaml-node(n,c) + - include: flow-alias + - include: flow-collection + - include: flow-scalar-12 - flow-scalar: + flow-scalar-11: # http://yaml.org/spec/1.2/spec.html#style/flow/scalar - include: flow-scalar-double-quoted - include: flow-scalar-single-quoted - include: flow-scalar-plain-in-11 + flow-scalar-12: + # http://yaml.org/spec/1.2/spec.html#style/flow/scalar + - include: flow-scalar-double-quoted + - include: flow-scalar-single-quoted + - include: flow-scalar-plain-in-12 + flow-collection: # http://yaml.org/spec/1.2/spec.html#style/flow/collection - include: flow-sequence @@ -580,79 +597,50 @@ contexts: - match: \? scope: meta.mapping.key.yaml punctuation.definition.key.begin.yaml push: - - flow-pair-value-set + - flow-pair-clear-1 - flow-pair-key # Attempt to match plain-in scalars followed by a colon - match: '{{_flow_key_in_lookahead}}' push: - - flow-pair-value-set - - flow-pair-key-12 + - flow-pair-clear-1 + - flow-pair-key - match: :(?=\s|$|{{c_flow_indicator}}) # Empty mapping keys allowed scope: meta.mapping.yaml punctuation.separator.key-value.mapping.yaml - push: flow-pair-value + push: + - flow-pair-clear-1 + - 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 + push: flow-pair-key - match: '{{_flow_key_in_lookahead}}' - push: - - flow-pair-value-set-no-clear - - flow-pair-key-no-clear + push: flow-pair-key - match: :(?=\s|$|{{c_flow_indicator}}) scope: meta.mapping.yaml punctuation.separator.key-value.mapping.yaml - push: flow-pair-value-no-clear + push: flow-pair-value 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 - - 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 + - include: flow-pair-end # Empty mapping keys & values are allowed + - include: flow-node-12 flow-pair-value: - - clear_scopes: 1 - meta_content_scope: meta.mapping.value.yaml + - include: flow-pair-end - include: flow-node - - match: (?=[},\]]) - pop: true - flow-pair-value-set-no-clear: + flow-pair-clear-1: + - meta_include_prototype: false + - clear_scopes: 1 - match: '' - set: flow-pair-value-no-clear + pop: true - flow-pair-value-no-clear: - - meta_content_scope: meta.mapping.value.yaml - - include: flow-node + flow-pair-end: - match: (?=[},\]]) pop: true diff --git a/YAML/tests/syntax_test_flow.yaml b/YAML/tests/syntax_test_flow.yaml index 30b72d33ca..ed5428e747 100644 --- a/YAML/tests/syntax_test_flow.yaml +++ b/YAML/tests/syntax_test_flow.yaml @@ -139,6 +139,22 @@ continuation" # ^^^ meta.mapping.value.yaml # ^ constant.numeric +{ "key": "value", 'key': 0 } +#^^^^^^^^^^^^^^^^^^^^^^^^^^^ source.yaml +# <- source.yaml meta.mapping.yaml punctuation.definition.mapping.begin.yaml +#^ meta.mapping.yaml +# ^^^^^ meta.mapping.key string.quoted.double.yaml +# ^ meta.mapping.yaml punctuation.separator.key-value.mapping.yaml +# ^^^^^^^^ meta.mapping.value.yaml +# ^^^^^^^ string.quoted.double.yaml +# ^^ meta.mapping.yaml +# ^ punctuation.separator.mapping.yaml +# ^^^^^ meta.mapping.key.yaml string.quoted.single.yaml +# ^ punctuation.separator.key-value.mapping.yaml +# ^^^ meta.mapping.value.yaml +# ^ meta.number.integer.decimal.yaml constant.numeric.value.yaml +# ^ meta.mapping.yaml punctuation.definition.mapping.end.yaml + {? !!str 'key' : !!str value, # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.mapping - meta.mapping meta.mapping # ^^^^^^^^^^^^ meta.mapping.value From 661ef3e7a25902ab15fca1ffb96bd7ba1c2c8b11 Mon Sep 17 00:00:00 2001 From: FichteFoll Date: Sat, 12 Feb 2022 22:01:41 +0100 Subject: [PATCH 14/15] [YAML] Fix quoted keys' meta scopes in block mappings Additionally implements some fixes for explicit block keys, now verified with tests. --- YAML/YAML.sublime-syntax | 92 +++++++++++++++++++------------ YAML/tests/syntax_test_block.yaml | 18 +++++- 2 files changed, 73 insertions(+), 37 deletions(-) diff --git a/YAML/YAML.sublime-syntax b/YAML/YAML.sublime-syntax index 00a2ccf651..2d1c0c5c28 100644 --- a/YAML/YAML.sublime-syntax +++ b/YAML/YAML.sublime-syntax @@ -115,12 +115,12 @@ variables: (?x: (?= ( - {{ns_plain_first_plain_in}} - ( [^\s:{{c_flow_indicator}}] - | : [^\s{{c_flow_indicator}}] - | \s+ (?![#\s]) - )* - | \".*\" + {{ns_plain_first_plain_in}} + ( [^\s:{{c_flow_indicator}}] + | : [^\s{{c_flow_indicator}}] + | \s+ (?![#\s]) + )* + | \".*\" # simplified | \'.*\' ) \s* @@ -132,11 +132,15 @@ variables: _flow_key_out_lookahead: |- (?x: (?= - {{ns_plain_first_plain_out}} - ( [^\s:] - | : \S - | \s+ (?![#\s]) - )* + ( + {{ns_plain_first_plain_out}} + ( [^\s:] + | : \S + | \s+ (?![#\s]) + )* + | \".*\" # simplified + | \'.*\' + ) \s* : (\s|$) @@ -242,6 +246,12 @@ contexts: - include: flow-scalar-single-quoted - include: flow-scalar-plain-in-12 + flow-scalar-out-12: + # for block keys + - include: flow-scalar-double-quoted + - include: flow-scalar-single-quoted + - include: flow-scalar-plain-out-12 + flow-collection: # http://yaml.org/spec/1.2/spec.html#style/flow/collection - include: flow-sequence @@ -254,6 +264,13 @@ contexts: - include: flow-scalar-plain-out # needs higher priority than flow-node, which includes flow-scalar-plain-in - include: flow-node + block-node-12: + # http://yaml.org/spec/1.2/spec.html#style/block/ + - include: block-scalar + - include: block-collection + - include: flow-scalar-plain-out-12 + - include: flow-node-12 # the -12 variant should not make a difference + block-collection: # http://yaml.org/spec/1.2/spec.html#style/block/collection - include: block-sequence @@ -559,6 +576,13 @@ contexts: - match: (?={{ns_plain_first_plain_out}}) push: flow-scalar-plain-out-content + flow-scalar-plain-out-12: + # http://yaml.org/spec/1.2/spec.html#style/flow/plain + # ns-plain(n,c) (c=flow-out, c=block-key) + - include: flow-scalar-plain-out-implicit-type-12 + - match: (?={{ns_plain_first_plain_out}}) + push: flow-scalar-plain-out-content + flow-scalar-plain-out-content: - meta_scope: string.unquoted.plain.out.yaml - meta_include_prototype: false @@ -680,39 +704,37 @@ contexts: - include: block-pair block-pair: - - match: \? + - match: \?(?=\s|$) scope: meta.mapping.yaml punctuation.definition.key-value.begin.yaml push: - - 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: meta.mapping.yaml invalid.illegal.expected-newline.yaml - pop: true - - include: block-node + - block-key-explicit # Attempt to match plain-out scalars and highlight as "meta.mapping.key", # if followed by a colon - # TODO rewrite with branching - 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: meta.mapping.key.yaml string.unquoted.plain.out.yaml - - meta_include_prototype: false - - match: '{{_flow_scalar_end_plain_out}}' - pop: true + - block-key-implicit - match: :(?=\s|$) scope: meta.mapping.yaml punctuation.separator.key-value.mapping.yaml + block-key-implicit: + - meta_content_scope: meta.mapping.key.yaml + - match: :(?=\s|$) + scope: meta.mapping.yaml punctuation.separator.key-value.mapping.yaml + pop: true + - include: flow-scalar-out-12 + + block-key-explicit: + - meta_content_scope: meta.mapping.key.yaml + # the colon *must* be on a new line + - match: ^ *(:) + scope: meta.mapping.yaml + captures: + 1: punctuation.separator.key-value.mapping.yaml + pop: true + - match: (?=\?(?=\s|$)) # Empty mapping keys & values are allowed + pop: true + - include: block-node-12 + comment: # http://www.yaml.org/spec/1.2/spec.html#comment// - match: | # l-comment diff --git a/YAML/tests/syntax_test_block.yaml b/YAML/tests/syntax_test_block.yaml index 239790713e..3c712328ed 100644 --- a/YAML/tests/syntax_test_block.yaml +++ b/YAML/tests/syntax_test_block.yaml @@ -100,8 +100,14 @@ _type_null: (?:null|Null|NULL|~) # http://yaml.org/type/null.html # ^ comment key on line one: -#^^^^^^^^^^^^^^ meta.mapping.key +#^^^^^^^^^^^^^^ meta.mapping.key string.unquoted.plain value on line two +# ^^^^^^^^^^^^^^^^^ string.unquoted.plain.out - meta.mapping.key + + +"quoted key": value +#^^^^^^^^^^^ meta.mapping.key string.quoted.double +# ^ punctuation.definition.string.end ? explicit key # Empty value #^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.mapping.key @@ -121,12 +127,20 @@ key on line one: # ^ punctuation.separator.key-value.mapping # ^^^^^^ string.unquoted.plain.out +# the entire first line is the key (as a mapping with one entry) ? a key : not a value -# ^ meta.mapping invalid.illegal.expected-newline +# ^^^^^^^^^^^^^^^^^^^ meta.mapping.key +# ^ meta.mapping.key meta.mapping punctuation.separator.key-value.mapping +: +# <- meta.mapping punctuation.separator.key-value.mapping - meta.mapping meta.mapping scalar # <- -meta.mapping + ?not a key +#^^^^^^^^^^ - meta.mapping + + x: - #1 # ^^ comment.line From 2af4c5dda1e4dfc9d4b3425512c0036e32e2354c Mon Sep 17 00:00:00 2001 From: FichteFoll Date: Fri, 25 Feb 2022 21:42:34 +0100 Subject: [PATCH 15/15] [YAML] Use string version for single-context push --- YAML/YAML.sublime-syntax | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/YAML/YAML.sublime-syntax b/YAML/YAML.sublime-syntax index 2d1c0c5c28..6729e55f26 100644 --- a/YAML/YAML.sublime-syntax +++ b/YAML/YAML.sublime-syntax @@ -706,13 +706,11 @@ contexts: block-pair: - match: \?(?=\s|$) scope: meta.mapping.yaml punctuation.definition.key-value.begin.yaml - push: - - block-key-explicit + push: block-key-explicit # 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 + push: block-key-implicit - match: :(?=\s|$) scope: meta.mapping.yaml punctuation.separator.key-value.mapping.yaml