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] Fix unbalanced quoted scalars #3923

Merged
merged 2 commits into from
Feb 18, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
54 changes: 44 additions & 10 deletions YAML/YAML.sublime-syntax
Original file line number Diff line number Diff line change
Expand Up @@ -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 ]###############################################################
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
66 changes: 66 additions & 0 deletions YAML/tests/syntax_test_flow.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Loading