Defining new structs for each type of lesser block.
This commit is contained in:
parent
77d3f40c19
commit
dbb04dcba6
@ -2,22 +2,26 @@ use super::sexp::Token;
|
||||
use super::util::assert_bounds;
|
||||
use super::util::assert_name;
|
||||
use crate::parser::Comment;
|
||||
use crate::parser::CommentBlock;
|
||||
use crate::parser::Document;
|
||||
use crate::parser::DocumentElement;
|
||||
use crate::parser::Drawer;
|
||||
use crate::parser::Element;
|
||||
use crate::parser::ExampleBlock;
|
||||
use crate::parser::ExportBlock;
|
||||
use crate::parser::FootnoteDefinition;
|
||||
use crate::parser::GreaterBlock;
|
||||
use crate::parser::Heading;
|
||||
use crate::parser::LesserBlock;
|
||||
use crate::parser::Paragraph;
|
||||
use crate::parser::PlainList;
|
||||
use crate::parser::PlainListItem;
|
||||
use crate::parser::PropertyDrawer;
|
||||
use crate::parser::Section;
|
||||
use crate::parser::SrcBlock;
|
||||
use crate::parser::Table;
|
||||
use crate::parser::TableCell;
|
||||
use crate::parser::TableRow;
|
||||
use crate::parser::VerseBlock;
|
||||
use crate::DynamicBlock;
|
||||
|
||||
#[derive(Debug)]
|
||||
@ -203,7 +207,11 @@ fn compare_element<'s>(
|
||||
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),
|
||||
Element::LesserBlock(obj) => compare_lesser_block(source, emacs, obj),
|
||||
Element::VerseBlock(obj) => compare_verse_block(source, emacs, obj),
|
||||
Element::CommentBlock(obj) => compare_comment_block(source, emacs, obj),
|
||||
Element::ExampleBlock(obj) => compare_example_block(source, emacs, obj),
|
||||
Element::ExportBlock(obj) => compare_export_block(source, emacs, obj),
|
||||
Element::SrcBlock(obj) => compare_src_block(source, emacs, obj),
|
||||
}
|
||||
}
|
||||
|
||||
@ -551,10 +559,42 @@ fn compare_table_cell<'s>(
|
||||
})
|
||||
}
|
||||
|
||||
fn compare_lesser_block<'s>(
|
||||
fn compare_verse_block<'s>(
|
||||
source: &'s str,
|
||||
emacs: &'s Token<'s>,
|
||||
rust: &'s LesserBlock<'s>,
|
||||
rust: &'s VerseBlock<'s>,
|
||||
) -> Result<DiffResult, Box<dyn std::error::Error>> {
|
||||
todo!()
|
||||
}
|
||||
|
||||
fn compare_comment_block<'s>(
|
||||
source: &'s str,
|
||||
emacs: &'s Token<'s>,
|
||||
rust: &'s CommentBlock<'s>,
|
||||
) -> Result<DiffResult, Box<dyn std::error::Error>> {
|
||||
todo!()
|
||||
}
|
||||
|
||||
fn compare_example_block<'s>(
|
||||
source: &'s str,
|
||||
emacs: &'s Token<'s>,
|
||||
rust: &'s ExampleBlock<'s>,
|
||||
) -> Result<DiffResult, Box<dyn std::error::Error>> {
|
||||
todo!()
|
||||
}
|
||||
|
||||
fn compare_export_block<'s>(
|
||||
source: &'s str,
|
||||
emacs: &'s Token<'s>,
|
||||
rust: &'s ExportBlock<'s>,
|
||||
) -> Result<DiffResult, Box<dyn std::error::Error>> {
|
||||
todo!()
|
||||
}
|
||||
|
||||
fn compare_src_block<'s>(
|
||||
source: &'s str,
|
||||
emacs: &'s Token<'s>,
|
||||
rust: &'s SrcBlock<'s>,
|
||||
) -> Result<DiffResult, Box<dyn std::error::Error>> {
|
||||
todo!()
|
||||
}
|
||||
|
@ -5,8 +5,12 @@ use super::greater_element::PlainList;
|
||||
use super::greater_element::PropertyDrawer;
|
||||
use super::greater_element::Table;
|
||||
use super::lesser_element::Comment;
|
||||
use super::lesser_element::LesserBlock;
|
||||
use super::lesser_element::CommentBlock;
|
||||
use super::lesser_element::ExampleBlock;
|
||||
use super::lesser_element::ExportBlock;
|
||||
use super::lesser_element::Paragraph;
|
||||
use super::lesser_element::SrcBlock;
|
||||
use super::lesser_element::VerseBlock;
|
||||
use super::source::Source;
|
||||
use super::Drawer;
|
||||
|
||||
@ -21,7 +25,11 @@ pub enum Element<'s> {
|
||||
Drawer(Drawer<'s>),
|
||||
PropertyDrawer(PropertyDrawer<'s>),
|
||||
Table(Table<'s>),
|
||||
LesserBlock(LesserBlock<'s>),
|
||||
VerseBlock(VerseBlock<'s>),
|
||||
CommentBlock(CommentBlock<'s>),
|
||||
ExampleBlock(ExampleBlock<'s>),
|
||||
ExportBlock(ExportBlock<'s>),
|
||||
SrcBlock(SrcBlock<'s>),
|
||||
}
|
||||
|
||||
impl<'s> Source<'s> for Element<'s> {
|
||||
@ -36,7 +44,11 @@ impl<'s> Source<'s> for Element<'s> {
|
||||
Element::Drawer(obj) => obj.source,
|
||||
Element::PropertyDrawer(obj) => obj.source,
|
||||
Element::Table(obj) => obj.source,
|
||||
Element::LesserBlock(obj) => obj.source,
|
||||
Element::VerseBlock(obj) => obj.source,
|
||||
Element::CommentBlock(obj) => obj.source,
|
||||
Element::ExampleBlock(obj) => obj.source,
|
||||
Element::ExportBlock(obj) => obj.source,
|
||||
Element::SrcBlock(obj) => obj.source,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -5,7 +5,11 @@ use super::element::Element;
|
||||
use super::error::Res;
|
||||
use super::footnote_definition::footnote_definition;
|
||||
use super::greater_block::greater_block;
|
||||
use super::lesser_block::lesser_block;
|
||||
use super::lesser_block::comment_block;
|
||||
use super::lesser_block::example_block;
|
||||
use super::lesser_block::export_block;
|
||||
use super::lesser_block::src_block;
|
||||
use super::lesser_block::verse_block;
|
||||
use super::paragraph::paragraph;
|
||||
use super::plain_list::plain_list;
|
||||
use super::Context;
|
||||
@ -36,7 +40,11 @@ pub fn non_paragraph_element<'r, 's>(
|
||||
let comment_matcher = parser_with_context!(comment)(context);
|
||||
let drawer_matcher = parser_with_context!(drawer)(context);
|
||||
let table_matcher = parser_with_context!(org_mode_table)(context);
|
||||
let lesser_block_matcher = parser_with_context!(lesser_block)(context);
|
||||
let verse_block_matcher = parser_with_context!(verse_block)(context);
|
||||
let comment_block_matcher = parser_with_context!(comment_block)(context);
|
||||
let example_block_matcher = parser_with_context!(example_block)(context);
|
||||
let export_block_matcher = parser_with_context!(export_block)(context);
|
||||
let src_block_matcher = parser_with_context!(src_block)(context);
|
||||
alt((
|
||||
map(plain_list_matcher, Element::PlainList),
|
||||
map(greater_block_matcher, Element::GreaterBlock),
|
||||
@ -45,6 +53,10 @@ pub fn non_paragraph_element<'r, 's>(
|
||||
map(comment_matcher, Element::Comment),
|
||||
map(drawer_matcher, Element::Drawer),
|
||||
map(table_matcher, Element::Table),
|
||||
map(lesser_block_matcher, Element::LesserBlock),
|
||||
map(verse_block_matcher, Element::VerseBlock),
|
||||
map(comment_block_matcher, Element::CommentBlock),
|
||||
map(example_block_matcher, Element::ExampleBlock),
|
||||
map(export_block_matcher, Element::ExportBlock),
|
||||
map(src_block_matcher, Element::SrcBlock),
|
||||
))(input)
|
||||
}
|
||||
|
@ -15,8 +15,11 @@ use nom::sequence::tuple;
|
||||
use super::error::Res;
|
||||
use super::Context;
|
||||
use crate::parser::exiting::ExitClass;
|
||||
use crate::parser::lesser_element::LesserBlock;
|
||||
use crate::parser::lesser_element::LesserBlockComment;
|
||||
use crate::parser::lesser_element::CommentBlock;
|
||||
use crate::parser::lesser_element::ExampleBlock;
|
||||
use crate::parser::lesser_element::ExportBlock;
|
||||
use crate::parser::lesser_element::SrcBlock;
|
||||
use crate::parser::lesser_element::VerseBlock;
|
||||
use crate::parser::object_parser::standard_set_object;
|
||||
use crate::parser::parser_context::ContextElement;
|
||||
use crate::parser::parser_context::ExitMatcherNode;
|
||||
@ -29,10 +32,10 @@ use crate::parser::util::maybe_consume_trailing_whitespace_if_not_exiting;
|
||||
use crate::parser::util::start_of_line;
|
||||
|
||||
#[tracing::instrument(ret, level = "debug")]
|
||||
pub fn lesser_block<'r, 's>(
|
||||
pub fn verse_block<'r, 's>(
|
||||
context: Context<'r, 's>,
|
||||
input: &'s str,
|
||||
) -> Res<&'s str, LesserBlock<'s>> {
|
||||
) -> Res<&'s str, VerseBlock<'s>> {
|
||||
start_of_line(context, input)?;
|
||||
let (remaining, _leading_whitespace) = space0(input)?;
|
||||
let (remaining, (_begin, name)) = tuple((
|
||||
@ -77,7 +80,7 @@ pub fn lesser_block<'r, 's>(
|
||||
let source = get_consumed(input, remaining);
|
||||
Ok((
|
||||
remaining,
|
||||
LesserBlock {
|
||||
VerseBlock {
|
||||
source,
|
||||
name,
|
||||
data: parameters,
|
||||
@ -87,10 +90,10 @@ pub fn lesser_block<'r, 's>(
|
||||
}
|
||||
|
||||
#[tracing::instrument(ret, level = "debug")]
|
||||
pub fn lesser_block_comment<'r, 's>(
|
||||
pub fn comment_block<'r, 's>(
|
||||
context: Context<'r, 's>,
|
||||
input: &'s str,
|
||||
) -> Res<&'s str, LesserBlockComment<'s>> {
|
||||
) -> Res<&'s str, CommentBlock<'s>> {
|
||||
let (remaining, name) = lesser_block_begin("comment")(context, input)?;
|
||||
let (remaining, parameters) = opt(tuple((space1, data)))(remaining)?;
|
||||
let (remaining, _nl) = line_ending(remaining)?;
|
||||
@ -118,7 +121,127 @@ pub fn lesser_block_comment<'r, 's>(
|
||||
let source = get_consumed(input, remaining);
|
||||
Ok((
|
||||
remaining,
|
||||
LesserBlockComment {
|
||||
CommentBlock {
|
||||
source,
|
||||
name,
|
||||
data: parameters,
|
||||
contents,
|
||||
},
|
||||
))
|
||||
}
|
||||
|
||||
#[tracing::instrument(ret, level = "debug")]
|
||||
pub fn example_block<'r, 's>(
|
||||
context: Context<'r, 's>,
|
||||
input: &'s str,
|
||||
) -> Res<&'s str, ExampleBlock<'s>> {
|
||||
let (remaining, name) = lesser_block_begin("example")(context, input)?;
|
||||
let (remaining, parameters) = opt(tuple((space1, data)))(remaining)?;
|
||||
let (remaining, _nl) = line_ending(remaining)?;
|
||||
let lesser_block_end_specialized = lesser_block_end("example");
|
||||
let parser_context = context
|
||||
.with_additional_node(ContextElement::ConsumeTrailingWhitespace(true))
|
||||
.with_additional_node(ContextElement::Context("lesser block"))
|
||||
.with_additional_node(ContextElement::ExitMatcherNode(ExitMatcherNode {
|
||||
class: ExitClass::Beta,
|
||||
exit_matcher: &lesser_block_end_specialized,
|
||||
}));
|
||||
let parameters = match parameters {
|
||||
Some((_ws, parameters)) => Some(parameters),
|
||||
None => None,
|
||||
};
|
||||
|
||||
let (remaining, contents) = map(parser_with_context!(plain_text)(&parser_context), |obj| {
|
||||
obj.source
|
||||
})(remaining)?;
|
||||
let (remaining, _end) = lesser_block_end_specialized(&parser_context, remaining)?;
|
||||
|
||||
let (remaining, _trailing_ws) =
|
||||
maybe_consume_trailing_whitespace_if_not_exiting(context, remaining)?;
|
||||
|
||||
let source = get_consumed(input, remaining);
|
||||
Ok((
|
||||
remaining,
|
||||
ExampleBlock {
|
||||
source,
|
||||
name,
|
||||
data: parameters,
|
||||
contents,
|
||||
},
|
||||
))
|
||||
}
|
||||
|
||||
#[tracing::instrument(ret, level = "debug")]
|
||||
pub fn export_block<'r, 's>(
|
||||
context: Context<'r, 's>,
|
||||
input: &'s str,
|
||||
) -> Res<&'s str, ExportBlock<'s>> {
|
||||
let (remaining, name) = lesser_block_begin("export")(context, input)?;
|
||||
let (remaining, parameters) = opt(tuple((space1, data)))(remaining)?;
|
||||
let (remaining, _nl) = line_ending(remaining)?;
|
||||
let lesser_block_end_specialized = lesser_block_end("export");
|
||||
let parser_context = context
|
||||
.with_additional_node(ContextElement::ConsumeTrailingWhitespace(true))
|
||||
.with_additional_node(ContextElement::Context("lesser block"))
|
||||
.with_additional_node(ContextElement::ExitMatcherNode(ExitMatcherNode {
|
||||
class: ExitClass::Beta,
|
||||
exit_matcher: &lesser_block_end_specialized,
|
||||
}));
|
||||
let parameters = match parameters {
|
||||
Some((_ws, parameters)) => Some(parameters),
|
||||
None => None,
|
||||
};
|
||||
|
||||
let (remaining, contents) = map(parser_with_context!(plain_text)(&parser_context), |obj| {
|
||||
obj.source
|
||||
})(remaining)?;
|
||||
let (remaining, _end) = lesser_block_end_specialized(&parser_context, remaining)?;
|
||||
|
||||
let (remaining, _trailing_ws) =
|
||||
maybe_consume_trailing_whitespace_if_not_exiting(context, remaining)?;
|
||||
|
||||
let source = get_consumed(input, remaining);
|
||||
Ok((
|
||||
remaining,
|
||||
ExportBlock {
|
||||
source,
|
||||
name,
|
||||
data: parameters,
|
||||
contents,
|
||||
},
|
||||
))
|
||||
}
|
||||
|
||||
#[tracing::instrument(ret, level = "debug")]
|
||||
pub fn src_block<'r, 's>(context: Context<'r, 's>, input: &'s str) -> Res<&'s str, SrcBlock<'s>> {
|
||||
let (remaining, name) = lesser_block_begin("src")(context, input)?;
|
||||
let (remaining, parameters) = opt(tuple((space1, data)))(remaining)?;
|
||||
let (remaining, _nl) = line_ending(remaining)?;
|
||||
let lesser_block_end_specialized = lesser_block_end("src");
|
||||
let parser_context = context
|
||||
.with_additional_node(ContextElement::ConsumeTrailingWhitespace(true))
|
||||
.with_additional_node(ContextElement::Context("lesser block"))
|
||||
.with_additional_node(ContextElement::ExitMatcherNode(ExitMatcherNode {
|
||||
class: ExitClass::Beta,
|
||||
exit_matcher: &lesser_block_end_specialized,
|
||||
}));
|
||||
let parameters = match parameters {
|
||||
Some((_ws, parameters)) => Some(parameters),
|
||||
None => None,
|
||||
};
|
||||
|
||||
let (remaining, contents) = map(parser_with_context!(plain_text)(&parser_context), |obj| {
|
||||
obj.source
|
||||
})(remaining)?;
|
||||
let (remaining, _end) = lesser_block_end_specialized(&parser_context, remaining)?;
|
||||
|
||||
let (remaining, _trailing_ws) =
|
||||
maybe_consume_trailing_whitespace_if_not_exiting(context, remaining)?;
|
||||
|
||||
let source = get_consumed(input, remaining);
|
||||
Ok((
|
||||
remaining,
|
||||
SrcBlock {
|
||||
source,
|
||||
name,
|
||||
data: parameters,
|
||||
|
@ -20,7 +20,7 @@ pub struct TableCell<'s> {
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct LesserBlock<'s> {
|
||||
pub struct VerseBlock<'s> {
|
||||
pub source: &'s str,
|
||||
pub name: &'s str,
|
||||
pub data: Option<&'s str>,
|
||||
@ -28,7 +28,31 @@ pub struct LesserBlock<'s> {
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct LesserBlockComment<'s> {
|
||||
pub struct CommentBlock<'s> {
|
||||
pub source: &'s str,
|
||||
pub name: &'s str,
|
||||
pub data: Option<&'s str>,
|
||||
pub contents: &'s str,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct ExampleBlock<'s> {
|
||||
pub source: &'s str,
|
||||
pub name: &'s str,
|
||||
pub data: Option<&'s str>,
|
||||
pub contents: &'s str,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct ExportBlock<'s> {
|
||||
pub source: &'s str,
|
||||
pub name: &'s str,
|
||||
pub data: Option<&'s str>,
|
||||
pub contents: &'s str,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct SrcBlock<'s> {
|
||||
pub source: &'s str,
|
||||
pub name: &'s str,
|
||||
pub data: Option<&'s str>,
|
||||
@ -63,3 +87,29 @@ impl<'s> Source<'s> for Comment<'s> {
|
||||
self.source
|
||||
}
|
||||
}
|
||||
|
||||
impl<'s> Source<'s> for VerseBlock<'s> {
|
||||
fn get_source(&'s self) -> &'s str {
|
||||
self.source
|
||||
}
|
||||
}
|
||||
impl<'s> Source<'s> for CommentBlock<'s> {
|
||||
fn get_source(&'s self) -> &'s str {
|
||||
self.source
|
||||
}
|
||||
}
|
||||
impl<'s> Source<'s> for ExampleBlock<'s> {
|
||||
fn get_source(&'s self) -> &'s str {
|
||||
self.source
|
||||
}
|
||||
}
|
||||
impl<'s> Source<'s> for ExportBlock<'s> {
|
||||
fn get_source(&'s self) -> &'s str {
|
||||
self.source
|
||||
}
|
||||
}
|
||||
impl<'s> Source<'s> for SrcBlock<'s> {
|
||||
fn get_source(&'s self) -> &'s str {
|
||||
self.source
|
||||
}
|
||||
}
|
||||
|
@ -39,8 +39,12 @@ pub use greater_element::PropertyDrawer;
|
||||
pub use greater_element::Table;
|
||||
pub use greater_element::TableRow;
|
||||
pub use lesser_element::Comment;
|
||||
pub use lesser_element::LesserBlock;
|
||||
pub use lesser_element::CommentBlock;
|
||||
pub use lesser_element::ExampleBlock;
|
||||
pub use lesser_element::ExportBlock;
|
||||
pub use lesser_element::Paragraph;
|
||||
pub use lesser_element::SrcBlock;
|
||||
pub use lesser_element::TableCell;
|
||||
pub use lesser_element::VerseBlock;
|
||||
pub use source::Source;
|
||||
type Context<'r, 's> = &'r parser_context::ContextTree<'r, 's>;
|
||||
|
Loading…
x
Reference in New Issue
Block a user