Create structure for entities.
This commit is contained in:
parent
2966b91a09
commit
21f46d09e6
@ -13,6 +13,7 @@ use crate::parser::DocumentElement;
|
||||
use crate::parser::Drawer;
|
||||
use crate::parser::DynamicBlock;
|
||||
use crate::parser::Element;
|
||||
use crate::parser::Entity;
|
||||
use crate::parser::ExampleBlock;
|
||||
use crate::parser::ExportBlock;
|
||||
use crate::parser::FixedWidthArea;
|
||||
@ -154,6 +155,7 @@ fn compare_object<'s>(
|
||||
Object::PlainLink(obj) => compare_plain_link(source, emacs, obj),
|
||||
Object::AngleLink(obj) => compare_angle_link(source, emacs, obj),
|
||||
Object::OrgMacro(obj) => compare_org_macro(source, emacs, obj),
|
||||
Object::Entity(obj) => compare_entity(source, emacs, obj),
|
||||
}
|
||||
}
|
||||
|
||||
@ -1238,3 +1240,26 @@ fn compare_org_macro<'s>(
|
||||
children: Vec::new(),
|
||||
})
|
||||
}
|
||||
|
||||
fn compare_entity<'s>(
|
||||
source: &'s str,
|
||||
emacs: &'s Token<'s>,
|
||||
rust: &'s Entity<'s>,
|
||||
) -> Result<DiffResult, Box<dyn std::error::Error>> {
|
||||
let mut this_status = DiffStatus::Good;
|
||||
let emacs_name = "entity";
|
||||
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(),
|
||||
})
|
||||
}
|
||||
|
@ -7,6 +7,7 @@ mod drawer;
|
||||
mod dynamic_block;
|
||||
mod element;
|
||||
mod element_parser;
|
||||
mod entity;
|
||||
mod exiting;
|
||||
mod fixed_width_area;
|
||||
mod footnote_definition;
|
||||
@ -70,6 +71,7 @@ pub use lesser_element::VerseBlock;
|
||||
pub use object::AngleLink;
|
||||
pub use object::Bold;
|
||||
pub use object::Code;
|
||||
pub use object::Entity;
|
||||
pub use object::Italic;
|
||||
pub use object::Object;
|
||||
pub use object::OrgMacro;
|
||||
|
@ -15,6 +15,7 @@ pub enum Object<'s> {
|
||||
PlainLink(PlainLink<'s>),
|
||||
AngleLink(AngleLink<'s>),
|
||||
OrgMacro(OrgMacro<'s>),
|
||||
Entity(Entity<'s>),
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq)]
|
||||
@ -96,6 +97,12 @@ pub struct OrgMacro<'s> {
|
||||
pub macro_args: Vec<&'s str>,
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq)]
|
||||
pub struct Entity<'s> {
|
||||
pub source: &'s str,
|
||||
pub entity_name: &'s str,
|
||||
}
|
||||
|
||||
impl<'s> Source<'s> for Object<'s> {
|
||||
fn get_source(&'s self) -> &'s str {
|
||||
match self {
|
||||
@ -112,6 +119,7 @@ impl<'s> Source<'s> for Object<'s> {
|
||||
Object::PlainLink(obj) => obj.source,
|
||||
Object::AngleLink(obj) => obj.source,
|
||||
Object::OrgMacro(obj) => obj.source,
|
||||
Object::Entity(obj) => obj.source,
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -187,3 +195,9 @@ impl<'s> Source<'s> for OrgMacro<'s> {
|
||||
self.source
|
||||
}
|
||||
}
|
||||
|
||||
impl<'s> Source<'s> for Entity<'s> {
|
||||
fn get_source(&'s self) -> &'s str {
|
||||
self.source
|
||||
}
|
||||
}
|
||||
|
@ -8,6 +8,7 @@ use super::regular_link::regular_link;
|
||||
use super::Context;
|
||||
use crate::error::Res;
|
||||
use crate::parser::angle_link::angle_link;
|
||||
use crate::parser::entity::entity;
|
||||
use crate::parser::object::Object;
|
||||
use crate::parser::org_macro::org_macro;
|
||||
use crate::parser::plain_link::plain_link;
|
||||
@ -20,10 +21,11 @@ pub fn standard_set_object<'r, 's>(
|
||||
context: Context<'r, 's>,
|
||||
input: &'s str,
|
||||
) -> Res<&'s str, Object<'s>> {
|
||||
// TODO: add entities, LaTeX fragments, export snippets, 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.
|
||||
// TODO: LaTeX fragments, export snippets, 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)?;
|
||||
|
||||
alt((
|
||||
map(parser_with_context!(entity)(context), Object::Entity),
|
||||
map(parser_with_context!(radio_link)(context), Object::RadioLink),
|
||||
map(
|
||||
parser_with_context!(radio_target)(context),
|
||||
@ -46,10 +48,11 @@ pub fn minimal_set_object<'r, 's>(
|
||||
context: Context<'r, 's>,
|
||||
input: &'s str,
|
||||
) -> Res<&'s str, Object<'s>> {
|
||||
// TODO: add entities, LaTeX fragments, superscripts and subscripts
|
||||
// TODO: LaTeX fragments, superscripts and subscripts
|
||||
not(|i| context.check_exit_matcher(i))(input)?;
|
||||
|
||||
alt((
|
||||
map(parser_with_context!(entity)(context), Object::Entity),
|
||||
parser_with_context!(text_markup)(context),
|
||||
map(parser_with_context!(plain_text)(context), Object::PlainText),
|
||||
))(input)
|
||||
@ -62,6 +65,7 @@ pub fn any_object_except_plain_text<'r, 's>(
|
||||
) -> Res<&'s str, Object<'s>> {
|
||||
// Used for exit matchers so this does not check exit matcher condition.
|
||||
alt((
|
||||
map(parser_with_context!(entity)(context), Object::Entity),
|
||||
map(parser_with_context!(radio_link)(context), Object::RadioLink),
|
||||
map(
|
||||
parser_with_context!(radio_target)(context),
|
||||
|
@ -52,70 +52,7 @@ impl<'r, 's> Token<'r, 's> {
|
||||
Object::PlainLink(_) => Box::new(std::iter::empty()),
|
||||
Object::AngleLink(_) => Box::new(std::iter::empty()),
|
||||
Object::OrgMacro(_) => Box::new(std::iter::empty()),
|
||||
},
|
||||
Token::Element(elem) => match elem {
|
||||
Element::Paragraph(inner) => Box::new(inner.children.iter().map(Token::Object)),
|
||||
Element::PlainList(inner) => {
|
||||
Box::new(inner.children.iter().map(Token::PlainListItem))
|
||||
}
|
||||
Element::GreaterBlock(inner) => Box::new(inner.children.iter().map(Token::Element)),
|
||||
Element::DynamicBlock(inner) => Box::new(inner.children.iter().map(Token::Element)),
|
||||
Element::FootnoteDefinition(inner) => {
|
||||
Box::new(inner.children.iter().map(Token::Element))
|
||||
}
|
||||
Element::Comment(_) => Box::new(std::iter::empty()),
|
||||
Element::Drawer(inner) => Box::new(inner.children.iter().map(Token::Element)),
|
||||
Element::PropertyDrawer(_) => Box::new(std::iter::empty()),
|
||||
Element::Table(inner) => Box::new(inner.children.iter().map(Token::TableRow)),
|
||||
Element::VerseBlock(inner) => Box::new(inner.children.iter().map(Token::Object)),
|
||||
Element::CommentBlock(_) => Box::new(std::iter::empty()),
|
||||
Element::ExampleBlock(_) => Box::new(std::iter::empty()),
|
||||
Element::ExportBlock(_) => Box::new(std::iter::empty()),
|
||||
Element::SrcBlock(_) => Box::new(std::iter::empty()),
|
||||
Element::Clock(_) => Box::new(std::iter::empty()),
|
||||
Element::DiarySexp(_) => Box::new(std::iter::empty()),
|
||||
Element::Planning(_) => Box::new(std::iter::empty()),
|
||||
Element::FixedWidthArea(_) => Box::new(std::iter::empty()),
|
||||
Element::HorizontalRule(_) => Box::new(std::iter::empty()),
|
||||
Element::Keyword(_) => Box::new(std::iter::empty()),
|
||||
Element::LatexEnvironment(_) => Box::new(std::iter::empty()),
|
||||
},
|
||||
Token::PlainListItem(elem) => Box::new(elem.children.iter().map(Token::Element)),
|
||||
Token::TableRow(elem) => Box::new(elem.children.iter().map(Token::TableCell)),
|
||||
Token::TableCell(elem) => Box::new(elem.children.iter().map(Token::Object)),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn all_tokens_no_order(&self) -> Box<dyn Iterator<Item = Token<'r, 's>> + '_> {
|
||||
match self {
|
||||
Token::Document(document) => Box::new(
|
||||
document
|
||||
.zeroth_section
|
||||
.iter()
|
||||
.map(Token::Section)
|
||||
.chain(document.children.iter().map(Token::Heading)),
|
||||
),
|
||||
Token::Heading(heading) => Box::new(heading.title.iter().map(Token::Object).chain(
|
||||
heading.children.iter().map(|de| match de {
|
||||
DocumentElement::Heading(ref obj) => Token::Heading(obj),
|
||||
DocumentElement::Section(ref obj) => Token::Section(obj),
|
||||
}),
|
||||
)),
|
||||
Token::Section(section) => Box::new(section.children.iter().map(Token::Element)),
|
||||
Token::Object(obj) => match obj {
|
||||
Object::Bold(inner) => Box::new(inner.children.iter().map(Token::Object)),
|
||||
Object::Italic(inner) => Box::new(inner.children.iter().map(Token::Object)),
|
||||
Object::Underline(inner) => Box::new(inner.children.iter().map(Token::Object)),
|
||||
Object::StrikeThrough(inner) => Box::new(inner.children.iter().map(Token::Object)),
|
||||
Object::Code(_) => Box::new(std::iter::empty()),
|
||||
Object::Verbatim(_) => Box::new(std::iter::empty()),
|
||||
Object::PlainText(_) => Box::new(std::iter::empty()),
|
||||
Object::RegularLink(_) => Box::new(std::iter::empty()),
|
||||
Object::RadioLink(inner) => Box::new(inner.children.iter().map(Token::Object)),
|
||||
Object::RadioTarget(inner) => Box::new(inner.children.iter().map(Token::Object)),
|
||||
Object::PlainLink(_) => Box::new(std::iter::empty()),
|
||||
Object::AngleLink(_) => Box::new(std::iter::empty()),
|
||||
Object::OrgMacro(_) => Box::new(std::iter::empty()),
|
||||
Object::Entity(_) => Box::new(std::iter::empty()),
|
||||
},
|
||||
Token::Element(elem) => match elem {
|
||||
Element::Paragraph(inner) => Box::new(inner.children.iter().map(Token::Object)),
|
||||
|
Loading…
Reference in New Issue
Block a user