Issues with determining posistion of null values #34
-
Thank you for a great library. I have been using it for a project, but I am struggling to figure out how to determine the position of a certain yaml data path. I am using MarkedYaml and for most things it works ok. It would have been nice if the spans for hash and array wrapped the entire span of their definition instead of only the starting point. But the real issue is for null values where the position seems to be marking the beginning of the next object, and since each object do not track their "parent" I need to maintain the context myself. fn test_marked_yaml_with_null_values() {
let yaml = "key:\n - \n - 1\n - \nanother_key: 123";
let binding = MarkedYaml::load_from_str(yaml).unwrap();
let marked_yaml = binding.first().unwrap();
println!("---");
println!("{}", yaml);
println!("---");
println!("{:?}", marked_yaml);
println!("---"); output key:
-
- 1
-
another_key: 123 MarkedYaml {
span: Span { start: Marker { index: 0, line: 1, col: 0 }, end: Marker { index: 0, line: 1, col: 0 } },
data: Hash({
MarkedYaml {
span: Span { start: Marker { index: 0, line: 1, col: 0 }, end: Marker { index: 3, line: 1, col: 3 } },
data: String("key") }: MarkedYaml {
span: Span { start: Marker { index: 7, line: 2, col: 2 }, end: Marker { index: 7, line: 2, col: 2 } },
data: Array([
MarkedYaml {
span: Span { start: Marker { index: 14, line: 3, col: 4 }, end: Marker { index: 14, line: 3, col: 4 } },
data: Null },
MarkedYaml {
span: Span { start: Marker { index: 14, line: 3, col: 4 }, end: Marker { index: 15, line: 3, col: 5 } },
data: Integer(1) },
MarkedYaml {
span: Span { start: Marker { index: 21, line: 5, col: 0 }, end: Marker { index: 21, line: 5, col: 0 } },
data: Null }
]) },
MarkedYaml {
span: Span { start: Marker { index: 21, line: 5, col: 0 }, end: Marker { index: 32, line: 5, col: 11 } },
data: String("another_key") }: MarkedYaml {
span: Span { start: Marker { index: 34, line: 5, col: 13 }, end: Marker { index: 37, line: 5, col: 16 } },
data: Integer(123) }}) }
--- Do you have any suggestions apart from writing my own EventReceiver? Thanks again |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
There is much room for improvement with regard to spans. As of now, I'm more trying to focus on performance and avoiding to always have to reallocate objects. The I don't want to take too much of your time, but a The only thing I can think of as a suggestion aside from the custom |
Beta Was this translation helpful? Give feedback.
There is much room for improvement with regard to spans. As of now, I'm more trying to focus on performance and avoiding to always have to reallocate objects.
The
Null
case is an interesting one. I suppose it stems from the fact that we cannot know until we reach the next token that there is aNull
value, at which time the position in the parser is already set to said next token. ExplicitNull
values should have theirSpan
set properly I assume?I don't want to take too much of your time, but a
#[test]
for the expectedMarkers
onNull
nodes would help a lot.The only thing I can think of as a suggestion aside from the custom
EventReceiver
would be a pull request :( I don't think there is …