Modernize the verse block parser.
This commit is contained in:
parent
dbb04dcba6
commit
1006576a69
@ -20,6 +20,8 @@ use crate::parser::lesser_element::ExampleBlock;
|
||||
use crate::parser::lesser_element::ExportBlock;
|
||||
use crate::parser::lesser_element::SrcBlock;
|
||||
use crate::parser::lesser_element::VerseBlock;
|
||||
use crate::parser::object::Object;
|
||||
use crate::parser::object::PlainText;
|
||||
use crate::parser::object_parser::standard_set_object;
|
||||
use crate::parser::parser_context::ContextElement;
|
||||
use crate::parser::parser_context::ExitMatcherNode;
|
||||
@ -36,19 +38,10 @@ pub fn verse_block<'r, 's>(
|
||||
context: Context<'r, 's>,
|
||||
input: &'s str,
|
||||
) -> Res<&'s str, VerseBlock<'s>> {
|
||||
start_of_line(context, input)?;
|
||||
let (remaining, _leading_whitespace) = space0(input)?;
|
||||
let (remaining, (_begin, name)) = tuple((
|
||||
tag_no_case("#+begin_"),
|
||||
verify(name, |name: &str| match name.to_lowercase().as_str() {
|
||||
"comment" | "example" | "export" | "src" | "verse" => true,
|
||||
_ => false,
|
||||
}),
|
||||
))(remaining)?;
|
||||
|
||||
let (remaining, name) = lesser_block_begin("verse")(context, input)?;
|
||||
let (remaining, parameters) = opt(tuple((space1, data)))(remaining)?;
|
||||
let (remaining, _nl) = line_ending(remaining)?;
|
||||
let lesser_block_end_specialized = lesser_block_end(name);
|
||||
let lesser_block_end_specialized = lesser_block_end("verse");
|
||||
let parser_context = context
|
||||
.with_additional_node(ContextElement::ConsumeTrailingWhitespace(true))
|
||||
.with_additional_node(ContextElement::Context("lesser block"))
|
||||
@ -65,7 +58,10 @@ pub fn verse_block<'r, 's>(
|
||||
let exit_matcher = parser_with_context!(exit_matcher_parser)(&parser_context);
|
||||
// Check for a completely empty block
|
||||
let (remaining, children) = match consumed(many_till(blank_line, exit_matcher))(remaining) {
|
||||
Ok((remaining, (whitespace, (_children, _exit_contents)))) => todo!(),
|
||||
Ok((remaining, (whitespace, (_children, _exit_contents)))) => (
|
||||
remaining,
|
||||
vec![Object::PlainText(PlainText { source: whitespace })],
|
||||
),
|
||||
Err(_) => {
|
||||
let (remaining, (children, _exit_contents)) =
|
||||
many_till(object_matcher, exit_matcher)(remaining)?;
|
||||
|
Loading…
Reference in New Issue
Block a user