-
Notifications
You must be signed in to change notification settings - Fork 17
WIP: Try to retain location #5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for having worked on this! Unfortunately, I do think we'll proceed with yannham's design idea. I am not closing this until a valid implementation is written lest we encounter issues.
@@ -12,6 +12,93 @@ use hashlink::LinkedHashMap; | |||
|
|||
use saphyr_parser::{Event, MarkedEventReceiver, Marker, Parser, ScanError, TScalarStyle, Tag}; | |||
|
|||
#[derive(Clone, Debug, Eq, PartialEq)] | |||
pub struct OtherMarker { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What does OtherMarker
provide that Marker
doesn't? Seems like all occurrences of it could be changed to just Marker
.
impl From<(usize, usize, usize)> for OtherMarker { | ||
fn from((line, column, idx): (usize, usize, usize)) -> Self { | ||
OtherMarker { line, column, idx } | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would very much have this conversion be explicit. (usize, usize, usize)
is a very generic type that may be used for much more than a Marker
.
Start(OtherMarker), | ||
Ended { | ||
start: OtherMarker, | ||
end: OtherMarker, | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Start(OtherMarker), | |
Ended { | |
start: OtherMarker, | |
end: OtherMarker, | |
}, | |
Index(OtherMarker), | |
Span { | |
start: OtherMarker, | |
end: OtherMarker, | |
}, |
Location::Start(start) => { | ||
let mut end = start.clone(); | ||
end.idx = start.idx + arg; | ||
end.column = start.column + arg; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would need much more context than that. This doesn't support linebreaks.
match Location::from(m) { | ||
Location::Start(start) => Location::Ended { | ||
start, | ||
end: OtherMarker { | ||
line: last_row, | ||
column: last_column, | ||
idx: last_idx, | ||
}, | ||
}, | ||
Location::Ended { .. } => { | ||
unreachable!("If we just convert this, it can't really have an end!") | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't it just be
Location::Ended { start: m.into(), end: OtherMarker { ... } }
I don't see why the conversion to a Location
is necessary. The into
could also be removed if we change OtherMarker
to be a Marker
.
@@ -771,6 +974,7 @@ c: [1, 2] | |||
"; | |||
let out = YamlDecoder::read(s as &[u8]).decode().unwrap(); | |||
let doc = &out[0]; | |||
dbg!(&doc); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
dbg!(&doc); |
Closing this in favour of #6 |
Allows the event consumer to know whether the document explicitly starts with a `---`
No description provided.