Compare commits
No commits in common. "4e791b175ef703df130c53a9d6ccffc9c12b8b10" and "8cdca061f8179f610f1becab36d186c1a796efb4" have entirely different histories.
4e791b175e
...
8cdca061f8
@ -1,8 +0,0 @@
|
|||||||
[fn:1] This is a regular footnote definition because it is on an unindented line while lacking a definition inside the brackets.
|
|
||||||
|
|
||||||
|
|
||||||
[fn:1] This is a footnote reference because the line is indented
|
|
||||||
|
|
||||||
[fn:2:This is a footnote reference since it has the definition inside the brackets. This style is referred to as an "inline footnote".]
|
|
||||||
|
|
||||||
[fn::This is a footnote reference since it has the definition inside the brackets. This style is referred to as an "anonymous footnote".]
|
|
@ -19,7 +19,6 @@ use crate::parser::ExportBlock;
|
|||||||
use crate::parser::ExportSnippet;
|
use crate::parser::ExportSnippet;
|
||||||
use crate::parser::FixedWidthArea;
|
use crate::parser::FixedWidthArea;
|
||||||
use crate::parser::FootnoteDefinition;
|
use crate::parser::FootnoteDefinition;
|
||||||
use crate::parser::FootnoteReference;
|
|
||||||
use crate::parser::GreaterBlock;
|
use crate::parser::GreaterBlock;
|
||||||
use crate::parser::Heading;
|
use crate::parser::Heading;
|
||||||
use crate::parser::HorizontalRule;
|
use crate::parser::HorizontalRule;
|
||||||
@ -161,7 +160,6 @@ fn compare_object<'s>(
|
|||||||
Object::Entity(obj) => compare_entity(source, emacs, obj),
|
Object::Entity(obj) => compare_entity(source, emacs, obj),
|
||||||
Object::LatexFragment(obj) => compare_latex_fragment(source, emacs, obj),
|
Object::LatexFragment(obj) => compare_latex_fragment(source, emacs, obj),
|
||||||
Object::ExportSnippet(obj) => compare_export_snippet(source, emacs, obj),
|
Object::ExportSnippet(obj) => compare_export_snippet(source, emacs, obj),
|
||||||
Object::FootnoteReference(obj) => compare_footnote_reference(source, emacs, obj),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1315,26 +1313,3 @@ fn compare_export_snippet<'s>(
|
|||||||
children: Vec::new(),
|
children: Vec::new(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn compare_footnote_reference<'s>(
|
|
||||||
source: &'s str,
|
|
||||||
emacs: &'s Token<'s>,
|
|
||||||
rust: &'s FootnoteReference<'s>,
|
|
||||||
) -> Result<DiffResult, Box<dyn std::error::Error>> {
|
|
||||||
let mut this_status = DiffStatus::Good;
|
|
||||||
let emacs_name = "footnote-reference";
|
|
||||||
if assert_name(emacs, emacs_name).is_err() {
|
|
||||||
this_status = DiffStatus::Bad;
|
|
||||||
}
|
|
||||||
|
|
||||||
if assert_bounds(source, emacs, rust).is_err() {
|
|
||||||
this_status = DiffStatus::Bad;
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(DiffResult {
|
|
||||||
status: this_status,
|
|
||||||
name: emacs_name.to_owned(),
|
|
||||||
message: None,
|
|
||||||
children: Vec::new(),
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
@ -67,7 +67,7 @@ pub fn footnote_definition<'r, 's>(
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[tracing::instrument(ret, level = "debug")]
|
#[tracing::instrument(ret, level = "debug")]
|
||||||
pub fn label<'s>(input: &'s str) -> Res<&'s str, &'s str> {
|
fn label<'s>(input: &'s str) -> Res<&'s str, &'s str> {
|
||||||
alt((
|
alt((
|
||||||
digit1,
|
digit1,
|
||||||
take_while(|c| WORD_CONSTITUENT_CHARACTERS.contains(c) || "-_".contains(c)),
|
take_while(|c| WORD_CONSTITUENT_CHARACTERS.contains(c) || "-_".contains(c)),
|
||||||
|
@ -1,184 +0,0 @@
|
|||||||
use nom::branch::alt;
|
|
||||||
use nom::bytes::complete::tag;
|
|
||||||
use nom::bytes::complete::tag_no_case;
|
|
||||||
use nom::character::complete::space0;
|
|
||||||
use nom::combinator::verify;
|
|
||||||
use nom::multi::many_till;
|
|
||||||
|
|
||||||
use super::parser_context::ContextElement;
|
|
||||||
use super::Context;
|
|
||||||
use crate::error::CustomError;
|
|
||||||
use crate::error::MyError;
|
|
||||||
use crate::error::Res;
|
|
||||||
use crate::parser::exiting::ExitClass;
|
|
||||||
use crate::parser::footnote_definition::label;
|
|
||||||
use crate::parser::object_parser::standard_set_object;
|
|
||||||
use crate::parser::parser_context::ExitMatcherNode;
|
|
||||||
use crate::parser::parser_context::FootnoteReferenceDefinition;
|
|
||||||
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::FootnoteReference;
|
|
||||||
use crate::parser::Object;
|
|
||||||
|
|
||||||
#[tracing::instrument(ret, level = "debug")]
|
|
||||||
pub fn footnote_reference<'r, 's>(
|
|
||||||
context: Context<'r, 's>,
|
|
||||||
input: &'s str,
|
|
||||||
) -> Res<&'s str, FootnoteReference<'s>> {
|
|
||||||
alt((
|
|
||||||
parser_with_context!(anonymous_footnote)(context),
|
|
||||||
parser_with_context!(footnote_reference_only)(context),
|
|
||||||
parser_with_context!(inline_footnote)(context),
|
|
||||||
))(input)
|
|
||||||
}
|
|
||||||
|
|
||||||
#[tracing::instrument(ret, level = "debug")]
|
|
||||||
fn anonymous_footnote<'r, 's>(
|
|
||||||
context: Context<'r, 's>,
|
|
||||||
input: &'s str,
|
|
||||||
) -> Res<&'s str, FootnoteReference<'s>> {
|
|
||||||
let (remaining, _) = tag_no_case("[fn::")(input)?;
|
|
||||||
let parser_context = context
|
|
||||||
.with_additional_node(ContextElement::FootnoteReferenceDefinition(
|
|
||||||
FootnoteReferenceDefinition {
|
|
||||||
position: remaining,
|
|
||||||
depth: 0,
|
|
||||||
},
|
|
||||||
))
|
|
||||||
.with_additional_node(ContextElement::ExitMatcherNode(ExitMatcherNode {
|
|
||||||
class: ExitClass::Beta,
|
|
||||||
exit_matcher: &footnote_definition_end,
|
|
||||||
}));
|
|
||||||
// TODO: I could insert FootnoteReferenceDefinition entries in the context after each matched object to reduce the scanning done for counting brackets which should be more efficient.
|
|
||||||
let (remaining, (children, _exit_contents)) = verify(
|
|
||||||
many_till(
|
|
||||||
parser_with_context!(standard_set_object)(&parser_context),
|
|
||||||
parser_with_context!(exit_matcher_parser)(&parser_context),
|
|
||||||
),
|
|
||||||
|(children, _exit_contents)| !children.is_empty(),
|
|
||||||
)(remaining)?;
|
|
||||||
let (remaining, _) = tag("]")(remaining)?;
|
|
||||||
|
|
||||||
let (remaining, _) = space0(remaining)?;
|
|
||||||
let source = get_consumed(input, remaining);
|
|
||||||
Ok((
|
|
||||||
remaining,
|
|
||||||
FootnoteReference {
|
|
||||||
source,
|
|
||||||
label: None,
|
|
||||||
definition: children,
|
|
||||||
},
|
|
||||||
))
|
|
||||||
}
|
|
||||||
|
|
||||||
#[tracing::instrument(ret, level = "debug")]
|
|
||||||
fn inline_footnote<'r, 's>(
|
|
||||||
context: Context<'r, 's>,
|
|
||||||
input: &'s str,
|
|
||||||
) -> Res<&'s str, FootnoteReference<'s>> {
|
|
||||||
let (remaining, _) = tag_no_case("[fn:")(input)?;
|
|
||||||
let (remaining, label_contents) = label(remaining)?;
|
|
||||||
let (remaining, _) = tag(":")(remaining)?;
|
|
||||||
let parser_context = context
|
|
||||||
.with_additional_node(ContextElement::FootnoteReferenceDefinition(
|
|
||||||
FootnoteReferenceDefinition {
|
|
||||||
position: remaining,
|
|
||||||
depth: 0,
|
|
||||||
},
|
|
||||||
))
|
|
||||||
.with_additional_node(ContextElement::ExitMatcherNode(ExitMatcherNode {
|
|
||||||
class: ExitClass::Beta,
|
|
||||||
exit_matcher: &footnote_definition_end,
|
|
||||||
}));
|
|
||||||
// TODO: I could insert FootnoteReferenceDefinition entries in the context after each matched object to reduce the scanning done for counting brackets which should be more efficient.
|
|
||||||
let (remaining, (children, _exit_contents)) = verify(
|
|
||||||
many_till(
|
|
||||||
parser_with_context!(standard_set_object)(&parser_context),
|
|
||||||
parser_with_context!(exit_matcher_parser)(&parser_context),
|
|
||||||
),
|
|
||||||
|(children, _exit_contents)| !children.is_empty(),
|
|
||||||
)(remaining)?;
|
|
||||||
let (remaining, _) = tag("]")(remaining)?;
|
|
||||||
|
|
||||||
let (remaining, _) = space0(remaining)?;
|
|
||||||
let source = get_consumed(input, remaining);
|
|
||||||
Ok((
|
|
||||||
remaining,
|
|
||||||
FootnoteReference {
|
|
||||||
source,
|
|
||||||
label: Some(label_contents),
|
|
||||||
definition: children,
|
|
||||||
},
|
|
||||||
))
|
|
||||||
}
|
|
||||||
|
|
||||||
#[tracing::instrument(ret, level = "debug")]
|
|
||||||
fn footnote_reference_only<'r, 's>(
|
|
||||||
context: Context<'r, 's>,
|
|
||||||
input: &'s str,
|
|
||||||
) -> Res<&'s str, FootnoteReference<'s>> {
|
|
||||||
let (remaining, _) = tag_no_case("[fn:")(input)?;
|
|
||||||
let (remaining, label_contents) = label(remaining)?;
|
|
||||||
let (remaining, _) = tag("]")(remaining)?;
|
|
||||||
let (remaining, _) = space0(remaining)?;
|
|
||||||
let source = get_consumed(input, remaining);
|
|
||||||
Ok((
|
|
||||||
remaining,
|
|
||||||
FootnoteReference {
|
|
||||||
source,
|
|
||||||
label: Some(label_contents),
|
|
||||||
definition: Vec::with_capacity(0),
|
|
||||||
},
|
|
||||||
))
|
|
||||||
}
|
|
||||||
|
|
||||||
#[tracing::instrument(ret, level = "debug")]
|
|
||||||
fn definition<'s>(input: &'s str) -> Res<&'s str, Vec<Object<'s>>> {
|
|
||||||
Ok((input, vec![]))
|
|
||||||
}
|
|
||||||
|
|
||||||
#[tracing::instrument(ret, level = "debug")]
|
|
||||||
fn footnote_definition_end<'r, 's>(
|
|
||||||
context: Context<'r, 's>,
|
|
||||||
input: &'s str,
|
|
||||||
) -> Res<&'s str, &'s str> {
|
|
||||||
let context_depth = get_bracket_depth(context)
|
|
||||||
.expect("This function should only be called from inside a footnote definition.");
|
|
||||||
let text_since_context_entry = get_consumed(context_depth.position, input);
|
|
||||||
let mut current_depth = context_depth.depth;
|
|
||||||
for c in text_since_context_entry.chars() {
|
|
||||||
match c {
|
|
||||||
'[' => {
|
|
||||||
current_depth += 1;
|
|
||||||
}
|
|
||||||
']' if current_depth == 0 => {
|
|
||||||
panic!("Exceeded footnote reference definition bracket depth.")
|
|
||||||
}
|
|
||||||
']' if current_depth > 0 => {
|
|
||||||
current_depth -= 1;
|
|
||||||
}
|
|
||||||
_ => {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if current_depth > 0 {
|
|
||||||
// Its impossible for the next character to end the footnote reference definition if we're any amount of brackets deep
|
|
||||||
return Err(nom::Err::Error(CustomError::MyError(MyError(
|
|
||||||
"NoFootnoteReferenceDefinitionEnd",
|
|
||||||
))));
|
|
||||||
}
|
|
||||||
tag("]")(input)
|
|
||||||
}
|
|
||||||
|
|
||||||
#[tracing::instrument(ret, level = "debug")]
|
|
||||||
fn get_bracket_depth<'r, 's>(
|
|
||||||
context: Context<'r, 's>,
|
|
||||||
) -> Option<&'r FootnoteReferenceDefinition<'s>> {
|
|
||||||
for node in context.iter() {
|
|
||||||
match node.get_data() {
|
|
||||||
ContextElement::FootnoteReferenceDefinition(depth) => return Some(depth),
|
|
||||||
_ => {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
None
|
|
||||||
}
|
|
@ -12,7 +12,6 @@ mod exiting;
|
|||||||
mod export_snippet;
|
mod export_snippet;
|
||||||
mod fixed_width_area;
|
mod fixed_width_area;
|
||||||
mod footnote_definition;
|
mod footnote_definition;
|
||||||
mod footnote_reference;
|
|
||||||
mod greater_block;
|
mod greater_block;
|
||||||
mod greater_element;
|
mod greater_element;
|
||||||
mod horizontal_rule;
|
mod horizontal_rule;
|
||||||
@ -76,7 +75,6 @@ pub use object::Bold;
|
|||||||
pub use object::Code;
|
pub use object::Code;
|
||||||
pub use object::Entity;
|
pub use object::Entity;
|
||||||
pub use object::ExportSnippet;
|
pub use object::ExportSnippet;
|
||||||
pub use object::FootnoteReference;
|
|
||||||
pub use object::Italic;
|
pub use object::Italic;
|
||||||
pub use object::LatexFragment;
|
pub use object::LatexFragment;
|
||||||
pub use object::Object;
|
pub use object::Object;
|
||||||
|
@ -18,7 +18,6 @@ pub enum Object<'s> {
|
|||||||
Entity(Entity<'s>),
|
Entity(Entity<'s>),
|
||||||
LatexFragment(LatexFragment<'s>),
|
LatexFragment(LatexFragment<'s>),
|
||||||
ExportSnippet(ExportSnippet<'s>),
|
ExportSnippet(ExportSnippet<'s>),
|
||||||
FootnoteReference(FootnoteReference<'s>),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, PartialEq)]
|
#[derive(Debug, PartialEq)]
|
||||||
@ -118,13 +117,6 @@ pub struct ExportSnippet<'s> {
|
|||||||
pub contents: Option<&'s str>,
|
pub contents: Option<&'s str>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, PartialEq)]
|
|
||||||
pub struct FootnoteReference<'s> {
|
|
||||||
pub source: &'s str,
|
|
||||||
pub label: Option<&'s str>,
|
|
||||||
pub definition: Vec<Object<'s>>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'s> Source<'s> for Object<'s> {
|
impl<'s> Source<'s> for Object<'s> {
|
||||||
fn get_source(&'s self) -> &'s str {
|
fn get_source(&'s self) -> &'s str {
|
||||||
match self {
|
match self {
|
||||||
@ -144,7 +136,6 @@ impl<'s> Source<'s> for Object<'s> {
|
|||||||
Object::Entity(obj) => obj.source,
|
Object::Entity(obj) => obj.source,
|
||||||
Object::LatexFragment(obj) => obj.source,
|
Object::LatexFragment(obj) => obj.source,
|
||||||
Object::ExportSnippet(obj) => obj.source,
|
Object::ExportSnippet(obj) => obj.source,
|
||||||
Object::FootnoteReference(obj) => obj.source,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -238,9 +229,3 @@ impl<'s> Source<'s> for ExportSnippet<'s> {
|
|||||||
self.source
|
self.source
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'s> Source<'s> for FootnoteReference<'s> {
|
|
||||||
fn get_source(&'s self) -> &'s str {
|
|
||||||
self.source
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@ -10,7 +10,6 @@ use crate::error::Res;
|
|||||||
use crate::parser::angle_link::angle_link;
|
use crate::parser::angle_link::angle_link;
|
||||||
use crate::parser::entity::entity;
|
use crate::parser::entity::entity;
|
||||||
use crate::parser::export_snippet::export_snippet;
|
use crate::parser::export_snippet::export_snippet;
|
||||||
use crate::parser::footnote_reference::footnote_reference;
|
|
||||||
use crate::parser::latex_fragment::latex_fragment;
|
use crate::parser::latex_fragment::latex_fragment;
|
||||||
use crate::parser::object::Object;
|
use crate::parser::object::Object;
|
||||||
use crate::parser::org_macro::org_macro;
|
use crate::parser::org_macro::org_macro;
|
||||||
@ -24,14 +23,10 @@ pub fn standard_set_object<'r, 's>(
|
|||||||
context: Context<'r, 's>,
|
context: Context<'r, 's>,
|
||||||
input: &'s str,
|
input: &'s str,
|
||||||
) -> Res<&'s str, Object<'s>> {
|
) -> Res<&'s str, Object<'s>> {
|
||||||
// TODO: citations (NOT citation references), inline babel calls, inline source blocks, line breaks, links, macros, targets and radio targets, statistics cookies, subscript and superscript, timestamps, and text markup.
|
// TODO: footnote references, citations (NOT citation references), inline babel calls, inline source blocks, line breaks, links, macros, targets and radio targets, statistics cookies, subscript and superscript, timestamps, and text markup.
|
||||||
not(|i| context.check_exit_matcher(i))(input)?;
|
not(|i| context.check_exit_matcher(i))(input)?;
|
||||||
|
|
||||||
alt((
|
alt((
|
||||||
map(
|
|
||||||
parser_with_context!(footnote_reference)(context),
|
|
||||||
Object::FootnoteReference,
|
|
||||||
),
|
|
||||||
map(
|
map(
|
||||||
parser_with_context!(export_snippet)(context),
|
parser_with_context!(export_snippet)(context),
|
||||||
Object::ExportSnippet,
|
Object::ExportSnippet,
|
||||||
@ -84,10 +79,6 @@ pub fn any_object_except_plain_text<'r, 's>(
|
|||||||
) -> Res<&'s str, Object<'s>> {
|
) -> Res<&'s str, Object<'s>> {
|
||||||
// Used for exit matchers so this does not check exit matcher condition.
|
// Used for exit matchers so this does not check exit matcher condition.
|
||||||
alt((
|
alt((
|
||||||
map(
|
|
||||||
parser_with_context!(footnote_reference)(context),
|
|
||||||
Object::FootnoteReference,
|
|
||||||
),
|
|
||||||
map(
|
map(
|
||||||
parser_with_context!(export_snippet)(context),
|
parser_with_context!(export_snippet)(context),
|
||||||
Object::ExportSnippet,
|
Object::ExportSnippet,
|
||||||
|
@ -141,18 +141,6 @@ pub enum ContextElement<'r, 's> {
|
|||||||
/// org-mode document since text needs to be re-parsed to look for
|
/// org-mode document since text needs to be re-parsed to look for
|
||||||
/// radio links matching the contents of radio targets.
|
/// radio links matching the contents of radio targets.
|
||||||
RadioTarget(Vec<&'r Vec<Object<'s>>>),
|
RadioTarget(Vec<&'r Vec<Object<'s>>>),
|
||||||
|
|
||||||
/// Stores the current bracket depth inside a footnote reference's definition.
|
|
||||||
///
|
|
||||||
/// The definition inside a footnote reference must have balanced
|
|
||||||
/// brackets [] inside the definition, so this stores the amount
|
|
||||||
/// of opening brackets subtracted by the amount of closing
|
|
||||||
/// brackets within the definition.
|
|
||||||
///
|
|
||||||
/// A reference to the position in the string is also included so
|
|
||||||
/// unbalanced brackets can be detected in the middle of an
|
|
||||||
/// object.
|
|
||||||
FootnoteReferenceDefinition(FootnoteReferenceDefinition<'s>),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct ExitMatcherNode<'r> {
|
pub struct ExitMatcherNode<'r> {
|
||||||
@ -160,12 +148,6 @@ pub struct ExitMatcherNode<'r> {
|
|||||||
pub class: ExitClass,
|
pub class: ExitClass,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
|
||||||
pub struct FootnoteReferenceDefinition<'s> {
|
|
||||||
pub position: &'s str,
|
|
||||||
pub depth: usize,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'r> std::fmt::Debug for ExitMatcherNode<'r> {
|
impl<'r> std::fmt::Debug for ExitMatcherNode<'r> {
|
||||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
let mut formatter = f.debug_struct("ExitMatcherNode");
|
let mut formatter = f.debug_struct("ExitMatcherNode");
|
||||||
|
@ -55,9 +55,6 @@ impl<'r, 's> Token<'r, 's> {
|
|||||||
Object::Entity(_) => Box::new(std::iter::empty()),
|
Object::Entity(_) => Box::new(std::iter::empty()),
|
||||||
Object::LatexFragment(_) => Box::new(std::iter::empty()),
|
Object::LatexFragment(_) => Box::new(std::iter::empty()),
|
||||||
Object::ExportSnippet(_) => Box::new(std::iter::empty()),
|
Object::ExportSnippet(_) => Box::new(std::iter::empty()),
|
||||||
Object::FootnoteReference(inner) => {
|
|
||||||
Box::new(inner.definition.iter().map(Token::Object))
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
Token::Element(elem) => match elem {
|
Token::Element(elem) => match elem {
|
||||||
Element::Paragraph(inner) => Box::new(inner.children.iter().map(Token::Object)),
|
Element::Paragraph(inner) => Box::new(inner.children.iter().map(Token::Object)),
|
||||||
|
@ -1 +1,3 @@
|
|||||||
[fn:2:This is a footnote reference since it has the definition inside the brackets. This style is referred to as an "inline footnote".]
|
foo \Delta bar
|
||||||
|
foo \pibar
|
||||||
|
foo \pi{}bar
|
||||||
|
Loading…
x
Reference in New Issue
Block a user