Create structure for citations.
This commit is contained in:
parent
4e791b175e
commit
d5c611674e
@ -3,6 +3,8 @@ use super::util::assert_name;
|
||||
use crate::parser::sexp::Token;
|
||||
use crate::parser::AngleLink;
|
||||
use crate::parser::Bold;
|
||||
use crate::parser::Citation;
|
||||
use crate::parser::CitationReference;
|
||||
use crate::parser::Clock;
|
||||
use crate::parser::Code;
|
||||
use crate::parser::Comment;
|
||||
@ -162,6 +164,8 @@ fn compare_object<'s>(
|
||||
Object::LatexFragment(obj) => compare_latex_fragment(source, emacs, obj),
|
||||
Object::ExportSnippet(obj) => compare_export_snippet(source, emacs, obj),
|
||||
Object::FootnoteReference(obj) => compare_footnote_reference(source, emacs, obj),
|
||||
Object::Citation(obj) => compare_citation(source, emacs, obj),
|
||||
Object::CitationReference(obj) => compare_citation_reference(source, emacs, obj),
|
||||
}
|
||||
}
|
||||
|
||||
@ -1338,3 +1342,49 @@ fn compare_footnote_reference<'s>(
|
||||
children: Vec::new(),
|
||||
})
|
||||
}
|
||||
|
||||
fn compare_citation<'s>(
|
||||
source: &'s str,
|
||||
emacs: &'s Token<'s>,
|
||||
rust: &'s Citation<'s>,
|
||||
) -> Result<DiffResult, Box<dyn std::error::Error>> {
|
||||
let mut this_status = DiffStatus::Good;
|
||||
let emacs_name = "citation";
|
||||
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(),
|
||||
})
|
||||
}
|
||||
|
||||
fn compare_citation_reference<'s>(
|
||||
source: &'s str,
|
||||
emacs: &'s Token<'s>,
|
||||
rust: &'s CitationReference<'s>,
|
||||
) -> Result<DiffResult, Box<dyn std::error::Error>> {
|
||||
let mut this_status = DiffStatus::Good;
|
||||
let emacs_name = "citation-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(),
|
||||
})
|
||||
}
|
||||
|
10
src/parser/citation.rs
Normal file
10
src/parser/citation.rs
Normal 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!()
|
||||
}
|
13
src/parser/citation_reference.rs
Normal file
13
src/parser/citation_reference.rs
Normal 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!()
|
||||
}
|
@ -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;
|
||||
|
@ -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
|
||||
}
|
||||
}
|
||||
|
@ -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)),
|
||||
|
Loading…
Reference in New Issue
Block a user