Merge branch 'greater_block_properties'
Some checks failed
rustfmt Build rustfmt has succeeded
rust-build Build rust-build has failed
rust-test Build rust-test has succeeded
rust-foreign-document-test Build rust-foreign-document-test has succeeded

This commit is contained in:
Tom Alexander 2023-10-02 22:37:11 -04:00
commit 590e7fba0e
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE
11 changed files with 285 additions and 62 deletions

View File

@ -0,0 +1,3 @@
#+begin_defun foo bar baz
lorem
#+end_defun

View File

@ -17,6 +17,7 @@ use crate::types::AngleLink;
use crate::types::AstNode; use crate::types::AstNode;
use crate::types::BabelCall; use crate::types::BabelCall;
use crate::types::Bold; use crate::types::Bold;
use crate::types::CenterBlock;
use crate::types::CheckboxType; use crate::types::CheckboxType;
use crate::types::Citation; use crate::types::Citation;
use crate::types::CitationReference; use crate::types::CitationReference;
@ -40,7 +41,6 @@ use crate::types::FixedWidthArea;
use crate::types::FootnoteDefinition; use crate::types::FootnoteDefinition;
use crate::types::FootnoteReference; use crate::types::FootnoteReference;
use crate::types::GetStandardProperties; use crate::types::GetStandardProperties;
use crate::types::GreaterBlock;
use crate::types::Heading; use crate::types::Heading;
use crate::types::HorizontalRule; use crate::types::HorizontalRule;
use crate::types::Hour; use crate::types::Hour;
@ -69,12 +69,14 @@ use crate::types::PlainText;
use crate::types::Planning; use crate::types::Planning;
use crate::types::PriorityCookie; use crate::types::PriorityCookie;
use crate::types::PropertyDrawer; use crate::types::PropertyDrawer;
use crate::types::QuoteBlock;
use crate::types::RadioLink; use crate::types::RadioLink;
use crate::types::RadioTarget; use crate::types::RadioTarget;
use crate::types::RegularLink; use crate::types::RegularLink;
use crate::types::RepeaterType; use crate::types::RepeaterType;
use crate::types::RepeaterWarningDelayValueType; use crate::types::RepeaterWarningDelayValueType;
use crate::types::Section; use crate::types::Section;
use crate::types::SpecialBlock;
use crate::types::SrcBlock; use crate::types::SrcBlock;
use crate::types::StandardProperties; use crate::types::StandardProperties;
use crate::types::StatisticsCookie; use crate::types::StatisticsCookie;
@ -329,7 +331,9 @@ fn compare_ast_node<'b, 's>(
AstNode::Paragraph(node) => compare_paragraph(source, emacs, node), AstNode::Paragraph(node) => compare_paragraph(source, emacs, node),
AstNode::PlainList(node) => compare_plain_list(source, emacs, node), AstNode::PlainList(node) => compare_plain_list(source, emacs, node),
AstNode::PlainListItem(node) => compare_plain_list_item(source, emacs, node), AstNode::PlainListItem(node) => compare_plain_list_item(source, emacs, node),
AstNode::GreaterBlock(node) => compare_greater_block(source, emacs, node), AstNode::CenterBlock(node) => compare_center_block(source, emacs, node),
AstNode::QuoteBlock(node) => compare_quote_block(source, emacs, node),
AstNode::SpecialBlock(node) => compare_special_block(source, emacs, node),
AstNode::DynamicBlock(node) => compare_dynamic_block(source, emacs, node), AstNode::DynamicBlock(node) => compare_dynamic_block(source, emacs, node),
AstNode::FootnoteDefinition(node) => compare_footnote_definition(source, emacs, node), AstNode::FootnoteDefinition(node) => compare_footnote_definition(source, emacs, node),
AstNode::Comment(node) => compare_comment(source, emacs, node), AstNode::Comment(node) => compare_comment(source, emacs, node),
@ -1011,17 +1015,90 @@ fn compare_plain_list_item<'b, 's>(
.into()) .into())
} }
fn compare_greater_block<'b, 's>( fn compare_center_block<'b, 's>(
source: &'s str, source: &'s str,
emacs: &'b Token<'s>, emacs: &'b Token<'s>,
rust: &'b GreaterBlock<'s>, rust: &'b CenterBlock<'s>,
) -> Result<DiffEntry<'b, 's>, Box<dyn std::error::Error>> { ) -> Result<DiffEntry<'b, 's>, Box<dyn std::error::Error>> {
let children = emacs.as_list()?; let children = emacs.as_list()?;
let mut child_status = Vec::new(); let mut child_status = Vec::new();
let this_status = DiffStatus::Good; let this_status = DiffStatus::Good;
let message = None; let message = None;
// TODO: Special block compare :type :parameters
// Center and quote block has no additional properties for (emacs_child, rust_child) in children.iter().skip(2).zip(rust.children.iter()) {
child_status.push(compare_ast_node(source, emacs_child, rust_child.into())?);
}
Ok(DiffResult {
status: this_status,
name: rust.get_elisp_name(),
message,
children: child_status,
rust_source: rust.get_source(),
emacs_token: emacs,
}
.into())
}
fn compare_quote_block<'b, 's>(
source: &'s str,
emacs: &'b Token<'s>,
rust: &'b QuoteBlock<'s>,
) -> Result<DiffEntry<'b, 's>, Box<dyn std::error::Error>> {
let children = emacs.as_list()?;
let mut child_status = Vec::new();
let this_status = DiffStatus::Good;
let message = None;
for (emacs_child, rust_child) in children.iter().skip(2).zip(rust.children.iter()) {
child_status.push(compare_ast_node(source, emacs_child, rust_child.into())?);
}
Ok(DiffResult {
status: this_status,
name: rust.get_elisp_name(),
message,
children: child_status,
rust_source: rust.get_source(),
emacs_token: emacs,
}
.into())
}
fn compare_special_block<'b, 's>(
source: &'s str,
emacs: &'b Token<'s>,
rust: &'b SpecialBlock<'s>,
) -> Result<DiffEntry<'b, 's>, Box<dyn std::error::Error>> {
let children = emacs.as_list()?;
let mut child_status = Vec::new();
let mut this_status = DiffStatus::Good;
let mut message = None;
// Compare type
let special_block_type =
get_property_quoted_string(emacs, ":type")?.ok_or("Special blocks should have a name.")?;
if special_block_type != rust.name {
this_status = DiffStatus::Bad;
message = Some(format!(
"Name mismatch (emacs != rust) {:?} != {:?}",
special_block_type, rust.name
));
}
// Compare parameters
let parameters = get_property_quoted_string(emacs, ":parameters")?;
match (parameters.as_ref(), rust.parameters) {
(None, None) => {}
(Some(emacs_parameters), Some(rust_parameters)) if emacs_parameters == rust_parameters => {}
_ => {
this_status = DiffStatus::Bad;
message = Some(format!(
"Parameters mismatch (emacs != rust) {:?} != {:?}",
parameters, rust.parameters
));
}
}
for (emacs_child, rust_child) in children.iter().skip(2).zip(rust.children.iter()) { for (emacs_child, rust_child) in children.iter().skip(2).zip(rust.children.iter()) {
child_status.push(compare_ast_node(source, emacs_child, rust_child.into())?); child_status.push(compare_ast_node(source, emacs_child, rust_child.into())?);

View File

@ -4,6 +4,7 @@ use crate::types::AngleLink;
use crate::types::AstNode; use crate::types::AstNode;
use crate::types::BabelCall; use crate::types::BabelCall;
use crate::types::Bold; use crate::types::Bold;
use crate::types::CenterBlock;
use crate::types::Citation; use crate::types::Citation;
use crate::types::CitationReference; use crate::types::CitationReference;
use crate::types::Clock; use crate::types::Clock;
@ -22,7 +23,6 @@ use crate::types::ExportSnippet;
use crate::types::FixedWidthArea; use crate::types::FixedWidthArea;
use crate::types::FootnoteDefinition; use crate::types::FootnoteDefinition;
use crate::types::FootnoteReference; use crate::types::FootnoteReference;
use crate::types::GreaterBlock;
use crate::types::Heading; use crate::types::Heading;
use crate::types::HorizontalRule; use crate::types::HorizontalRule;
use crate::types::InlineBabelCall; use crate::types::InlineBabelCall;
@ -42,10 +42,12 @@ use crate::types::PlainListItem;
use crate::types::PlainText; use crate::types::PlainText;
use crate::types::Planning; use crate::types::Planning;
use crate::types::PropertyDrawer; use crate::types::PropertyDrawer;
use crate::types::QuoteBlock;
use crate::types::RadioLink; use crate::types::RadioLink;
use crate::types::RadioTarget; use crate::types::RadioTarget;
use crate::types::RegularLink; use crate::types::RegularLink;
use crate::types::Section; use crate::types::Section;
use crate::types::SpecialBlock;
use crate::types::SrcBlock; use crate::types::SrcBlock;
use crate::types::StatisticsCookie; use crate::types::StatisticsCookie;
use crate::types::StrikeThrough; use crate::types::StrikeThrough;
@ -83,7 +85,9 @@ impl<'r, 's> GetElispFact<'s> for AstNode<'r, 's> {
AstNode::Paragraph(inner) => *inner, AstNode::Paragraph(inner) => *inner,
AstNode::PlainList(inner) => *inner, AstNode::PlainList(inner) => *inner,
AstNode::PlainListItem(inner) => *inner, AstNode::PlainListItem(inner) => *inner,
AstNode::GreaterBlock(inner) => *inner, AstNode::CenterBlock(inner) => *inner,
AstNode::QuoteBlock(inner) => *inner,
AstNode::SpecialBlock(inner) => *inner,
AstNode::DynamicBlock(inner) => *inner, AstNode::DynamicBlock(inner) => *inner,
AstNode::FootnoteDefinition(inner) => *inner, AstNode::FootnoteDefinition(inner) => *inner,
AstNode::Comment(inner) => *inner, AstNode::Comment(inner) => *inner,
@ -142,7 +146,9 @@ impl<'s> GetElispFact<'s> for Element<'s> {
match self { match self {
Element::Paragraph(inner) => inner, Element::Paragraph(inner) => inner,
Element::PlainList(inner) => inner, Element::PlainList(inner) => inner,
Element::GreaterBlock(inner) => inner, Element::CenterBlock(inner) => inner,
Element::QuoteBlock(inner) => inner,
Element::SpecialBlock(inner) => inner,
Element::DynamicBlock(inner) => inner, Element::DynamicBlock(inner) => inner,
Element::FootnoteDefinition(inner) => inner, Element::FootnoteDefinition(inner) => inner,
Element::Comment(inner) => inner, Element::Comment(inner) => inner,
@ -230,14 +236,22 @@ impl<'s> ElispFact<'s> for PlainListItem<'s> {
} }
} }
impl<'s> ElispFact<'s> for GreaterBlock<'s> { impl<'s> ElispFact<'s> for CenterBlock<'s> {
fn get_elisp_name<'b>(&'b self) -> Cow<'s, str> { fn get_elisp_name<'b>(&'b self) -> Cow<'s, str> {
match self.name.to_lowercase().as_str() { "center-block".into()
"center" => "center-block".into(),
"quote" => "quote-block".into(),
_ => "special-block".into(),
} }
} }
impl<'s> ElispFact<'s> for QuoteBlock<'s> {
fn get_elisp_name<'b>(&'b self) -> Cow<'s, str> {
"quote-block".into()
}
}
impl<'s> ElispFact<'s> for SpecialBlock<'s> {
fn get_elisp_name<'b>(&'b self) -> Cow<'s, str> {
"special-block".into()
}
} }
impl<'s> ElispFact<'s> for DynamicBlock<'s> { impl<'s> ElispFact<'s> for DynamicBlock<'s> {

View File

@ -24,7 +24,9 @@ impl<'r, 's> Iterator for AllAstNodeIter<'r, 's> {
AstNodeIter::Paragraph(ref mut i) => i.next(), AstNodeIter::Paragraph(ref mut i) => i.next(),
AstNodeIter::PlainList(ref mut i) => i.next(), AstNodeIter::PlainList(ref mut i) => i.next(),
AstNodeIter::PlainListItem(ref mut i) => i.next(), AstNodeIter::PlainListItem(ref mut i) => i.next(),
AstNodeIter::GreaterBlock(ref mut i) => i.next(), AstNodeIter::CenterBlock(ref mut i) => i.next(),
AstNodeIter::QuoteBlock(ref mut i) => i.next(),
AstNodeIter::SpecialBlock(ref mut i) => i.next(),
AstNodeIter::DynamicBlock(ref mut i) => i.next(), AstNodeIter::DynamicBlock(ref mut i) => i.next(),
AstNodeIter::FootnoteDefinition(ref mut i) => i.next(), AstNodeIter::FootnoteDefinition(ref mut i) => i.next(),
AstNodeIter::Comment(ref mut i) => i.next(), AstNodeIter::Comment(ref mut i) => i.next(),

View File

@ -7,6 +7,7 @@ use crate::types::AngleLink;
use crate::types::AstNode; use crate::types::AstNode;
use crate::types::BabelCall; use crate::types::BabelCall;
use crate::types::Bold; use crate::types::Bold;
use crate::types::CenterBlock;
use crate::types::Citation; use crate::types::Citation;
use crate::types::CitationReference; use crate::types::CitationReference;
use crate::types::Clock; use crate::types::Clock;
@ -26,7 +27,6 @@ use crate::types::ExportSnippet;
use crate::types::FixedWidthArea; use crate::types::FixedWidthArea;
use crate::types::FootnoteDefinition; use crate::types::FootnoteDefinition;
use crate::types::FootnoteReference; use crate::types::FootnoteReference;
use crate::types::GreaterBlock;
use crate::types::Heading; use crate::types::Heading;
use crate::types::HorizontalRule; use crate::types::HorizontalRule;
use crate::types::InlineBabelCall; use crate::types::InlineBabelCall;
@ -46,10 +46,12 @@ use crate::types::PlainListItem;
use crate::types::PlainText; use crate::types::PlainText;
use crate::types::Planning; use crate::types::Planning;
use crate::types::PropertyDrawer; use crate::types::PropertyDrawer;
use crate::types::QuoteBlock;
use crate::types::RadioLink; use crate::types::RadioLink;
use crate::types::RadioTarget; use crate::types::RadioTarget;
use crate::types::RegularLink; use crate::types::RegularLink;
use crate::types::Section; use crate::types::Section;
use crate::types::SpecialBlock;
use crate::types::SrcBlock; use crate::types::SrcBlock;
use crate::types::StatisticsCookie; use crate::types::StatisticsCookie;
use crate::types::StrikeThrough; use crate::types::StrikeThrough;
@ -78,7 +80,9 @@ pub(crate) enum AstNodeIter<'r, 's> {
Paragraph(ParagraphIter<'r, 's>), Paragraph(ParagraphIter<'r, 's>),
PlainList(PlainListIter<'r, 's>), PlainList(PlainListIter<'r, 's>),
PlainListItem(PlainListItemIter<'r, 's>), PlainListItem(PlainListItemIter<'r, 's>),
GreaterBlock(GreaterBlockIter<'r, 's>), CenterBlock(CenterBlockIter<'r, 's>),
QuoteBlock(QuoteBlockIter<'r, 's>),
SpecialBlock(SpecialBlockIter<'r, 's>),
DynamicBlock(DynamicBlockIter<'r, 's>), DynamicBlock(DynamicBlockIter<'r, 's>),
FootnoteDefinition(FootnoteDefinitionIter<'r, 's>), FootnoteDefinition(FootnoteDefinitionIter<'r, 's>),
Comment(CommentIter<'r, 's>), Comment(CommentIter<'r, 's>),
@ -140,7 +144,9 @@ impl<'r, 's> AstNodeIter<'r, 's> {
AstNode::Paragraph(inner) => AstNodeIter::Paragraph(inner.into_iter()), AstNode::Paragraph(inner) => AstNodeIter::Paragraph(inner.into_iter()),
AstNode::PlainList(inner) => AstNodeIter::PlainList(inner.into_iter()), AstNode::PlainList(inner) => AstNodeIter::PlainList(inner.into_iter()),
AstNode::PlainListItem(inner) => AstNodeIter::PlainListItem(inner.into_iter()), AstNode::PlainListItem(inner) => AstNodeIter::PlainListItem(inner.into_iter()),
AstNode::GreaterBlock(inner) => AstNodeIter::GreaterBlock(inner.into_iter()), AstNode::CenterBlock(inner) => AstNodeIter::CenterBlock(inner.into_iter()),
AstNode::QuoteBlock(inner) => AstNodeIter::QuoteBlock(inner.into_iter()),
AstNode::SpecialBlock(inner) => AstNodeIter::SpecialBlock(inner.into_iter()),
AstNode::DynamicBlock(inner) => AstNodeIter::DynamicBlock(inner.into_iter()), AstNode::DynamicBlock(inner) => AstNodeIter::DynamicBlock(inner.into_iter()),
AstNode::FootnoteDefinition(inner) => { AstNode::FootnoteDefinition(inner) => {
AstNodeIter::FootnoteDefinition(inner.into_iter()) AstNodeIter::FootnoteDefinition(inner.into_iter())
@ -232,8 +238,18 @@ multi_field_iter!(
std::slice::Iter<'r, Element<'s>> std::slice::Iter<'r, Element<'s>>
); );
children_iter!( children_iter!(
GreaterBlock<'s>, CenterBlock<'s>,
GreaterBlockIter, CenterBlockIter,
std::slice::Iter<'r, Element<'s>>
);
children_iter!(
QuoteBlock<'s>,
QuoteBlockIter,
std::slice::Iter<'r, Element<'s>>
);
children_iter!(
SpecialBlock<'s>,
SpecialBlockIter,
std::slice::Iter<'r, Element<'s>> std::slice::Iter<'r, Element<'s>>
); );
children_iter!( children_iter!(

View File

@ -81,7 +81,7 @@ fn _element<'b, 'g, 'r, 's>(
let (remaining, mut affiliated_keywords) = many0(affiliated_keyword_matcher)(input)?; let (remaining, mut affiliated_keywords) = many0(affiliated_keyword_matcher)(input)?;
let (remaining, mut element) = match alt(( let (remaining, mut element) = match alt((
map(plain_list_matcher, Element::PlainList), map(plain_list_matcher, Element::PlainList),
map(greater_block_matcher, Element::GreaterBlock), greater_block_matcher,
map(dynamic_block_matcher, Element::DynamicBlock), map(dynamic_block_matcher, Element::DynamicBlock),
map(footnote_definition_matcher, Element::FootnoteDefinition), map(footnote_definition_matcher, Element::FootnoteDefinition),
map(comment_matcher, Element::Comment), map(comment_matcher, Element::Comment),

View File

@ -1,6 +1,7 @@
use nom::branch::alt; use nom::branch::alt;
use nom::bytes::complete::is_not; use nom::bytes::complete::is_not;
use nom::bytes::complete::tag_no_case; use nom::bytes::complete::tag_no_case;
use nom::character::complete::anychar;
use nom::character::complete::line_ending; use nom::character::complete::line_ending;
use nom::character::complete::space0; use nom::character::complete::space0;
use nom::character::complete::space1; use nom::character::complete::space1;
@ -8,6 +9,8 @@ use nom::combinator::consumed;
use nom::combinator::eof; use nom::combinator::eof;
use nom::combinator::not; use nom::combinator::not;
use nom::combinator::opt; use nom::combinator::opt;
use nom::combinator::peek;
use nom::combinator::recognize;
use nom::combinator::verify; use nom::combinator::verify;
use nom::multi::many0; use nom::multi::many0;
use nom::multi::many_till; use nom::multi::many_till;
@ -30,17 +33,18 @@ use crate::parser::util::blank_line;
use crate::parser::util::exit_matcher_parser; use crate::parser::util::exit_matcher_parser;
use crate::parser::util::get_consumed; use crate::parser::util::get_consumed;
use crate::parser::util::start_of_line; use crate::parser::util::start_of_line;
use crate::types::CenterBlock;
use crate::types::Element; use crate::types::Element;
use crate::types::GreaterBlock;
use crate::types::Paragraph; use crate::types::Paragraph;
use crate::types::QuoteBlock;
use crate::types::SetSource; use crate::types::SetSource;
use crate::types::SpecialBlock;
#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))]
pub(crate) fn greater_block<'b, 'g, 'r, 's>( pub(crate) fn greater_block<'b, 'g, 'r, 's>(
context: RefContext<'b, 'g, 'r, 's>, context: RefContext<'b, 'g, 'r, 's>,
input: OrgSource<'s>, input: OrgSource<'s>,
) -> Res<OrgSource<'s>, GreaterBlock<'s>> { ) -> Res<OrgSource<'s>, Element<'s>> {
// TODO: Do I need to differentiate between different greater block types.
start_of_line(input)?; start_of_line(input)?;
let (remaining, _leading_whitespace) = space0(input)?; let (remaining, _leading_whitespace) = space0(input)?;
let (remaining, (_begin, name)) = tuple(( let (remaining, (_begin, name)) = tuple((
@ -52,22 +56,98 @@ pub(crate) fn greater_block<'b, 'g, 'r, 's>(
} }
}), }),
))(remaining)?; ))(remaining)?;
let context_name = match Into::<&str>::into(name).to_lowercase().as_str() { let name = Into::<&str>::into(name);
"center" => "center block".to_owned(), let (remaining, element) = match name.to_lowercase().as_str() {
"quote" => "quote block".to_owned(), "center" => center_block(context, remaining, input)?,
name @ _ => format!("special block {}", name), "quote" => quote_block(context, remaining, input)?,
_ => special_block(name)(context, remaining, input)?,
}; };
if in_section(context, context_name.as_str()) { Ok((remaining, element))
}
#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))]
fn center_block<'b, 'g, 'r, 's>(
context: RefContext<'b, 'g, 'r, 's>,
input: OrgSource<'s>,
original_input: OrgSource<'s>,
) -> Res<OrgSource<'s>, Element<'s>> {
let (remaining, (source, children)) =
greater_block_body(context, input, original_input, "center", "center block")?;
Ok((
remaining,
Element::CenterBlock(CenterBlock { source, children }),
))
}
#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))]
fn quote_block<'b, 'g, 'r, 's>(
context: RefContext<'b, 'g, 'r, 's>,
input: OrgSource<'s>,
original_input: OrgSource<'s>,
) -> Res<OrgSource<'s>, Element<'s>> {
let (remaining, (source, children)) =
greater_block_body(context, input, original_input, "quote", "quote block")?;
Ok((
remaining,
Element::QuoteBlock(QuoteBlock { source, children }),
))
}
#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))]
fn special_block<'s>(
name: &'s str,
) -> impl for<'b, 'g, 'r> Fn(
RefContext<'b, 'g, 'r, 's>,
OrgSource<'s>,
OrgSource<'s>,
) -> Res<OrgSource<'s>, Element<'s>>
+ 's {
let context_name = format!("special block {}", name);
move |context, input, original_input| {
_special_block(context, input, original_input, name, context_name.as_str())
}
}
#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))]
fn _special_block<'c, 'b, 'g, 'r, 's>(
context: RefContext<'b, 'g, 'r, 's>,
input: OrgSource<'s>,
original_input: OrgSource<'s>,
name: &'s str,
context_name: &'c str,
) -> Res<OrgSource<'s>, Element<'s>> {
let (remaining, parameters) = opt(tuple((space1, parameters)))(input)?;
let (remaining, (source, children)) =
greater_block_body(context, remaining, original_input, name, context_name)?;
Ok((
remaining,
Element::SpecialBlock(SpecialBlock {
source,
children,
name,
parameters: parameters.map(|(_, parameters)| Into::<&str>::into(parameters)),
}),
))
}
#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))]
fn greater_block_body<'c, 'b, 'g, 'r, 's>(
context: RefContext<'b, 'g, 'r, 's>,
input: OrgSource<'s>,
original_input: OrgSource<'s>,
name: &'c str,
context_name: &'c str,
) -> Res<OrgSource<'s>, (&'s str, Vec<Element<'s>>)> {
if in_section(context, context_name) {
return Err(nom::Err::Error(CustomError::MyError(MyError( return Err(nom::Err::Error(CustomError::MyError(MyError(
"Cannot nest objects of the same element".into(), "Cannot nest objects of the same element".into(),
)))); ))));
} }
let exit_with_name = greater_block_end(name.into()); let exit_with_name = greater_block_end(name);
let (remaining, parameters) = opt(tuple((space1, parameters)))(remaining)?; let (remaining, _nl) = tuple((space0, line_ending))(input)?;
let (remaining, _nl) = line_ending(remaining)?;
let contexts = [ let contexts = [
ContextElement::ConsumeTrailingWhitespace(true), ContextElement::ConsumeTrailingWhitespace(true),
ContextElement::Context(context_name.as_str()), ContextElement::Context(context_name),
ContextElement::ExitMatcherNode(ExitMatcherNode { ContextElement::ExitMatcherNode(ExitMatcherNode {
class: ExitClass::Alpha, class: ExitClass::Alpha,
exit_matcher: &exit_with_name, exit_matcher: &exit_with_name,
@ -76,11 +156,6 @@ pub(crate) fn greater_block<'b, 'g, 'r, 's>(
let parser_context = context.with_additional_node(&contexts[0]); let parser_context = context.with_additional_node(&contexts[0]);
let parser_context = parser_context.with_additional_node(&contexts[1]); let parser_context = parser_context.with_additional_node(&contexts[1]);
let parser_context = parser_context.with_additional_node(&contexts[2]); let parser_context = parser_context.with_additional_node(&contexts[2]);
let parameters = match parameters {
Some((_ws, parameters)) => Some(parameters),
None => None,
};
let element_matcher = parser_with_context!(element(true))(&parser_context); let element_matcher = parser_with_context!(element(true))(&parser_context);
let exit_matcher = parser_with_context!(exit_matcher_parser)(&parser_context); let exit_matcher = parser_with_context!(exit_matcher_parser)(&parser_context);
not(exit_matcher)(remaining)?; not(exit_matcher)(remaining)?;
@ -104,16 +179,8 @@ pub(crate) fn greater_block<'b, 'g, 'r, 's>(
// Not checking if parent exit matcher is causing exit because the greater_block_end matcher asserts we matched a full greater block // Not checking if parent exit matcher is causing exit because the greater_block_end matcher asserts we matched a full greater block
let source = get_consumed(input, remaining); let source = get_consumed(original_input, remaining);
Ok(( Ok((remaining, (Into::<&str>::into(source), children)))
remaining,
GreaterBlock {
source: source.into(),
name: name.into(),
parameters: parameters.map(|val| Into::<&str>::into(val)),
children,
},
))
} }
#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))]
@ -123,7 +190,7 @@ fn name<'s>(input: OrgSource<'s>) -> Res<OrgSource<'s>, OrgSource<'s>> {
#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))]
fn parameters<'s>(input: OrgSource<'s>) -> Res<OrgSource<'s>, OrgSource<'s>> { fn parameters<'s>(input: OrgSource<'s>) -> Res<OrgSource<'s>, OrgSource<'s>> {
is_not("\r\n")(input) recognize(many_till(anychar, peek(tuple((space0, line_ending)))))(input)
} }
fn greater_block_end<'c>(name: &'c str) -> impl ContextMatcher + 'c { fn greater_block_end<'c>(name: &'c str) -> impl ContextMatcher + 'c {

View File

@ -1,4 +1,7 @@
use super::macros::to_ast_node; use super::macros::to_ast_node;
use super::CenterBlock;
use super::QuoteBlock;
use super::SpecialBlock;
use crate::types::AngleLink; use crate::types::AngleLink;
use crate::types::BabelCall; use crate::types::BabelCall;
use crate::types::Bold; use crate::types::Bold;
@ -22,7 +25,6 @@ use crate::types::FixedWidthArea;
use crate::types::FootnoteDefinition; use crate::types::FootnoteDefinition;
use crate::types::FootnoteReference; use crate::types::FootnoteReference;
use crate::types::GetStandardProperties; use crate::types::GetStandardProperties;
use crate::types::GreaterBlock;
use crate::types::Heading; use crate::types::Heading;
use crate::types::HorizontalRule; use crate::types::HorizontalRule;
use crate::types::InlineBabelCall; use crate::types::InlineBabelCall;
@ -69,7 +71,9 @@ pub enum AstNode<'r, 's> {
Paragraph(&'r Paragraph<'s>), Paragraph(&'r Paragraph<'s>),
PlainList(&'r PlainList<'s>), PlainList(&'r PlainList<'s>),
PlainListItem(&'r PlainListItem<'s>), PlainListItem(&'r PlainListItem<'s>),
GreaterBlock(&'r GreaterBlock<'s>), CenterBlock(&'r CenterBlock<'s>),
QuoteBlock(&'r QuoteBlock<'s>),
SpecialBlock(&'r SpecialBlock<'s>),
DynamicBlock(&'r DynamicBlock<'s>), DynamicBlock(&'r DynamicBlock<'s>),
FootnoteDefinition(&'r FootnoteDefinition<'s>), FootnoteDefinition(&'r FootnoteDefinition<'s>),
Comment(&'r Comment<'s>), Comment(&'r Comment<'s>),
@ -136,7 +140,9 @@ impl<'r, 's> From<&'r Element<'s>> for AstNode<'r, 's> {
match value { match value {
Element::Paragraph(inner) => inner.into(), Element::Paragraph(inner) => inner.into(),
Element::PlainList(inner) => inner.into(), Element::PlainList(inner) => inner.into(),
Element::GreaterBlock(inner) => inner.into(), Element::CenterBlock(inner) => inner.into(),
Element::QuoteBlock(inner) => inner.into(),
Element::SpecialBlock(inner) => inner.into(),
Element::DynamicBlock(inner) => inner.into(), Element::DynamicBlock(inner) => inner.into(),
Element::FootnoteDefinition(inner) => inner.into(), Element::FootnoteDefinition(inner) => inner.into(),
Element::Comment(inner) => inner.into(), Element::Comment(inner) => inner.into(),
@ -200,7 +206,9 @@ to_ast_node!(&'r Section<'s>, AstNode::Section);
to_ast_node!(&'r Paragraph<'s>, AstNode::Paragraph); to_ast_node!(&'r Paragraph<'s>, AstNode::Paragraph);
to_ast_node!(&'r PlainList<'s>, AstNode::PlainList); to_ast_node!(&'r PlainList<'s>, AstNode::PlainList);
to_ast_node!(&'r PlainListItem<'s>, AstNode::PlainListItem); to_ast_node!(&'r PlainListItem<'s>, AstNode::PlainListItem);
to_ast_node!(&'r GreaterBlock<'s>, AstNode::GreaterBlock); to_ast_node!(&'r CenterBlock<'s>, AstNode::CenterBlock);
to_ast_node!(&'r QuoteBlock<'s>, AstNode::QuoteBlock);
to_ast_node!(&'r SpecialBlock<'s>, AstNode::SpecialBlock);
to_ast_node!(&'r DynamicBlock<'s>, AstNode::DynamicBlock); to_ast_node!(&'r DynamicBlock<'s>, AstNode::DynamicBlock);
to_ast_node!(&'r FootnoteDefinition<'s>, AstNode::FootnoteDefinition); to_ast_node!(&'r FootnoteDefinition<'s>, AstNode::FootnoteDefinition);
to_ast_node!(&'r Comment<'s>, AstNode::Comment); to_ast_node!(&'r Comment<'s>, AstNode::Comment);
@ -260,7 +268,9 @@ impl<'r, 's> GetStandardProperties<'s> for AstNode<'r, 's> {
AstNode::Paragraph(inner) => *inner, AstNode::Paragraph(inner) => *inner,
AstNode::PlainList(inner) => *inner, AstNode::PlainList(inner) => *inner,
AstNode::PlainListItem(inner) => *inner, AstNode::PlainListItem(inner) => *inner,
AstNode::GreaterBlock(inner) => *inner, AstNode::CenterBlock(inner) => *inner,
AstNode::QuoteBlock(inner) => *inner,
AstNode::SpecialBlock(inner) => *inner,
AstNode::DynamicBlock(inner) => *inner, AstNode::DynamicBlock(inner) => *inner,
AstNode::FootnoteDefinition(inner) => *inner, AstNode::FootnoteDefinition(inner) => *inner,
AstNode::Comment(inner) => *inner, AstNode::Comment(inner) => *inner,

View File

@ -1,6 +1,5 @@
use super::greater_element::DynamicBlock; use super::greater_element::DynamicBlock;
use super::greater_element::FootnoteDefinition; use super::greater_element::FootnoteDefinition;
use super::greater_element::GreaterBlock;
use super::greater_element::PlainList; use super::greater_element::PlainList;
use super::greater_element::PropertyDrawer; use super::greater_element::PropertyDrawer;
use super::greater_element::Table; use super::greater_element::Table;
@ -19,16 +18,21 @@ use super::lesser_element::Paragraph;
use super::lesser_element::Planning; use super::lesser_element::Planning;
use super::lesser_element::SrcBlock; use super::lesser_element::SrcBlock;
use super::lesser_element::VerseBlock; use super::lesser_element::VerseBlock;
use super::CenterBlock;
use super::Drawer; use super::Drawer;
use super::GetStandardProperties; use super::GetStandardProperties;
use super::QuoteBlock;
use super::SetSource; use super::SetSource;
use super::SpecialBlock;
use super::StandardProperties; use super::StandardProperties;
#[derive(Debug)] #[derive(Debug)]
pub enum Element<'s> { pub enum Element<'s> {
Paragraph(Paragraph<'s>), Paragraph(Paragraph<'s>),
PlainList(PlainList<'s>), PlainList(PlainList<'s>),
GreaterBlock(GreaterBlock<'s>), CenterBlock(CenterBlock<'s>),
QuoteBlock(QuoteBlock<'s>),
SpecialBlock(SpecialBlock<'s>),
DynamicBlock(DynamicBlock<'s>), DynamicBlock(DynamicBlock<'s>),
FootnoteDefinition(FootnoteDefinition<'s>), FootnoteDefinition(FootnoteDefinition<'s>),
Comment(Comment<'s>), Comment(Comment<'s>),
@ -56,7 +60,9 @@ impl<'s> SetSource<'s> for Element<'s> {
match self { match self {
Element::Paragraph(obj) => obj.source = source, Element::Paragraph(obj) => obj.source = source,
Element::PlainList(obj) => obj.source = source, Element::PlainList(obj) => obj.source = source,
Element::GreaterBlock(obj) => obj.source = source, Element::CenterBlock(obj) => obj.source = source,
Element::QuoteBlock(obj) => obj.source = source,
Element::SpecialBlock(obj) => obj.source = source,
Element::DynamicBlock(obj) => obj.source = source, Element::DynamicBlock(obj) => obj.source = source,
Element::FootnoteDefinition(obj) => obj.source = source, Element::FootnoteDefinition(obj) => obj.source = source,
Element::Comment(obj) => obj.source = source, Element::Comment(obj) => obj.source = source,
@ -85,7 +91,9 @@ impl<'s> GetStandardProperties<'s> for Element<'s> {
match self { match self {
Element::Paragraph(inner) => inner, Element::Paragraph(inner) => inner,
Element::PlainList(inner) => inner, Element::PlainList(inner) => inner,
Element::GreaterBlock(inner) => inner, Element::CenterBlock(inner) => inner,
Element::QuoteBlock(inner) => inner,
Element::SpecialBlock(inner) => inner,
Element::DynamicBlock(inner) => inner, Element::DynamicBlock(inner) => inner,
Element::FootnoteDefinition(inner) => inner, Element::FootnoteDefinition(inner) => inner,
Element::Comment(inner) => inner, Element::Comment(inner) => inner,

View File

@ -44,7 +44,19 @@ pub enum CheckboxType {
} }
#[derive(Debug)] #[derive(Debug)]
pub struct GreaterBlock<'s> { pub struct CenterBlock<'s> {
pub source: &'s str,
pub children: Vec<Element<'s>>,
}
#[derive(Debug)]
pub struct QuoteBlock<'s> {
pub source: &'s str,
pub children: Vec<Element<'s>>,
}
#[derive(Debug)]
pub struct SpecialBlock<'s> {
pub source: &'s str, pub source: &'s str,
pub name: &'s str, pub name: &'s str,
pub parameters: Option<&'s str>, pub parameters: Option<&'s str>,
@ -110,7 +122,19 @@ impl<'s> StandardProperties<'s> for PlainListItem<'s> {
} }
} }
impl<'s> StandardProperties<'s> for GreaterBlock<'s> { impl<'s> StandardProperties<'s> for CenterBlock<'s> {
fn get_source<'b>(&'b self) -> &'s str {
self.source
}
}
impl<'s> StandardProperties<'s> for QuoteBlock<'s> {
fn get_source<'b>(&'b self) -> &'s str {
self.source
}
}
impl<'s> StandardProperties<'s> for SpecialBlock<'s> {
fn get_source<'b>(&'b self) -> &'s str { fn get_source<'b>(&'b self) -> &'s str {
self.source self.source
} }

View File

@ -18,11 +18,11 @@ pub use document::Section;
pub use document::TodoKeywordType; pub use document::TodoKeywordType;
pub use element::Element; pub use element::Element;
pub use get_standard_properties::GetStandardProperties; pub use get_standard_properties::GetStandardProperties;
pub use greater_element::CenterBlock;
pub use greater_element::CheckboxType; pub use greater_element::CheckboxType;
pub use greater_element::Drawer; pub use greater_element::Drawer;
pub use greater_element::DynamicBlock; pub use greater_element::DynamicBlock;
pub use greater_element::FootnoteDefinition; pub use greater_element::FootnoteDefinition;
pub use greater_element::GreaterBlock;
pub use greater_element::IndentationLevel; pub use greater_element::IndentationLevel;
pub use greater_element::NodeProperty; pub use greater_element::NodeProperty;
pub use greater_element::PlainList; pub use greater_element::PlainList;
@ -31,6 +31,8 @@ pub use greater_element::PlainListItemCounter;
pub use greater_element::PlainListItemPreBlank; pub use greater_element::PlainListItemPreBlank;
pub use greater_element::PlainListType; pub use greater_element::PlainListType;
pub use greater_element::PropertyDrawer; pub use greater_element::PropertyDrawer;
pub use greater_element::QuoteBlock;
pub use greater_element::SpecialBlock;
pub use greater_element::Table; pub use greater_element::Table;
pub use greater_element::TableRow; pub use greater_element::TableRow;
pub use lesser_element::BabelCall; pub use lesser_element::BabelCall;