mirror of
https://github.com/google/go-jsonnet.git
synced 2026-04-07 14:31:00 +02:00
This doesn't make them fully correct, in particular directives sections (e.g., "%YAML 1.2" directive before a document start marker) are not handled correctly, but they weren't handled correctly before, either. It also doesn't recognise or try to do anything about document end markers (`...`). This fix does allow scalar documents to be on the same line as the document start tag which is valid per examples in the YAML spec, see for example https://yaml.org/spec/1.2.1/#id2760844 (YAML 1.2.1 spec, section 2.3 Scalars) It also matches the C++ jsonnet output for std.parseYaml("42\n---"), which is a stream of two documents, a scalar and then an empty document (where the empty document is interpreted as JSON null)
65 lines
1.0 KiB
Jsonnet
65 lines
1.0 KiB
Jsonnet
[
|
|
std.parseYaml(text)
|
|
for text in [
|
|
// various node types
|
|
|||
|
|
foo: bar
|
|
aaa: {}
|
|
ąę: ćż
|
|
xxx:
|
|
- 42
|
|
- asdf
|
|
- {}
|
|
|||,
|
|
|
|
// Returns an array of documents when there is an explicit document(s), i.e.
|
|
// the text is a "multi-doc" stream
|
|
|||
|
|
---
|
|
a: 1
|
|
---
|
|
a: 2
|
|
|||,
|
|
|
|
// The first document in a "multi-doc" stream can be an implicit document.
|
|
|||
|
|
a: 1
|
|
---
|
|
a: 2
|
|
|||,
|
|
|
|
// Whitespaces are allowed after the document start marker
|
|
|||
|
|
---
|
|
a: 1
|
|
---
|
|
a: 2
|
|
|||,
|
|
|
|
// Document start marker needs a following line break or a whitespace.
|
|
|||
|
|
a: 1
|
|
---a: 2
|
|
a---: 3
|
|
|||,
|
|
|
|
// Scalar documents can start on the same line as the document-start marker
|
|
|||
|
|
a: 1
|
|
--- >
|
|
hello
|
|
world
|
|
--- 3
|
|
|||,
|
|
|
|
// Documents can be empty; this is interpreted as null
|
|
|||
|
|
a: 1
|
|
---
|
|
--- 2
|
|
|||,
|
|
|
|
"---",
|
|
]
|
|
]
|