Initial code structure for property drawers.

This commit is contained in:
Tom Alexander 2023-04-19 16:51:00 -04:00
parent fcf1ba4ea6
commit a267f23e0f
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE
5 changed files with 61 additions and 1 deletions

View File

@ -1,7 +1,6 @@
use super::sexp::Token;
use super::util::assert_bounds;
use super::util::assert_name;
use crate::compare::util::get_offsets;
use crate::parser::Comment;
use crate::parser::Document;
use crate::parser::DocumentElement;
@ -13,6 +12,7 @@ use crate::parser::Heading;
use crate::parser::Paragraph;
use crate::parser::PlainList;
use crate::parser::PlainListItem;
use crate::parser::PropertyDrawer;
use crate::parser::Section;
use crate::DynamicBlock;
@ -197,6 +197,7 @@ fn compare_element<'s>(
Element::FootnoteDefinition(obj) => compare_footnote_definition(source, emacs, obj),
Element::Comment(obj) => compare_comment(source, emacs, obj),
Element::Drawer(obj) => compare_drawer(source, emacs, obj),
Element::PropertyDrawer(obj) => compare_property_drawer(source, emacs, obj),
}
}
@ -428,3 +429,33 @@ fn compare_drawer<'s>(
children: child_status,
})
}
fn compare_property_drawer<'s>(
source: &'s str,
emacs: &'s Token<'s>,
rust: &'s PropertyDrawer<'s>,
) -> Result<DiffResult, Box<dyn std::error::Error>> {
let children = emacs.as_list()?;
let mut child_status = Vec::new();
let mut this_status = DiffStatus::Good;
let emacs_name = "property-drawer";
if assert_name(emacs, emacs_name).is_err() {
this_status = DiffStatus::Bad;
}
if assert_bounds(source, emacs, rust).is_err() {
this_status = DiffStatus::Bad;
}
for (emacs_child, rust_child) in children.iter().skip(2).zip(rust.children.iter()) {
// TODO: What are node properties and are they the only legal child of property drawers?
// child_status.push(compare_element(source, emacs_child, rust_child)?);
}
Ok(DiffResult {
status: this_status,
name: emacs_name.to_owned(),
message: None,
children: child_status,
})
}

View File

@ -8,6 +8,7 @@ use super::greater_element::DynamicBlock;
use super::greater_element::FootnoteDefinition;
use super::greater_element::GreaterBlock;
use super::greater_element::PlainList;
use super::greater_element::PropertyDrawer;
use super::lesser_element::Comment;
use super::lesser_element::Paragraph;
use super::paragraph::paragraph;
@ -29,6 +30,7 @@ pub enum Element<'s> {
FootnoteDefinition(FootnoteDefinition<'s>),
Comment(Comment<'s>),
Drawer(Drawer<'s>),
PropertyDrawer(PropertyDrawer<'s>),
}
impl<'s> Source<'s> for Element<'s> {
@ -41,6 +43,7 @@ impl<'s> Source<'s> for Element<'s> {
Element::FootnoteDefinition(obj) => obj.source,
Element::Comment(obj) => obj.source,
Element::Drawer(obj) => obj.source,
Element::PropertyDrawer(obj) => obj.source,
}
}
}
@ -93,6 +96,12 @@ impl<'s> Source<'s> for Drawer<'s> {
}
}
impl<'s> Source<'s> for PropertyDrawer<'s> {
fn get_source(&'s self) -> &'s str {
self.source
}
}
#[tracing::instrument(ret, level = "debug")]
pub fn element<'r, 's>(context: Context<'r, 's>, input: &'s str) -> Res<&'s str, Element<'s>> {
let non_paragraph_matcher = parser_with_context!(non_paragraph_element)(context);

View File

@ -43,3 +43,10 @@ pub struct Drawer<'s> {
pub name: &'s str,
pub children: Vec<Element<'s>>,
}
#[derive(Debug)]
pub struct PropertyDrawer<'s> {
pub source: &'s str,
pub name: &'s str,
pub children: Vec<Element<'s>>,
}

View File

@ -16,6 +16,7 @@ mod parser_context;
mod parser_with_context;
mod plain_list;
mod plain_text;
mod property_drawer;
mod source;
mod util;
pub use document::document;
@ -30,6 +31,7 @@ pub use greater_element::FootnoteDefinition;
pub use greater_element::GreaterBlock;
pub use greater_element::PlainList;
pub use greater_element::PlainListItem;
pub use greater_element::PropertyDrawer;
pub use lesser_element::Comment;
pub use lesser_element::Paragraph;
pub use source::Source;

View File

@ -0,0 +1,11 @@
use super::Context;
use crate::parser::error::Res;
use crate::parser::greater_element::PropertyDrawer;
#[tracing::instrument(ret, level = "debug")]
pub fn property_drawer<'r, 's>(
context: Context<'r, 's>,
input: &'s str,
) -> Res<&'s str, PropertyDrawer<'s>> {
todo!()
}