Initial structure for tables.

This commit is contained in:
Tom Alexander 2023-04-19 20:59:58 -04:00
parent 1badd3b0fc
commit 17ab8727d1
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE
5 changed files with 54 additions and 0 deletions

View File

@ -14,6 +14,7 @@ use crate::parser::PlainList;
use crate::parser::PlainListItem;
use crate::parser::PropertyDrawer;
use crate::parser::Section;
use crate::parser::Table;
use crate::DynamicBlock;
#[derive(Debug)]
@ -198,6 +199,7 @@ fn compare_element<'s>(
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),
Element::Table(obj) => compare_table(source, emacs, obj),
}
}
@ -459,3 +461,28 @@ fn compare_property_drawer<'s>(
children: child_status,
})
}
fn compare_table<'s>(
source: &'s str,
emacs: &'s Token<'s>,
rust: &'s Table<'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 = "table";
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: child_status,
})
}

View File

@ -9,6 +9,7 @@ use super::greater_element::FootnoteDefinition;
use super::greater_element::GreaterBlock;
use super::greater_element::PlainList;
use super::greater_element::PropertyDrawer;
use super::greater_element::Table;
use super::lesser_element::Comment;
use super::lesser_element::Paragraph;
use super::paragraph::paragraph;
@ -18,6 +19,7 @@ use super::Context;
use super::Drawer;
use super::PlainListItem;
use crate::parser::parser_with_context::parser_with_context;
use crate::parser::table::table;
use nom::branch::alt;
use nom::combinator::map;
@ -31,6 +33,7 @@ pub enum Element<'s> {
Comment(Comment<'s>),
Drawer(Drawer<'s>),
PropertyDrawer(PropertyDrawer<'s>),
Table(Table<'s>),
}
impl<'s> Source<'s> for Element<'s> {
@ -44,6 +47,7 @@ impl<'s> Source<'s> for Element<'s> {
Element::Comment(obj) => obj.source,
Element::Drawer(obj) => obj.source,
Element::PropertyDrawer(obj) => obj.source,
Element::Table(obj) => obj.source,
}
}
}
@ -102,6 +106,12 @@ impl<'s> Source<'s> for PropertyDrawer<'s> {
}
}
impl<'s> Source<'s> for Table<'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);
@ -123,6 +133,7 @@ pub fn non_paragraph_element<'r, 's>(
let footnote_definition_matcher = parser_with_context!(footnote_definition)(context);
let comment_matcher = parser_with_context!(comment)(context);
let drawer_matcher = parser_with_context!(drawer)(context);
let table_matcher = parser_with_context!(table)(context);
alt((
map(plain_list_matcher, Element::PlainList),
map(greater_block_matcher, Element::GreaterBlock),
@ -130,5 +141,6 @@ pub fn non_paragraph_element<'r, 's>(
map(footnote_definition_matcher, Element::FootnoteDefinition),
map(comment_matcher, Element::Comment),
map(drawer_matcher, Element::Drawer),
map(table_matcher, Element::Table),
))(input)
}

View File

@ -55,3 +55,8 @@ pub struct NodeProperty<'s> {
pub source: &'s str,
pub value: Option<&'s str>,
}
#[derive(Debug)]
pub struct Table<'s> {
pub source: &'s str,
}

View File

@ -18,6 +18,7 @@ mod plain_list;
mod plain_text;
mod property_drawer;
mod source;
mod table;
mod util;
pub use document::document;
pub use document::Document;
@ -32,6 +33,7 @@ pub use greater_element::GreaterBlock;
pub use greater_element::PlainList;
pub use greater_element::PlainListItem;
pub use greater_element::PropertyDrawer;
pub use greater_element::Table;
pub use lesser_element::Comment;
pub use lesser_element::Paragraph;
pub use source::Source;

8
src/parser/table.rs Normal file
View File

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