Skip to content

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

Closed
wants to merge 7 commits into from
Closed

WIP: Try to retain location #5

wants to merge 7 commits into from

Conversation

felipesere
Copy link

No description provided.

Copy link
Contributor

@Ethiraric Ethiraric left a 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 {
Copy link
Contributor

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.

Comment on lines +22 to +26
impl From<(usize, usize, usize)> for OtherMarker {
fn from((line, column, idx): (usize, usize, usize)) -> Self {
OtherMarker { line, column, idx }
}
}
Copy link
Contributor

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.

Comment on lines +40 to +44
Start(OtherMarker),
Ended {
start: OtherMarker,
end: OtherMarker,
},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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;
Copy link
Contributor

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.

Comment on lines +86 to +98
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!")
}
}
Copy link
Contributor

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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
dbg!(&doc);

@Ethiraric
Copy link
Contributor

Closing this in favour of #6

@Ethiraric Ethiraric closed this Jul 2, 2024
Ethiraric pushed a commit that referenced this pull request Oct 2, 2024
Allows the event consumer to know whether the document explicitly starts with a `---`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants