Code structure for radio links and radio targets.
This commit is contained in:
@@ -26,6 +26,7 @@ mod plain_list;
|
||||
mod plain_text;
|
||||
mod planning;
|
||||
mod property_drawer;
|
||||
mod radio_link;
|
||||
mod regular_link;
|
||||
pub mod sexp;
|
||||
mod source;
|
||||
@@ -67,6 +68,8 @@ pub use object::Code;
|
||||
pub use object::Italic;
|
||||
pub use object::Object;
|
||||
pub use object::PlainText;
|
||||
pub use object::RadioLink;
|
||||
pub use object::RadioTarget;
|
||||
pub use object::RegularLink;
|
||||
pub use object::StrikeThrough;
|
||||
pub use object::Underline;
|
||||
|
||||
@@ -3,6 +3,8 @@ use super::source::Source;
|
||||
#[derive(Debug)]
|
||||
pub enum Object<'s> {
|
||||
RegularLink(RegularLink<'s>),
|
||||
RadioLink(RadioLink<'s>),
|
||||
RadioTarget(RadioTarget<'s>),
|
||||
Bold(Bold<'s>),
|
||||
Italic(Italic<'s>),
|
||||
Underline(Underline<'s>),
|
||||
@@ -58,6 +60,18 @@ pub struct RegularLink<'s> {
|
||||
pub source: &'s str,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct RadioTarget<'s> {
|
||||
pub source: &'s str,
|
||||
pub children: Vec<Object<'s>>,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct RadioLink<'s> {
|
||||
pub source: &'s str,
|
||||
pub children: Vec<Object<'s>>,
|
||||
}
|
||||
|
||||
impl<'s> Source<'s> for Object<'s> {
|
||||
fn get_source(&'s self) -> &'s str {
|
||||
match self {
|
||||
@@ -69,6 +83,8 @@ impl<'s> Source<'s> for Object<'s> {
|
||||
Object::Verbatim(obj) => obj.source,
|
||||
Object::PlainText(obj) => obj.source,
|
||||
Object::RegularLink(obj) => obj.source,
|
||||
Object::RadioLink(obj) => obj.source,
|
||||
Object::RadioTarget(obj) => obj.source,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -114,3 +130,15 @@ impl<'s> Source<'s> for RegularLink<'s> {
|
||||
self.source
|
||||
}
|
||||
}
|
||||
|
||||
impl<'s> Source<'s> for RadioLink<'s> {
|
||||
fn get_source(&'s self) -> &'s str {
|
||||
self.source
|
||||
}
|
||||
}
|
||||
|
||||
impl<'s> Source<'s> for RadioTarget<'s> {
|
||||
fn get_source(&'s self) -> &'s str {
|
||||
self.source
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,6 +8,8 @@ use super::regular_link::regular_link;
|
||||
use super::Context;
|
||||
use crate::error::Res;
|
||||
use crate::parser::object::Object;
|
||||
use crate::parser::radio_link::radio_link;
|
||||
use crate::parser::radio_link::radio_target;
|
||||
use crate::parser::text_markup::text_markup;
|
||||
|
||||
#[tracing::instrument(ret, level = "debug")]
|
||||
@@ -19,6 +21,11 @@ pub fn standard_set_object<'r, 's>(
|
||||
not(|i| context.check_exit_matcher(i))(input)?;
|
||||
|
||||
alt((
|
||||
map(parser_with_context!(radio_link)(context), Object::RadioLink),
|
||||
map(
|
||||
parser_with_context!(radio_target)(context),
|
||||
Object::RadioTarget,
|
||||
),
|
||||
parser_with_context!(text_markup)(context),
|
||||
map(
|
||||
parser_with_context!(regular_link)(context),
|
||||
@@ -33,7 +40,7 @@ pub fn minimal_set_object<'r, 's>(
|
||||
context: Context<'r, 's>,
|
||||
input: &'s str,
|
||||
) -> Res<&'s str, Object<'s>> {
|
||||
// TODO: add text markup, entities, LaTeX fragments, superscripts and subscripts
|
||||
// TODO: add entities, LaTeX fragments, superscripts and subscripts
|
||||
not(|i| context.check_exit_matcher(i))(input)?;
|
||||
|
||||
alt((
|
||||
@@ -49,6 +56,11 @@ pub fn any_object_except_plain_text<'r, 's>(
|
||||
) -> Res<&'s str, Object<'s>> {
|
||||
// Used for exit matchers so this does not check exit matcher condition.
|
||||
alt((
|
||||
map(parser_with_context!(radio_link)(context), Object::RadioLink),
|
||||
map(
|
||||
parser_with_context!(radio_target)(context),
|
||||
Object::RadioTarget,
|
||||
),
|
||||
parser_with_context!(text_markup)(context),
|
||||
map(
|
||||
parser_with_context!(regular_link)(context),
|
||||
|
||||
23
src/parser/radio_link.rs
Normal file
23
src/parser/radio_link.rs
Normal file
@@ -0,0 +1,23 @@
|
||||
use super::Context;
|
||||
use crate::error::CustomError;
|
||||
use crate::error::MyError;
|
||||
use crate::error::Res;
|
||||
use crate::parser::RadioLink;
|
||||
use crate::parser::RadioTarget;
|
||||
|
||||
#[tracing::instrument(ret, level = "debug")]
|
||||
pub fn radio_link<'r, 's>(context: Context<'r, 's>, input: &'s str) -> Res<&'s str, RadioLink<'s>> {
|
||||
return Err(nom::Err::Error(CustomError::MyError(MyError(
|
||||
"Not implemented yet.",
|
||||
))));
|
||||
}
|
||||
|
||||
#[tracing::instrument(ret, level = "debug")]
|
||||
pub fn radio_target<'r, 's>(
|
||||
context: Context<'r, 's>,
|
||||
input: &'s str,
|
||||
) -> Res<&'s str, RadioTarget<'s>> {
|
||||
return Err(nom::Err::Error(CustomError::MyError(MyError(
|
||||
"Not implemented yet.",
|
||||
))));
|
||||
}
|
||||
Reference in New Issue
Block a user