Implement the new fields for table.
Some checks failed
clippy Build clippy has failed
rust-foreign-document-test Build rust-foreign-document-test has failed
rust-build Build rust-build has succeeded
rust-test Build rust-test has failed

This commit is contained in:
Tom Alexander 2023-12-15 17:11:22 -05:00
parent cce9ca87fa
commit 565978225a
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE
3 changed files with 31 additions and 13 deletions

View File

@ -3,6 +3,7 @@ use nom::bytes::complete::is_not;
use nom::bytes::complete::tag;
use nom::character::complete::line_ending;
use nom::character::complete::space0;
use nom::combinator::consumed;
use nom::combinator::not;
use nom::combinator::opt;
use nom::combinator::peek;
@ -67,13 +68,13 @@ where
let org_mode_table_row_matcher = parser_with_context!(org_mode_table_row)(&parser_context);
let exit_matcher = parser_with_context!(exit_matcher_parser)(&parser_context);
let (remaining, (children, _exit_contents)) =
many_till(org_mode_table_row_matcher, exit_matcher)(remaining)?;
let (remaining, (contents, (children, _exit_contents))) =
consumed(many_till(org_mode_table_row_matcher, exit_matcher))(remaining)?;
let (remaining, formulas) =
many0(parser_with_context!(table_formula_keyword)(context))(remaining)?;
let (remaining, _trailing_ws) =
let (remaining, post_blank) =
maybe_consume_trailing_whitespace_if_not_exiting(context, remaining)?;
let source = get_consumed(input, remaining);
@ -87,6 +88,8 @@ where
),
formulas,
children,
contents: Into::<&str>::into(contents),
post_blank: post_blank.map(Into::<&str>::into),
},
))
}
@ -150,6 +153,7 @@ fn org_mode_table_row_rule<'b, 'g, 'r, 's>(
TableRow {
source: source.into(),
children: Vec::new(),
contents: None,
},
))
}
@ -164,8 +168,8 @@ fn org_mode_table_row_regular<'b, 'g, 'r, 's>(
) -> Res<OrgSource<'s>, TableRow<'s>> {
start_of_line(input)?;
let (remaining, _) = tuple((space0, tag("|")))(input)?;
let (remaining, children) =
many1(parser_with_context!(org_mode_table_cell)(context))(remaining)?;
let (remaining, (contents, children)) =
consumed(many1(parser_with_context!(org_mode_table_cell)(context)))(remaining)?;
let (remaining, _tail) = recognize(tuple((space0, org_line_ending)))(remaining)?;
let source = get_consumed(input, remaining);
Ok((
@ -173,6 +177,11 @@ fn org_mode_table_row_regular<'b, 'g, 'r, 's>(
TableRow {
source: source.into(),
children,
contents: if contents.len() > 0 {
Some(Into::<&str>::into(contents))
} else {
None
},
},
))
}
@ -194,12 +203,12 @@ fn org_mode_table_cell<'b, 'g, 'r, 's>(
parser_with_context!(table_cell_set_object)(&parser_context);
let exit_matcher = parser_with_context!(exit_matcher_parser)(&parser_context);
let (remaining, _) = space0(input)?;
let (remaining, (children, _exit_contents)) = verify(
let (remaining, (contents, (children, _exit_contents))) = consumed(verify(
many_till(table_cell_set_object_matcher, exit_matcher),
|(children, exit_contents)| {
!children.is_empty() || Into::<&str>::into(exit_contents).ends_with('|')
},
)(remaining)?;
))(remaining)?;
let (remaining, _tail) = org_mode_table_cell_end(&parser_context, remaining)?;
@ -210,6 +219,7 @@ fn org_mode_table_cell<'b, 'g, 'r, 's>(
TableCell {
source: source.into(),
children,
contents: Into::<&str>::into(contents),
},
))
}

View File

@ -130,12 +130,15 @@ pub struct Table<'s> {
pub affiliated_keywords: AffiliatedKeywords<'s>,
pub formulas: Vec<Keyword<'s>>,
pub children: Vec<TableRow<'s>>,
pub contents: &'s str,
pub post_blank: Option<&'s str>,
}
#[derive(Debug)]
pub struct TableRow<'s> {
pub source: &'s str,
pub children: Vec<TableCell<'s>>,
pub contents: Option<&'s str>,
}
#[derive(Debug)]
@ -322,11 +325,15 @@ impl<'s> StandardProperties<'s> for Table<'s> {
}
fn get_contents<'b>(&'b self) -> Option<&'s str> {
todo!()
Some(self.contents)
}
fn get_post_blank(&self) -> PostBlank {
todo!()
self.post_blank
.map(|text| text.lines().count())
.unwrap_or(0)
.try_into()
.expect("Too much post-blank to fit into a PostBlank.")
}
}
@ -336,11 +343,11 @@ impl<'s> StandardProperties<'s> for TableRow<'s> {
}
fn get_contents<'b>(&'b self) -> Option<&'s str> {
todo!()
self.contents
}
fn get_post_blank(&self) -> PostBlank {
todo!()
0
}
}

View File

@ -42,6 +42,7 @@ pub struct Comment<'s> {
pub struct TableCell<'s> {
pub source: &'s str,
pub children: Vec<Object<'s>>,
pub contents: &'s str,
}
#[derive(Debug)]
@ -257,11 +258,11 @@ impl<'s> StandardProperties<'s> for TableCell<'s> {
}
fn get_contents<'b>(&'b self) -> Option<&'s str> {
todo!()
Some(self.contents)
}
fn get_post_blank(&self) -> PostBlank {
todo!()
0
}
}