Skip to content

Commit

Permalink
sourcepos: slightly improve desc lists, document current/desired
Browse files Browse the repository at this point in the history
  • Loading branch information
kivikakk committed Mar 31, 2023
1 parent ab4a725 commit e186adc
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 23 deletions.
32 changes: 26 additions & 6 deletions src/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1345,18 +1345,37 @@ impl<'a, 'o, 'c> Parser<'a, 'o, 'c> {
// is added to it. If not, create a new list.

last_child.detach();
let last_child_sourcepos = last_child.data.borrow().sourcepos;

// TODO: description list sourcepos is totally broken.
// TODO: description list sourcepos has issues.
//
// DescriptionItem:
// For all but the last, the end line/col is wrong.
// Where it should be l:c, it gives (l+1):0.
//
// DescriptionTerm:
// All are incorrect; they all give the start line/col of
// the DescriptionDetails, and the end line/col is completely off.
//
// descriptionDetails:
// Same as the DescriptionItem. All but last, the end line/col
// is (l+1):0.
//
// See crate::tests::description_lists::sourcepos.
let list = match container.last_child() {
Some(lc) if node_matches!(lc, NodeValue::DescriptionList) => {
reopen_ast_nodes(lc);
lc
}
_ => self.add_child(
container,
NodeValue::DescriptionList,
self.first_nonspace + 1,
),
_ => {
let list = self.add_child(
container,
NodeValue::DescriptionList,
self.first_nonspace + 1,
);
list.data.borrow_mut().sourcepos.start = last_child_sourcepos.start;
list
}
};

let metadata = NodeDescriptionItem {
Expand All @@ -1369,6 +1388,7 @@ impl<'a, 'o, 'c> Parser<'a, 'o, 'c> {
NodeValue::DescriptionItem(metadata),
self.first_nonspace + 1,
);
item.data.borrow_mut().sourcepos.start = last_child_sourcepos.start;
let term = self.add_child(item, NodeValue::DescriptionTerm, self.first_nonspace + 1);
let details =
self.add_child(item, NodeValue::DescriptionDetails, self.first_nonspace + 1);
Expand Down
83 changes: 66 additions & 17 deletions src/tests/description_lists.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,20 +57,69 @@ fn description_lists() {
);
}

// #[test]
// fn sourcepos() {
// // So much work to do here still.
// assert_ast_match!(
// [extension.description_lists],
// "ta\n"
// "\n"
// ": da\n"
// "\n"
// "t*b*\n"
// "\n"
// ": d_b_\n",
// (document (1:1-1:1) [

// ])
// );
// }
#[test]
fn sourcepos() {
// TODO There's plenty of work to do here still. The test currently represents
// how things *are* -- see comments for what should be different.
// See partner comment in crate::parser::Parser::parse_desc_list_details.
assert_ast_match!(
[extension.description_lists],
"ta\n"
"\n"
": da\n"
"\n"
"t*b*\n"
"\n"
": d*b*\n"
"\n"
"tc\n"
"\n"
": dc\n",
(document (1:1-11:4) [
(description_list (1:1-11:4) [
(description_item (1:1-4:0) [ // (description_item (1:1-3:4) [
(description_term (3:1-3:0) [ // (description_term (1:1-1:2) [
(paragraph (1:1-1:2) [
(text (1:1-1:2) "ta")
])
])
(description_details (3:1-4:0) [ // (description_details (3:1-3:4) [
(paragraph (3:3-3:4) [
(text (3:3-3:4) "da")
])
])
])
(description_item (5:1-8:0) [ // (description_item (5:1-7:6) [
(description_term (7:1-7:0) [ // (description_term (5:1-5:4) [
(paragraph (5:1-5:4) [
(text (5:1-5:1) "t")
(emph (5:2-5:4) [
(text (5:3-5:3) "b")
])
])
])
(description_details (7:1-8:0) [ // (description_details (7:1-7:6) [
(paragraph (7:3-7:6) [
(text (7:3-7:3) "d")
(emph (7:4-7:6) [
(text (7:5-7:5) "b")
])
])
])
])
(description_item (9:1-11:4) [
(description_term (11:1-11:0) [ // (description_term (9:1-11:4) [
(paragraph (9:1-9:2) [
(text (9:1-9:2) "tc")
])
])
(description_details (11:1-11:4) [
(paragraph (11:3-11:4) [
(text (11:3-11:4) "dc")
])
])
])
])
])
);
}

0 comments on commit e186adc

Please sign in to comment.