Merge branch 'bold_nesting_fix'
This commit is contained in:
commit
11081f6936
3
org_mode_samples/text_markup/deep_nesting.org
Normal file
3
org_mode_samples/text_markup/deep_nesting.org
Normal file
@ -0,0 +1,3 @@
|
||||
foo *bar /baz *lorem* ipsum/ dolar* alpha
|
||||
|
||||
foo *bar /baz _lorem_ ipsum/ dolar* alpha
|
@ -1,55 +1,31 @@
|
||||
use nom::combinator::not;
|
||||
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::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 mut current_input = input.char_indices();
|
||||
loop {
|
||||
match current_input.next() {
|
||||
Some((offset, _char)) => {
|
||||
let remaining = &input[offset..];
|
||||
let exit_matcher_status = not(|i| parser_context.check_exit_matcher(i))(remaining);
|
||||
if exit_matcher_status.is_err() {
|
||||
if offset == 0 {
|
||||
// If we're at the start of the input, then nothing is plain text, so fire an error for zero-length match.
|
||||
exit_matcher_status?;
|
||||
} else {
|
||||
return Ok((
|
||||
&input[offset..],
|
||||
PlainText {
|
||||
source: &input[..offset],
|
||||
},
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
None => {
|
||||
// We hit the end of the file, so all input must be plain text
|
||||
return Ok((&input[input.len()..], PlainText { source: 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 }))
|
||||
}
|
||||
|
||||
#[tracing::instrument(ret, level = "debug")]
|
||||
|
@ -12,6 +12,7 @@ use nom::combinator::recognize;
|
||||
use nom::combinator::verify;
|
||||
use nom::multi::many_till;
|
||||
use nom::sequence::terminated;
|
||||
use tracing::span;
|
||||
|
||||
use super::Context;
|
||||
use crate::error::CustomError;
|
||||
@ -131,6 +132,16 @@ fn _text_markup_object<'r, 's, 'x>(
|
||||
|(children, _exit_contents)| !children.is_empty(),
|
||||
)(remaining)?;
|
||||
|
||||
{
|
||||
let span = span!(tracing::Level::DEBUG, "Checking parent exit.");
|
||||
let _enter = span.enter();
|
||||
if exit_matcher_parser(context, remaining).is_ok() {
|
||||
return Err(nom::Err::Error(CustomError::MyError(MyError(
|
||||
"Parent exit matcher is triggering.",
|
||||
))));
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: Sometimes its plain text, not objects
|
||||
let (remaining, _close) = text_markup_end_specialized(context, remaining)?;
|
||||
let (remaining, _trailing_whitespace) = space0(remaining)?;
|
||||
@ -168,6 +179,16 @@ fn _text_markup_string<'r, 's, 'x>(
|
||||
|(children, _exit_contents)| !children.is_empty(),
|
||||
))(remaining)?;
|
||||
|
||||
{
|
||||
let span = span!(tracing::Level::DEBUG, "Checking parent exit.");
|
||||
let _enter = span.enter();
|
||||
if exit_matcher_parser(context, remaining).is_ok() {
|
||||
return Err(nom::Err::Error(CustomError::MyError(MyError(
|
||||
"Parent exit matcher is triggering.",
|
||||
))));
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: Sometimes its plain text, not objects
|
||||
let (remaining, _close) = text_markup_end_specialized(context, remaining)?;
|
||||
let (remaining, _trailing_whitespace) = space0(remaining)?;
|
||||
|
@ -1,13 +1,3 @@
|
||||
prologue *goes here* I guess *bold
|
||||
text*
|
||||
foo *bar /baz *lorem* ipsum/ dolar* alpha
|
||||
|
||||
bold*wont* start *or stop*when there is text outside it
|
||||
|
||||
I guess *regular
|
||||
|
||||
text*
|
||||
|
||||
[[foo][foo *bar]] baz* car
|
||||
|
||||
|
||||
*nesting *bold entrances* and* exits
|
||||
foo *bar /baz _lorem_ ipsum/ dolar* alpha
|
||||
|
Loading…
Reference in New Issue
Block a user