Initial structure for adding support for comments.

This commit is contained in:
Tom Alexander 2023-04-15 16:31:38 -04:00
parent cfcf6443ca
commit 1b10b197f2
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE
5 changed files with 19 additions and 1 deletions

View File

@ -216,6 +216,7 @@ fn compare_element<'s>(
Element::PlainList(obj) => compare_plain_list(source, emacs, obj),
Element::GreaterBlock(obj) => compare_greater_block(source, emacs, obj),
Element::FootnoteDefinition(obj) => compare_footnote_definition(source, emacs, obj),
Element::Comment(obj) => todo!(),
}
}

1
src/parser/comment.rs Normal file
View File

@ -0,0 +1 @@

View File

@ -1,15 +1,16 @@
use super::PlainListItem;
use super::error::Res;
use super::footnote_definition::footnote_definition;
use super::greater_block::greater_block;
use super::greater_element::FootnoteDefinition;
use super::greater_element::GreaterBlock;
use super::greater_element::PlainList;
use super::lesser_element::Comment;
use super::lesser_element::Paragraph;
use super::paragraph::paragraph;
use super::plain_list::plain_list;
use super::source::Source;
use super::Context;
use super::PlainListItem;
use crate::parser::parser_with_context::parser_with_context;
use nom::branch::alt;
use nom::combinator::map;
@ -20,6 +21,7 @@ pub enum Element<'s> {
PlainList(PlainList<'s>),
GreaterBlock(GreaterBlock<'s>),
FootnoteDefinition(FootnoteDefinition<'s>),
Comment(Comment<'s>),
}
impl<'s> Source<'s> for Element<'s> {
@ -29,6 +31,7 @@ impl<'s> Source<'s> for Element<'s> {
Element::PlainList(obj) => obj.source,
Element::GreaterBlock(obj) => obj.source,
Element::FootnoteDefinition(obj) => obj.source,
Element::Comment(obj) => obj.source,
}
}
}
@ -63,6 +66,12 @@ impl<'s> Source<'s> for FootnoteDefinition<'s> {
}
}
impl<'s> Source<'s> for Comment<'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

@ -5,3 +5,8 @@ pub struct Paragraph<'s> {
pub source: &'s str,
pub children: Vec<Object<'s>>,
}
#[derive(Debug)]
pub struct Comment<'s> {
pub source: &'s str,
}

View File

@ -1,3 +1,4 @@
mod comment;
mod document;
mod element;
mod error;
@ -24,6 +25,7 @@ pub use greater_element::FootnoteDefinition;
pub use greater_element::GreaterBlock;
pub use greater_element::PlainList;
pub use greater_element::PlainListItem;
pub use lesser_element::Comment;
pub use lesser_element::Paragraph;
pub use source::Source;
type Context<'r, 's> = &'r parser_context::ContextTree<'r, 's>;