Merge branch 'nesting_same_objects'

This commit is contained in:
Tom Alexander 2023-04-18 22:20:52 -04:00
commit fba80f4f7b
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE
7 changed files with 48 additions and 13 deletions

View File

@ -13,17 +13,27 @@ use nom::sequence::tuple;
use super::util::get_consumed;
use super::Context;
use crate::parser::error::CustomError;
use crate::parser::error::MyError;
use crate::parser::error::Res;
use crate::parser::parser_context::ContextElement;
use crate::parser::parser_with_context::parser_with_context;
use crate::parser::util::exit_matcher_parser;
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::Comment;
#[tracing::instrument(ret, level = "debug")]
pub fn comment<'r, 's>(context: Context<'r, 's>, input: &'s str) -> Res<&'s str, Comment<'s>> {
let comment_line_matcher = parser_with_context!(comment_line)(context);
let exit_matcher = parser_with_context!(exit_matcher_parser)(context);
if immediate_in_section(context, "comment") {
return Err(nom::Err::Error(CustomError::MyError(MyError(
"Cannot nest objects of the same element",
))));
}
let parser_context = context.with_additional_node(ContextElement::Context("comment"));
let comment_line_matcher = parser_with_context!(comment_line)(&parser_context);
let exit_matcher = parser_with_context!(exit_matcher_parser)(&parser_context);
let (remaining, first_line) = comment_line_matcher(input)?;
let (remaining, remaining_lines) =
many0(preceded(not(exit_matcher), comment_line_matcher))(remaining)?;

View File

@ -10,6 +10,8 @@ use nom::sequence::tuple;
use super::Context;
use crate::parser::element::element;
use crate::parser::error::CustomError;
use crate::parser::error::MyError;
use crate::parser::error::Res;
use crate::parser::exiting::ExitClass;
use crate::parser::parser_context::ContextElement;
@ -17,6 +19,7 @@ use crate::parser::parser_context::ExitMatcherNode;
use crate::parser::parser_with_context::parser_with_context;
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::util::WORD_CONSTITUENT_CHARACTERS;
@ -24,6 +27,11 @@ use crate::parser::Drawer;
#[tracing::instrument(ret, level = "debug")]
pub fn drawer<'r, 's>(context: Context<'r, 's>, input: &'s str) -> Res<&'s str, Drawer<'s>> {
if immediate_in_section(context, "drawer") {
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)?;
let (remaining, (_open_colon, drawer_name, _close_colon, _new_line)) = tuple((
@ -35,6 +43,7 @@ pub fn drawer<'r, 's>(context: Context<'r, 's>, input: &'s str) -> Res<&'s str,
let parser_context = context
.with_additional_node(ContextElement::ConsumeTrailingWhitespace(true))
.with_additional_node(ContextElement::Context("drawer"))
.with_additional_node(ContextElement::ExitMatcherNode(ExitMatcherNode {
class: ExitClass::Alpha,
exit_matcher: &drawer_end,

View File

@ -2,6 +2,8 @@ use super::error::Res;
use super::util::WORD_CONSTITUENT_CHARACTERS;
use super::Context;
use crate::parser::element::element;
use crate::parser::error::CustomError;
use crate::parser::error::MyError;
use crate::parser::exiting::ExitClass;
use crate::parser::greater_element::FootnoteDefinition;
use crate::parser::parser_context::ContextElement;
@ -10,6 +12,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;
use crate::parser::util::maybe_consume_trailing_whitespace_if_not_exiting;
use crate::parser::util::start_of_line;
@ -30,12 +33,18 @@ pub fn footnote_definition<'r, 's>(
context: Context<'r, 's>,
input: &'s str,
) -> Res<&'s str, FootnoteDefinition<'s>> {
if immediate_in_section(context, "footnote definition") {
return Err(nom::Err::Error(CustomError::MyError(MyError(
"Cannot nest objects of the same element",
))));
}
start_of_line(context, input)?;
// Cannot be indented.
let (remaining, (_lead_in, lbl, _lead_out, _ws)) =
tuple((tag_no_case("[fn:"), label, tag("]"), space0))(input)?;
let parser_context = context
.with_additional_node(ContextElement::ConsumeTrailingWhitespace(true))
.with_additional_node(ContextElement::Context("footnote definition"))
.with_additional_node(ContextElement::ExitMatcherNode(ExitMatcherNode {
class: ExitClass::Alpha,
exit_matcher: &footnote_definition_end,

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,

View File

@ -6,12 +6,15 @@ use nom::multi::many1;
use nom::multi::many_till;
use nom::sequence::tuple;
use crate::parser::error::CustomError;
use crate::parser::error::MyError;
use crate::parser::exiting::ExitClass;
use crate::parser::object::standard_set_object;
use crate::parser::parser_context::ContextElement;
use crate::parser::parser_context::ExitMatcherNode;
use crate::parser::parser_with_context::parser_with_context;
use crate::parser::util::exit_matcher_parser;
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;

View File

@ -35,8 +35,9 @@ use tracing::span;
#[tracing::instrument(ret, level = "debug")]
pub fn plain_list<'r, 's>(context: Context<'r, 's>, input: &'s str) -> Res<&'s str, PlainList<'s>> {
let parser_context =
context.with_additional_node(ContextElement::ExitMatcherNode(ExitMatcherNode {
let parser_context = context
.with_additional_node(ContextElement::Context("plain list"))
.with_additional_node(ContextElement::ExitMatcherNode(ExitMatcherNode {
class: ExitClass::Beta,
exit_matcher: &plain_list_end,
}));

View File

@ -1,10 +1,5 @@
* Headline
before
:candle:
inside
** Headline inside the drawer
the
:firstdrawer:
:seconddrawer:
foo
:end:
:end:
drawer
after