Create structure for citations.

This commit is contained in:
Tom Alexander
2023-07-20 00:38:16 -04:00
parent 4e791b175e
commit d5c611674e
6 changed files with 105 additions and 0 deletions

10
src/parser/citation.rs Normal file
View File

@@ -0,0 +1,10 @@
use super::Context;
use crate::error::Res;
use crate::parser::object::Citation;
use crate::parser::util::not_yet_implemented;
#[tracing::instrument(ret, level = "debug")]
pub fn citation<'r, 's>(context: Context<'r, 's>, input: &'s str) -> Res<&'s str, Citation<'s>> {
not_yet_implemented()?;
todo!()
}

View File

@@ -0,0 +1,13 @@
use super::Context;
use crate::error::Res;
use crate::parser::object::CitationReference;
use crate::parser::util::not_yet_implemented;
#[tracing::instrument(ret, level = "debug")]
pub fn citation_reference<'r, 's>(
context: Context<'r, 's>,
input: &'s str,
) -> Res<&'s str, CitationReference<'s>> {
not_yet_implemented()?;
todo!()
}

View File

@@ -1,4 +1,6 @@
mod angle_link;
mod citation;
mod citation_reference;
mod clock;
mod comment;
mod diary_sexp;
@@ -73,6 +75,8 @@ pub use lesser_element::TableCell;
pub use lesser_element::VerseBlock;
pub use object::AngleLink;
pub use object::Bold;
pub use object::Citation;
pub use object::CitationReference;
pub use object::Code;
pub use object::Entity;
pub use object::ExportSnippet;

View File

@@ -19,6 +19,8 @@ pub enum Object<'s> {
LatexFragment(LatexFragment<'s>),
ExportSnippet(ExportSnippet<'s>),
FootnoteReference(FootnoteReference<'s>),
Citation(Citation<'s>),
CitationReference(CitationReference<'s>),
}
#[derive(Debug, PartialEq)]
@@ -125,6 +127,16 @@ pub struct FootnoteReference<'s> {
pub definition: Vec<Object<'s>>,
}
#[derive(Debug, PartialEq)]
pub struct Citation<'s> {
pub source: &'s str,
}
#[derive(Debug, PartialEq)]
pub struct CitationReference<'s> {
pub source: &'s str,
}
impl<'s> Source<'s> for Object<'s> {
fn get_source(&'s self) -> &'s str {
match self {
@@ -145,6 +157,8 @@ impl<'s> Source<'s> for Object<'s> {
Object::LatexFragment(obj) => obj.source,
Object::ExportSnippet(obj) => obj.source,
Object::FootnoteReference(obj) => obj.source,
Object::Citation(obj) => obj.source,
Object::CitationReference(obj) => obj.source,
}
}
}
@@ -244,3 +258,15 @@ impl<'s> Source<'s> for FootnoteReference<'s> {
self.source
}
}
impl<'s> Source<'s> for Citation<'s> {
fn get_source(&'s self) -> &'s str {
self.source
}
}
impl<'s> Source<'s> for CitationReference<'s> {
fn get_source(&'s self) -> &'s str {
self.source
}
}

View File

@@ -58,6 +58,8 @@ impl<'r, 's> Token<'r, 's> {
Object::FootnoteReference(inner) => {
Box::new(inner.definition.iter().map(Token::Object))
}
Object::Citation(_) => Box::new(std::iter::empty()), // TODO: Iterate over children
Object::CitationReference(_) => Box::new(std::iter::empty()), // TODO: Iterate over children
},
Token::Element(elem) => match elem {
Element::Paragraph(inner) => Box::new(inner.children.iter().map(Token::Object)),