Commit 5216abe
Jesse Hallett
Add
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.YamlLoader::load_from_str_with_markers to provide AST with source markers1 parent 1d29d21 commit 5216abe
File tree
8 files changed
+664
-265
lines changed- src
- yaml
- tests
8 files changed
+664
-265
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
| 13 | + | |
13 | 14 | | |
14 | 15 | | |
15 | 16 | | |
| 17 | + | |
16 | 18 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
27 | | - | |
| 27 | + | |
28 | 28 | | |
29 | 29 | | |
30 | 30 | | |
| |||
44 | 44 | | |
45 | 45 | | |
46 | 46 | | |
| 47 | + | |
47 | 48 | | |
48 | 49 | | |
49 | 50 | | |
| |||
54 | 55 | | |
55 | 56 | | |
56 | 57 | | |
57 | | - | |
58 | | - | |
| 58 | + | |
| 59 | + | |
59 | 60 | | |
60 | 61 | | |
61 | 62 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
21 | | - | |
| 21 | + | |
22 | 22 | | |
23 | 23 | | |
24 | 24 | | |
| |||
0 commit comments