Keep markers in parsed output#105
Open
moretea wants to merge 5 commits into
Open
Conversation
- Made sure that equality between Yaml is just based on the _content_, not the marks.
|
@moretea Hi! I'm have a use case for source location markers. I am happy to contribute some time to get this PR finished and merged. Is there anything that I can do to help? What needs to be done to complete this work? |
|
As a start I merged the latest changes from master into the code for this PR. The result is in my fork at https://github.com/hallettj/yaml-rust/tree/keep_markers |
hallettj
pushed a commit
to hallettj/yaml-rust
that referenced
this pull request
Mar 26, 2019
…ce markers fixes chyh1990#103, replaces chyh1990#105 The new function produces an alternative representation for YAML documents where each YAML node is paired with a `Marker` to indicate the corresponding line and column in the source markup. The new representation takes the form of two new types, `Node` and `YamlMarked`. `Node` is a pair of `YamlMarked` and `Marker`. `YamlMarked` mimics the existing `Yaml` enum; the difference is that array elements and hash keys and values are `Node` values instead of `Yaml` or `YamlMarked` values. I created a new enum because I did not know of a way to switch child nodes in `Yaml` between `Yaml` and `Node` types without backward-incompatible changes to the `Yaml` enum. The the behavior of the existing `load_from_str` function and `Yaml` enum are unchanged, so pattern matching on results from `load_from_str` will work as before. To ensure consistent behavior for the `Node` and `Yaml` I moved methods from the `impl Yaml` block to a new trait called `YamlNode` which is implemented by `Yaml`, `Node`, and `YamlMarked`. This is a breaking change since it means that consumers will have to import `YamlNode` to use 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 source location 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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This work in progress pull request adds the markers to the output of the parser
Changes
YamltoNode, introducedstruct Yaml(Option<Marker>, Node).HashItem. The key of theHashwill stay a Node without a Marker, we store the position of the key in thisHashItemtoo.I'm not very happy with the fact that now you need to use the
.0and.1struct indices to get access to the marker or the node. I'll probably update these.A question to you @chyh1990, is this something that you would merge eventually? Otherwise I'll be able to live with maintaining a fork for my own purpose.
Closes #103.