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

bug in parsing #693

Closed
geert56 opened this issue Dec 16, 2022 · 3 comments
Closed

bug in parsing #693

geert56 opened this issue Dec 16, 2022 · 3 comments

Comments

@geert56
Copy link

geert56 commented Dec 16, 2022

The YAML 1.2.2 spec states:
"Within a block collection, key/value pairs can start immediately following the dash, colon or question mark."
This implies that "a: b: c: d: - 1" is a valid YAML document. js-yaml however issues an error message.

@ingydotnet
Copy link

That sentence is just a clarification of the context around it.
You've taken it on its own to be an assertion/property of YAML, but it doesn't make sense outside the context at
https://yaml.org/spec/1.2.2/#example-mapping-between-sequences

The point of the sentence is to say that (from the examples that follow the statement) you can do this:

? - Detroit Tigers
  - Chicago cubs
: - 2001-07-23

instead of this:

?
  - Detroit Tigers
  - Chicago cubs
:
  - 2001-07-23

and this:

- item    : Super Hoop
  quantity: 1

instead of this:

-
  item    : Super Hoop
  quantity: 1

@ingydotnet
Copy link

For the record, a: b: c: d: - 1 is invalid YAML and this is not a "bug i n parsing".

YAML doesn't support compact block mappings

key: key: value   # wrong

even though it does support compact block sequences:

- - - value
# same as
-
  -
    - value

and also compact block mapping in sequence:

- - key1: value1
    key2: value2
# same as
-
  -
    key1: value1
    key2: value2

@geert56
Copy link
Author

geert56 commented Dec 20, 2022

Thanks for the clarifications. In my honest opinion, the spec could have been a bit more precise and express syntax in a more conventional, formal way. Alas, we shall have to live with it.

@geert56 geert56 closed this as completed Dec 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants