Add YamlLoader::load_from_str_with_markers
to provide AST with source markers
#125
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.
fixes #103, replaces #105
The new function produces an alternative representation for YAML
documents where each YAML node is paired with a
Marker
to indicate thecorresponding line and column in the source markup. The new
representation takes the form of two new types,
Node
andYamlMarked
.Node
is a pair ofYamlMarked
andMarker
.YamlMarked
mimics the existingYaml
enum; the difference is that arrayelements and hash keys and values are
Node
values instead ofYaml
orYamlMarked
values. I created a new enum because I did not know of a wayto switch child nodes in
Yaml
betweenYaml
andNode
types withoutbackward-incompatible changes to the
Yaml
enum.The the behavior of the existing
load_from_str
function andYaml
enum are unchanged, so pattern matching on results from
load_from_str
will work as before.
To ensure consistent behavior for the
Node
andYaml
I moved methodsfrom the
impl Yaml
block to a new trait calledYamlNode
which isimplemented by
Yaml
,Node
, andYamlMarked
. This is a breakingchange since it means that consumers will have to import
YamlNode
touse methods like
.as_str()
and.is_array()
.I want to present this pull request as one proposal. I think there is also
an argument for changing the existing
Yaml
type to incorporate sourcelocation markers instead of maintaining two parallel enums.
While making changes I split up
yaml.rs
into three nested modules.I can put it back the way it was if that is preferable.