From 6218337a4f90f731893d5feb5056e5782a0a57e0 Mon Sep 17 00:00:00 2001 From: deathaxe Date: Sat, 17 Feb 2024 15:36:45 +0100 Subject: [PATCH 1/2] [YAML] Fix unbalanced quoted scalars This commit scopes tokens after closing quotation mark illegal to discover unbalanced quotation marks. --- YAML/YAML.sublime-syntax | 54 +++++++++++++++++++++----- YAML/tests/syntax_test_flow.yaml | 66 ++++++++++++++++++++++++++++++++ 2 files changed, 110 insertions(+), 10 deletions(-) diff --git a/YAML/YAML.sublime-syntax b/YAML/YAML.sublime-syntax index 198072df87..780aec9d4a 100644 --- a/YAML/YAML.sublime-syntax +++ b/YAML/YAML.sublime-syntax @@ -265,20 +265,20 @@ contexts: 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-double-quoted-in + - include: flow-scalar-single-quoted-in - 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-double-quoted-in + - include: flow-scalar-single-quoted-in - 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-double-quoted-out + - include: flow-scalar-single-quoted-out - include: flow-scalar-plain-out-12 ###[ COMMENTS ]############################################################### @@ -466,12 +466,23 @@ contexts: 2: variable.other.alias.yaml 3: invalid.illegal.character.anchor.yaml - flow-scalar-double-quoted: + flow-scalar-double-quoted-in: # http://yaml.org/spec/1.2/spec.html#style/flow/double-quoted # c-double-quoted(n,c) - match: \" scope: punctuation.definition.string.begin.yaml - push: flow-scalar-double-quoted-body + push: + - flow-scalar-in-expect-end + - flow-scalar-double-quoted-body + + flow-scalar-double-quoted-out: + # http://yaml.org/spec/1.2/spec.html#style/flow/double-quoted + # c-double-quoted(n,c) + - match: \" + scope: punctuation.definition.string.begin.yaml + push: + - flow-scalar-out-expect-end + - flow-scalar-double-quoted-body flow-scalar-double-quoted-body: # TODO consider scoping meaningful trailing whitespace for color @@ -486,12 +497,23 @@ contexts: scope: punctuation.definition.string.end.yaml pop: 1 - flow-scalar-single-quoted: + flow-scalar-single-quoted-in: + # http://yaml.org/spec/1.2/spec.html#style/flow/single-quoted + # c-single-quoted(n,c) + - match: \' + scope: punctuation.definition.string.begin.yaml + push: + - flow-scalar-in-expect-end + - flow-scalar-single-quoted-body + + flow-scalar-single-quoted-out: # http://yaml.org/spec/1.2/spec.html#style/flow/single-quoted # c-single-quoted(n,c) - match: \' scope: punctuation.definition.string.begin.yaml - push: flow-scalar-single-quoted-body + push: + - flow-scalar-out-expect-end + - flow-scalar-single-quoted-body flow-scalar-single-quoted-body: - meta_include_prototype: false @@ -502,6 +524,18 @@ contexts: scope: punctuation.definition.string.end.yaml pop: 1 + flow-scalar-in-expect-end: + - meta_include_prototype: false + - meta_content_scope: invalid.illegal.unexpected.yaml + - match: '{{_flow_scalar_end_plain_in}}' + pop: 1 + + flow-scalar-out-expect-end: + - meta_include_prototype: false + - meta_content_scope: invalid.illegal.unexpected.yaml + - match: '{{_flow_scalar_end_plain_out}}' + pop: 1 + flow-scalar-plain-in-implicit-type-11: - match: '{{_type_bool_11}}{{_flow_scalar_end_plain_in}}' scope: constant.language.boolean.yaml diff --git a/YAML/tests/syntax_test_flow.yaml b/YAML/tests/syntax_test_flow.yaml index 07990cdeb2..6a89bd9cf6 100644 --- a/YAML/tests/syntax_test_flow.yaml +++ b/YAML/tests/syntax_test_flow.yaml @@ -59,6 +59,14 @@ "string\ continuation" +"string"illegal +# <- meta.string.yaml string.quoted.double.yaml +#^^^^^^^ meta.string.yaml string.quoted.double.yaml +# ^^^^^^^ invalid.illegal.unexpected.yaml + +unquoted"string" +# <- meta.string.yaml string.unquoted.plain.out.yaml +#^^^^^^^^^^^^^^^ meta.string.yaml string.unquoted.plain.out.yaml - invalid ############################################################################## ## Single-quoted @@ -80,6 +88,14 @@ continuation" # ^^ constant.character.escape # ^ -constant +'string'illegal +# <- meta.string.yaml string.quoted.single.yaml +#^^^^^^^ meta.string.yaml string.quoted.single.yaml +# ^^^^^^^ invalid.illegal.unexpected.yaml + +unquoted'string' +# <- meta.string.yaml string.unquoted.plain.out.yaml +#^^^^^^^^^^^^^^^ meta.string.yaml string.unquoted.plain.out.yaml - invalid ############################################################################## ## Flow-sequence @@ -107,6 +123,36 @@ continuation" # ^ punctuation.separator.sequence # ^^^ string.unquoted.plain.in - entity.name.tag +[ "str"err, 'str'err, "str"err ] +#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.sequence.flow.yaml +# ^^^^^ meta.string.yaml string.quoted.double.yaml +# ^^^ invalid.illegal.unexpected.yaml +# ^ punctuation.separator.sequence.yaml +# ^^^^^ meta.string.yaml string.quoted.single.yaml +# ^^^ invalid.illegal.unexpected.yaml +# ^ punctuation.separator.sequence.yaml +# ^^^^^ meta.string.yaml string.quoted.double.yaml +# ^^^ invalid.illegal.unexpected.yaml +# ^ punctuation.definition.sequence.end.yaml + +# mapping keys are not matched +[ "k"err: "v"err, "k"err : "v"err ] +# <- meta.sequence.flow.yaml punctuation.definition.sequence.begin.yaml +#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.sequence.flow.yaml +# ^^^ meta.string.yaml string.quoted.double.yaml +# ^^^ invalid.illegal.unexpected.yaml +# ^ meta.mapping.yaml punctuation.separator.key-value.mapping.yaml +# ^^^ meta.mapping.value.yaml meta.string.yaml string.quoted.double.yaml +# ^^^ meta.mapping.value.yaml invalid.illegal.unexpected.yaml +# ^ punctuation.separator.sequence.yaml +# ^^^ meta.string.yaml string.quoted.double.yaml +# ^^^ invalid.illegal.unexpected.yaml +# ^ - invalid +# ^ meta.mapping.yaml punctuation.separator.key-value.mapping.yaml +# ^^^ meta.mapping.value.yaml meta.string.yaml string.quoted.double.yaml +# ^^^ meta.mapping.value.yaml invalid.illegal.unexpected.yaml +# ^ meta.mapping.value.yaml - invalid +# ^ punctuation.definition.sequence.end.yaml ############################################################################## ## Flow-mapping @@ -155,6 +201,26 @@ continuation" # ^ meta.number.integer.decimal.yaml constant.numeric.value.yaml # ^ meta.mapping.yaml punctuation.definition.mapping.end.yaml +{ "k"err: "v"err, 'k'err: 'v'err } +# <- meta.mapping.yaml punctuation.definition.mapping.begin.yaml +#^^^^^^^^ meta.mapping.yaml +# ^^^^^^^ meta.mapping.value.yaml +# ^^^^^^^^^ meta.mapping.yaml +# ^^^^^^^^ meta.mapping.value.yaml +# ^ meta.mapping.yaml +# ^^^ meta.string.yaml string.quoted.double.yaml +# ^^^ invalid.illegal.unexpected.yaml - string +# ^ punctuation.separator.key-value.mapping.yaml +# ^^^ meta.string.yaml string.quoted.double.yaml +# ^^^ invalid.illegal.unexpected.yaml - string +# ^ punctuation.separator.sequence.yaml +# ^^^ meta.string.yaml string.quoted.single.yaml +# ^^^ invalid.illegal.unexpected.yaml - string +# ^ punctuation.separator.key-value.mapping.yaml +# ^^^ meta.string.yaml string.quoted.single.yaml +# ^^^ invalid.illegal.unexpected.yaml - string +# ^ punctuation.definition.mapping.end.yaml + {? !!str 'key' : !!str value, # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.mapping - meta.mapping meta.mapping # ^^^^^^^^^^^^ meta.mapping.value From ab20fc8db374c9d942a2bb5c2533460f7cc4523f Mon Sep 17 00:00:00 2001 From: deathaxe Date: Sat, 17 Feb 2024 17:37:41 +0100 Subject: [PATCH 2/2] [YAML] Fix illegal scope covering string due to multi-push --- YAML/YAML.sublime-syntax | 8 ++++---- YAML/tests/syntax_test_flow.yaml | 16 ++++++++-------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/YAML/YAML.sublime-syntax b/YAML/YAML.sublime-syntax index 780aec9d4a..1cae918e96 100644 --- a/YAML/YAML.sublime-syntax +++ b/YAML/YAML.sublime-syntax @@ -526,14 +526,14 @@ contexts: flow-scalar-in-expect-end: - meta_include_prototype: false - - meta_content_scope: invalid.illegal.unexpected.yaml - - match: '{{_flow_scalar_end_plain_in}}' + - match: (?:(?!{{_flow_scalar_end_plain_in}}).)* + scope: invalid.illegal.unexpected.yaml pop: 1 flow-scalar-out-expect-end: - meta_include_prototype: false - - meta_content_scope: invalid.illegal.unexpected.yaml - - match: '{{_flow_scalar_end_plain_out}}' + - match: (?:(?!{{_flow_scalar_end_plain_out}}).)* + scope: invalid.illegal.unexpected.yaml pop: 1 flow-scalar-plain-in-implicit-type-11: diff --git a/YAML/tests/syntax_test_flow.yaml b/YAML/tests/syntax_test_flow.yaml index 6a89bd9cf6..ce3c05f464 100644 --- a/YAML/tests/syntax_test_flow.yaml +++ b/YAML/tests/syntax_test_flow.yaml @@ -23,13 +23,13 @@ # http://yaml.org/spec/1.2/spec.html#style/flow/double-quoted "flow string" -#^^^^^^^^^^^^ string.quoted.double +#^^^^^^^^^^^^ string.quoted.double - invalid # ^ punctuation.definition.string.end # <- string.quoted.double punctuation.definition.string.begin "flow string more string" -#^^^^^^^^^^^^ string.quoted.double +#^^^^^^^^^^^^ string.quoted.double - invalid # ^ punctuation.definition.string.end "\" \0 \\ \x1b \u12c4 \U1234F678" @@ -60,8 +60,8 @@ continuation" "string"illegal -# <- meta.string.yaml string.quoted.double.yaml -#^^^^^^^ meta.string.yaml string.quoted.double.yaml +# <- meta.string.yaml string.quoted.double.yaml - invalid +#^^^^^^^ meta.string.yaml string.quoted.double.yaml - invalid # ^^^^^^^ invalid.illegal.unexpected.yaml unquoted"string" @@ -73,13 +73,13 @@ unquoted"string" # http://yaml.org/spec/1.2/spec.html#style/flow/single-quoted 'flow string' -#^^^^^^^^^^^^ string.quoted.single +#^^^^^^^^^^^^ string.quoted.single - invalid # ^ punctuation.definition.string.end # <- string.quoted.single punctuation.definition.string.begin 'flow string more string' -#^^^^^^^^^^^^ string.quoted.single +#^^^^^^^^^^^^ string.quoted.single - invalid # ^ punctuation.definition.string.end # <- string.quoted.single @@ -89,8 +89,8 @@ unquoted"string" # ^ -constant 'string'illegal -# <- meta.string.yaml string.quoted.single.yaml -#^^^^^^^ meta.string.yaml string.quoted.single.yaml +# <- meta.string.yaml string.quoted.single.yaml - invalid +#^^^^^^^ meta.string.yaml string.quoted.single.yaml - invalid # ^^^^^^^ invalid.illegal.unexpected.yaml unquoted'string'