Initial structure for dynamic blocks.
This commit is contained in:
parent
6cb536169d
commit
0d07a6aad3
@ -3,6 +3,7 @@ use crate::compare::util::get_offsets;
|
||||
use crate::parser::Comment;
|
||||
use crate::parser::Document;
|
||||
use crate::parser::DocumentElement;
|
||||
use crate::parser::Drawer;
|
||||
use crate::parser::Element;
|
||||
use crate::parser::FootnoteDefinition;
|
||||
use crate::parser::GreaterBlock;
|
||||
@ -11,7 +12,6 @@ use crate::parser::Paragraph;
|
||||
use crate::parser::PlainList;
|
||||
use crate::parser::PlainListItem;
|
||||
use crate::parser::Section;
|
||||
use crate::parser::Drawer;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct DiffResult {
|
||||
@ -217,6 +217,7 @@ fn compare_element<'s>(
|
||||
Element::Paragraph(obj) => compare_paragraph(source, emacs, obj),
|
||||
Element::PlainList(obj) => compare_plain_list(source, emacs, obj),
|
||||
Element::GreaterBlock(obj) => compare_greater_block(source, emacs, obj),
|
||||
Element::DynamicBlock(obj) => todo!(),
|
||||
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),
|
||||
|
22
src/parser/dynamic_block.rs
Normal file
22
src/parser/dynamic_block.rs
Normal file
@ -0,0 +1,22 @@
|
||||
use super::error::Res;
|
||||
use super::Context;
|
||||
use crate::parser::error::CustomError;
|
||||
use crate::parser::error::MyError;
|
||||
use crate::parser::greater_element::DynamicBlock;
|
||||
use crate::parser::util::immediate_in_section;
|
||||
use crate::parser::util::start_of_line;
|
||||
|
||||
#[tracing::instrument(ret, level = "debug")]
|
||||
pub fn dynamic_block<'r, 's>(
|
||||
context: Context<'r, 's>,
|
||||
input: &'s str,
|
||||
) -> Res<&'s str, DynamicBlock<'s>> {
|
||||
// TODO: Do I need to differentiate between different dynamic block types.
|
||||
if immediate_in_section(context, "dynamic block") {
|
||||
return Err(nom::Err::Error(CustomError::MyError(MyError(
|
||||
"Cannot nest objects of the same element",
|
||||
))));
|
||||
}
|
||||
start_of_line(context, input)?;
|
||||
todo!()
|
||||
}
|
@ -1,8 +1,10 @@
|
||||
use super::comment::comment;
|
||||
use super::drawer::drawer;
|
||||
use super::dynamic_block::dynamic_block;
|
||||
use super::error::Res;
|
||||
use super::footnote_definition::footnote_definition;
|
||||
use super::greater_block::greater_block;
|
||||
use super::greater_element::DynamicBlock;
|
||||
use super::greater_element::FootnoteDefinition;
|
||||
use super::greater_element::GreaterBlock;
|
||||
use super::greater_element::PlainList;
|
||||
@ -23,6 +25,7 @@ pub enum Element<'s> {
|
||||
Paragraph(Paragraph<'s>),
|
||||
PlainList(PlainList<'s>),
|
||||
GreaterBlock(GreaterBlock<'s>),
|
||||
DynamicBlock(DynamicBlock<'s>),
|
||||
FootnoteDefinition(FootnoteDefinition<'s>),
|
||||
Comment(Comment<'s>),
|
||||
Drawer(Drawer<'s>),
|
||||
@ -34,6 +37,7 @@ impl<'s> Source<'s> for Element<'s> {
|
||||
Element::Paragraph(obj) => obj.source,
|
||||
Element::PlainList(obj) => obj.source,
|
||||
Element::GreaterBlock(obj) => obj.source,
|
||||
Element::DynamicBlock(obj) => obj.source,
|
||||
Element::FootnoteDefinition(obj) => obj.source,
|
||||
Element::Comment(obj) => obj.source,
|
||||
Element::Drawer(obj) => obj.source,
|
||||
@ -65,6 +69,12 @@ impl<'s> Source<'s> for GreaterBlock<'s> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'s> Source<'s> for DynamicBlock<'s> {
|
||||
fn get_source(&'s self) -> &'s str {
|
||||
self.source
|
||||
}
|
||||
}
|
||||
|
||||
impl<'s> Source<'s> for FootnoteDefinition<'s> {
|
||||
fn get_source(&'s self) -> &'s str {
|
||||
self.source
|
||||
@ -100,12 +110,14 @@ pub fn non_paragraph_element<'r, 's>(
|
||||
) -> Res<&'s str, Element<'s>> {
|
||||
let plain_list_matcher = parser_with_context!(plain_list)(context);
|
||||
let greater_block_matcher = parser_with_context!(greater_block)(context);
|
||||
let dynamic_block_matcher = parser_with_context!(dynamic_block)(context);
|
||||
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);
|
||||
alt((
|
||||
map(plain_list_matcher, Element::PlainList),
|
||||
map(greater_block_matcher, Element::GreaterBlock),
|
||||
map(dynamic_block_matcher, Element::DynamicBlock),
|
||||
map(footnote_definition_matcher, Element::FootnoteDefinition),
|
||||
map(comment_matcher, Element::Comment),
|
||||
map(drawer_matcher, Element::Drawer),
|
||||
|
@ -1,12 +1,10 @@
|
||||
use super::error::Res;
|
||||
use super::object::TextMarkup;
|
||||
use super::Context;
|
||||
use crate::parser::element::element;
|
||||
use crate::parser::error::CustomError;
|
||||
use crate::parser::error::MyError;
|
||||
use crate::parser::exiting::ExitClass;
|
||||
use crate::parser::greater_element::GreaterBlock;
|
||||
use crate::parser::object::Object;
|
||||
use crate::parser::parser_context::ContextElement;
|
||||
use crate::parser::parser_context::ExitMatcherNode;
|
||||
use crate::parser::parser_with_context::parser_with_context;
|
||||
|
@ -22,6 +22,14 @@ pub struct GreaterBlock<'s> {
|
||||
pub children: Vec<Element<'s>>,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct DynamicBlock<'s> {
|
||||
pub source: &'s str,
|
||||
pub name: &'s str,
|
||||
pub parameters: Option<&'s str>,
|
||||
pub children: Vec<Element<'s>>,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct FootnoteDefinition<'s> {
|
||||
pub source: &'s str,
|
||||
|
@ -1,6 +1,7 @@
|
||||
mod comment;
|
||||
mod document;
|
||||
mod drawer;
|
||||
mod dynamic_block;
|
||||
mod element;
|
||||
mod error;
|
||||
mod exiting;
|
||||
@ -24,6 +25,7 @@ pub use document::Heading;
|
||||
pub use document::Section;
|
||||
pub use element::Element;
|
||||
pub use greater_element::Drawer;
|
||||
pub use greater_element::DynamicBlock;
|
||||
pub use greater_element::FootnoteDefinition;
|
||||
pub use greater_element::GreaterBlock;
|
||||
pub use greater_element::PlainList;
|
||||
|
Loading…
Reference in New Issue
Block a user