Do not allow elements to immediately nest inside themselves.

Plain list is omitted because they can nest.
This commit is contained in:
Tom Alexander
2023-04-18 22:10:44 -04:00
parent 3a3cee337c
commit 45d0ce17c3
6 changed files with 52 additions and 6 deletions

View File

@@ -13,6 +13,7 @@ use crate::parser::parser_with_context::parser_with_context;
use crate::parser::util::blank_line;
use crate::parser::util::exit_matcher_parser;
use crate::parser::util::get_consumed;
use crate::parser::util::immediate_in_section;
use crate::parser::util::maybe_consume_trailing_whitespace_if_not_exiting;
use crate::parser::util::start_of_line;
use crate::parser::Element;
@@ -35,6 +36,12 @@ pub fn greater_block<'r, 's>(
context: Context<'r, 's>,
input: &'s str,
) -> Res<&'s str, GreaterBlock<'s>> {
// TODO: Do I need to differentiate between different greater block types.
if immediate_in_section(context, "greater block") {
return Err(nom::Err::Error(CustomError::MyError(MyError(
"Cannot nest objects of the same element",
))));
}
start_of_line(context, input)?;
let (remaining, _leading_whitespace) = space0(input)?;
// TODO: Not handling indentation before start of block
@@ -49,6 +56,7 @@ pub fn greater_block<'r, 's>(
let (remaining, _nl) = line_ending(remaining)?;
let parser_context = context
.with_additional_node(ContextElement::ConsumeTrailingWhitespace(true))
.with_additional_node(ContextElement::Context("greater block"))
.with_additional_node(ContextElement::GreaterBlock(name))
.with_additional_node(ContextElement::ExitMatcherNode(ExitMatcherNode {
class: ExitClass::Alpha,