Fix counting brackets in inline source block.

This commit is contained in:
Tom Alexander 2023-07-21 23:14:52 -04:00
parent e8979513aa
commit 0b41e12424
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE
4 changed files with 31 additions and 9 deletions

View File

@ -0,0 +1,2 @@
before src_foo{ipsum} after
src_bar[lorem]{ipsum}

View File

@ -1422,7 +1422,7 @@ fn compare_inline_source_block<'s>(
rust: &'s InlineSourceBlock<'s>, rust: &'s InlineSourceBlock<'s>,
) -> Result<DiffResult, Box<dyn std::error::Error>> { ) -> Result<DiffResult, Box<dyn std::error::Error>> {
let mut this_status = DiffStatus::Good; let mut this_status = DiffStatus::Good;
let emacs_name = "inline-source-block"; let emacs_name = "inline-src-block";
if assert_name(emacs, emacs_name).is_err() { if assert_name(emacs, emacs_name).is_err() {
this_status = DiffStatus::Bad; this_status = DiffStatus::Bad;
} }

View File

@ -8,6 +8,7 @@ use nom::combinator::opt;
use nom::combinator::recognize; use nom::combinator::recognize;
use nom::combinator::verify; use nom::combinator::verify;
use nom::multi::many_till; use nom::multi::many_till;
use tracing::span;
use super::Context; use super::Context;
use crate::error::CustomError; use crate::error::CustomError;
@ -61,7 +62,7 @@ fn header<'r, 's>(context: Context<'r, 's>, input: &'s str) -> Res<&'s str, &'s
let parser_context = context let parser_context = context
.with_additional_node(ContextElement::InlineSourceBlockBracket( .with_additional_node(ContextElement::InlineSourceBlockBracket(
InlineSourceBlockBracket { InlineSourceBlockBracket {
position: input, position: remaining,
depth: 0, depth: 0,
}, },
)) ))
@ -115,7 +116,7 @@ fn body<'r, 's>(context: Context<'r, 's>, input: &'s str) -> Res<&'s str, &'s st
let parser_context = context let parser_context = context
.with_additional_node(ContextElement::InlineSourceBlockBracket( .with_additional_node(ContextElement::InlineSourceBlockBracket(
InlineSourceBlockBracket { InlineSourceBlockBracket {
position: input, position: remaining,
depth: 0, depth: 0,
}, },
)) ))
@ -128,7 +129,15 @@ fn body<'r, 's>(context: Context<'r, 's>, input: &'s str) -> Res<&'s str, &'s st
anychar, anychar,
parser_with_context!(exit_matcher_parser)(&parser_context), parser_with_context!(exit_matcher_parser)(&parser_context),
))(remaining)?; ))(remaining)?;
let (remaining, _) = tag("}")(remaining)?; let (remaining, _) = {
let span = span!(
tracing::Level::DEBUG,
"outside end body",
remaining = remaining
);
let _enter = span.enter();
tag("}")(remaining)?
};
Ok((remaining, body_contents)) Ok((remaining, body_contents))
} }
@ -152,10 +161,20 @@ fn body_end<'r, 's>(context: Context<'r, 's>, input: &'s str) -> Res<&'s str, &'
_ => {} _ => {}
} }
} }
if current_depth == 0 { {
let close_bracket = tag::<&str, &str, CustomError<&str>>("}")(input); let span = span!(
if close_bracket.is_ok() { tracing::Level::DEBUG,
return close_bracket; "inside end body",
remaining = input,
current_depth = current_depth
);
let _enter = span.enter();
if current_depth == 0 {
let close_bracket = tag::<&str, &str, CustomError<&str>>("}")(input);
if close_bracket.is_ok() {
return close_bracket;
}
} }
} }

View File

@ -1 +1,2 @@
[cite/a/b-_/foo:globalprefix;keyprefix @foo keysuffix;globalsuffix] before src_foo{ipsum} after
src_bar[lorem]{ipsum}