Make plain text exit condition not an exit matcher.
I think this condition needs to not exist deeper down the tree.
This commit is contained in:
parent
b2ee44ec09
commit
bc8e640574
@ -1,30 +1,30 @@
|
||||
use nom::branch::alt;
|
||||
use nom::character::complete::anychar;
|
||||
use nom::combinator::peek;
|
||||
use nom::combinator::recognize;
|
||||
use nom::combinator::verify;
|
||||
use nom::multi::many_till;
|
||||
|
||||
use super::object::PlainText;
|
||||
use super::Context;
|
||||
use crate::error::CustomError;
|
||||
use crate::error::MyError;
|
||||
use crate::error::Res;
|
||||
use crate::parser::exiting::ExitClass;
|
||||
use crate::parser::object_parser::any_object_except_plain_text;
|
||||
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::text_until_exit;
|
||||
use crate::parser::util::exit_matcher_parser;
|
||||
|
||||
#[tracing::instrument(ret, level = "debug")]
|
||||
pub fn plain_text<'r, 's>(context: Context<'r, 's>, input: &'s str) -> Res<&'s str, PlainText<'s>> {
|
||||
if input.len() == 0 {
|
||||
return Err(nom::Err::Error(CustomError::MyError(MyError(
|
||||
"Zero input length to plain_text.",
|
||||
))));
|
||||
}
|
||||
let parser_context =
|
||||
context.with_additional_node(ContextElement::ExitMatcherNode(ExitMatcherNode {
|
||||
class: ExitClass::Beta,
|
||||
exit_matcher: &plain_text_end,
|
||||
}));
|
||||
let (remaining, source) = text_until_exit(&parser_context, input)?;
|
||||
let (remaining, source) = recognize(verify(
|
||||
many_till(
|
||||
anychar,
|
||||
peek(alt((
|
||||
parser_with_context!(exit_matcher_parser)(context),
|
||||
parser_with_context!(plain_text_end)(context),
|
||||
))),
|
||||
),
|
||||
|(children, _exit_contents)| !children.is_empty(),
|
||||
))(input)?;
|
||||
|
||||
Ok((remaining, PlainText { source }))
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user