Feature/scanner/explict key #21

Merged
bazaah merged 7 commits from feature/scanner/explict-key into master 2021-08-08 09:59:11 +00:00

7 Commits

Author SHA1 Message Date
Paul Stemmet 1c4eae89db
lib/scanner: clippy lints 2021-08-08 09:57:08 +00:00
Paul Stemmet effd55d38b
lib/scanner: add tests for explicit key cases 2021-08-08 09:22:25 +00:00
Paul Stemmet 0da984150b
lib/scanner: add explicit key support to Scanner 2021-08-08 09:22:25 +00:00
Paul Stemmet a83aa903e8
scanner/error: add variant InvalidKey
for catching cases where a key was given but not valid, typically
involving explicit keys ('?')
2021-08-08 09:22:25 +00:00
Paul Stemmet 2d1d36bec5
lib/scanner: add test for zero indented sequence decrement 2021-08-08 09:22:25 +00:00
Paul Stemmet 18ce7ff0de
lib/scanner: further fixes to zero indented sequence handling
While the previous commit did add support for _adding_ zero indented
sequences to the token stream, it unfortunately relied on the indent
stack flush that happens once reaching end of stream to push the stored
BlockEnd tokens.

This commit adds better support for removing zero indented sequences
from the stack once finished.

The heuristic used here is:

A zero_indented BlockSequence starts when:

- The top stored indent is for a BlockMapping
- A BlockEntry occupies the same indentation level

And terminates when:

- The top indent stored is a BlockSequence & is tagged as zero indented
- A BlockEntry _does not_ occupy the same indentation level
2021-08-08 09:22:24 +00:00
Paul Stemmet 3c5c5cf8e6
lib/scanner: produce token for zero indentation block sequence
This fixes the edge case YAML allows where a sequence may be zero
indented, but still start a sequence.

E.g using the following YAML:

key:
- "one"
- "two"

The following tokens would have been produced (before this commit):

StreamStart
BlockMappingStart
Key
Scalar('key')
Value
BlockEntry
Scalar('one')
BlockEntry
Scalar('two')
BlockEnd
StreamEnd

Note the the lack of any indication that the values are in a sequence.
Post commit, the following is produced:

StreamStart
BlockMappingStart
Key
Scalar('key')
Value
BlockSequenceStart  <--
BlockEntry
Scalar('one')
BlockEntry
Scalar('two')
BlockEnd <--
BlockEnd
StreamEnd
2021-08-06 19:56:13 +00:00