Initial implementation for citations.

This implementation definitely has bugs and is completely untested at this point. I'm just committing the initial "assume everything works" version before I did into debugging and fixing.
This commit is contained in:
Tom Alexander
2023-07-21 17:52:18 -04:00
parent e24b413cd0
commit 6b47a6c6c3
2 changed files with 181 additions and 7 deletions

View File

@@ -30,7 +30,7 @@ pub fn citation_reference<'r, 's>(
input: &'s str,
) -> Res<&'s str, CitationReference<'s>> {
let (remaining, _prefix) = parser_with_context!(key_prefix)(context)(input)?;
let (remaining, _key) = parser_with_context!(key)(context)(remaining)?;
let (remaining, _key) = parser_with_context!(citation_reference_key)(context)(remaining)?;
let (remaining, _suffix) = parser_with_context!(key_suffix)(context)(remaining)?;
let source = get_consumed(input, remaining);
@@ -38,7 +38,10 @@ pub fn citation_reference<'r, 's>(
}
#[tracing::instrument(ret, level = "debug")]
fn key<'r, 's>(context: Context<'r, 's>, input: &'s str) -> Res<&'s str, &'s str> {
pub fn citation_reference_key<'r, 's>(
context: Context<'r, 's>,
input: &'s str,
) -> Res<&'s str, &'s str> {
let (remaining, source) = recognize(tuple((
tag("@"),
many1(verify(
@@ -99,7 +102,7 @@ fn key_suffix<'r, 's>(context: Context<'r, 's>, input: &'s str) -> Res<&'s str,
}
#[tracing::instrument(ret, level = "debug")]
fn get_bracket_depth<'r, 's>(context: Context<'r, 's>) -> Option<&'r CitationBracket<'s>> {
pub fn get_bracket_depth<'r, 's>(context: Context<'r, 's>) -> Option<&'r CitationBracket<'s>> {
for node in context.iter() {
match node.get_data() {
ContextElement::CitationBracket(depth) => return Some(depth),
@@ -135,7 +138,10 @@ fn key_prefix_end<'r, 's>(context: Context<'r, 's>, input: &'s str) -> Res<&'s s
return close_bracket;
}
}
alt((tag(";"), recognize(parser_with_context!(key)(context))))(input)
alt((
tag(";"),
recognize(parser_with_context!(citation_reference_key)(context)),
))(input)
}
#[tracing::instrument(ret, level = "debug")]