Create structure for org macros.

This commit is contained in:
Tom Alexander
2023-07-13 23:26:51 -04:00
parent c0371ff958
commit d24c26de7b
5 changed files with 60 additions and 5 deletions

View File

@@ -20,6 +20,7 @@ mod lesser_element;
mod list;
mod object;
mod object_parser;
mod org_macro;
mod paragraph;
mod parser_context;
mod parser_with_context;
@@ -70,6 +71,7 @@ pub use object::Bold;
pub use object::Code;
pub use object::Italic;
pub use object::Object;
pub use object::OrgMacro;
pub use object::PlainLink;
pub use object::PlainText;
pub use object::RadioLink;

View File

@@ -2,11 +2,6 @@ use super::source::Source;
#[derive(Debug, PartialEq)]
pub enum Object<'s> {
RegularLink(RegularLink<'s>),
RadioLink(RadioLink<'s>),
RadioTarget(RadioTarget<'s>),
PlainLink(PlainLink<'s>),
AngleLink(AngleLink<'s>),
Bold(Bold<'s>),
Italic(Italic<'s>),
Underline(Underline<'s>),
@@ -14,6 +9,12 @@ pub enum Object<'s> {
Code(Code<'s>),
Verbatim(Verbatim<'s>),
PlainText(PlainText<'s>),
RegularLink(RegularLink<'s>),
RadioLink(RadioLink<'s>),
RadioTarget(RadioTarget<'s>),
PlainLink(PlainLink<'s>),
AngleLink(AngleLink<'s>),
OrgMacro(OrgMacro<'s>),
}
#[derive(Debug, PartialEq)]
@@ -88,6 +89,13 @@ pub struct AngleLink<'s> {
pub path: &'s str,
}
#[derive(Debug, PartialEq)]
pub struct OrgMacro<'s> {
pub source: &'s str,
pub macro_name: &'s str,
pub macro_args: Vec<&'s str>,
}
impl<'s> Source<'s> for Object<'s> {
fn get_source(&'s self) -> &'s str {
match self {
@@ -103,6 +111,7 @@ impl<'s> Source<'s> for Object<'s> {
Object::RadioTarget(obj) => obj.source,
Object::PlainLink(obj) => obj.source,
Object::AngleLink(obj) => obj.source,
Object::OrgMacro(obj) => obj.source,
}
}
}
@@ -172,3 +181,9 @@ impl<'s> Source<'s> for AngleLink<'s> {
self.source
}
}
impl<'s> Source<'s> for OrgMacro<'s> {
fn get_source(&'s self) -> &'s str {
self.source
}
}

View File

@@ -8,6 +8,7 @@ use super::regular_link::regular_link;
use super::Context;
use crate::error::Res;
use crate::parser::angle_link::angle_link;
use crate::parser::org_macro::org_macro;
use crate::parser::object::Object;
use crate::parser::plain_link::plain_link;
use crate::parser::radio_link::radio_link;
@@ -35,6 +36,7 @@ pub fn standard_set_object<'r, 's>(
),
map(parser_with_context!(plain_link)(context), Object::PlainLink),
map(parser_with_context!(angle_link)(context), Object::AngleLink),
map(parser_with_context!(org_macro)(context), Object::OrgMacro),
map(parser_with_context!(plain_text)(context), Object::PlainText),
))(input)
}
@@ -72,6 +74,7 @@ pub fn any_object_except_plain_text<'r, 's>(
),
map(parser_with_context!(plain_link)(context), Object::PlainLink),
map(parser_with_context!(angle_link)(context), Object::AngleLink),
map(parser_with_context!(org_macro)(context), Object::OrgMacro),
))(input)
}

10
src/parser/org_macro.rs Normal file
View File

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