This repository has been archived by the owner on Dec 15, 2022. It is now read-only.
Fix multiline strings and add document end marker support #74
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Requirements
Description of the Change
YAML is tricky because it supports multiline strings using regular tags. As long as the next line is indented more than the tag, it'll be counted as part of the string. In previous PRs I implemented the multiline support, but without the indentation requirement. This PR properly implements indentation checks so that we don't attempt to tokenize everything until the next tag as scalar content. This fixes embedding (valid) YAML in other grammars, such as GFM.
In addition, the end document marker
...
has been added.Alternate Designs
None.
Benefits
The immediate benefits provided by this PR won't necessarily be evident to people who solely edit YAML because most non-tagged lines will be tokenized as a string anyway. However, it'll be extremely beneficial to grammars that allow for the embedding of YAML.
Possible Drawbacks
Not necessarily a drawback, but people don't get any indication that they're writing invalid YAML, even with this pull request. That is because all lines fall back to being tokenized a string if there are no other matches. That also makes it extremely hard to test, because the tags don't get an overarching scope name. So I've had to settle for a document end marker test, which will fail without indentation checks. This may be something that I'll try to fix for the future.
Applicable Issues
Fixes #72
Fixes #73
/cc @lierdakil