Implement all of regular link except for pathreg.
This commit is contained in:
parent
3600f46e3b
commit
8a828195bd
@ -2,17 +2,14 @@ use super::source::Source;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum Object<'s> {
|
||||
RegularLink(RegularLink<'s>),
|
||||
Bold(Bold<'s>),
|
||||
Italic(Italic<'s>),
|
||||
Underline(Underline<'s>),
|
||||
StrikeThrough(StrikeThrough<'s>),
|
||||
Code(Code<'s>),
|
||||
Verbatim(Verbatim<'s>),
|
||||
|
||||
PlainText(PlainText<'s>),
|
||||
|
||||
#[allow(dead_code)]
|
||||
RegularLink(RegularLink<'s>),
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
|
@ -4,6 +4,7 @@ use nom::combinator::not;
|
||||
|
||||
use super::parser_with_context::parser_with_context;
|
||||
use super::plain_text::plain_text;
|
||||
use super::regular_link::regular_link;
|
||||
use super::Context;
|
||||
use crate::error::Res;
|
||||
use crate::parser::object::Object;
|
||||
@ -19,6 +20,10 @@ pub fn standard_set_object<'r, 's>(
|
||||
|
||||
alt((
|
||||
parser_with_context!(text_markup)(context),
|
||||
map(
|
||||
parser_with_context!(regular_link)(context),
|
||||
Object::RegularLink,
|
||||
),
|
||||
map(parser_with_context!(plain_text)(context), Object::PlainText),
|
||||
))(input)
|
||||
}
|
||||
@ -43,5 +48,20 @@ pub fn any_object_except_plain_text<'r, 's>(
|
||||
input: &'s str,
|
||||
) -> Res<&'s str, Object<'s>> {
|
||||
// Used for exit matchers so this does not check exit matcher condition.
|
||||
alt((parser_with_context!(text_markup)(context),))(input)
|
||||
alt((
|
||||
parser_with_context!(text_markup)(context),
|
||||
map(
|
||||
parser_with_context!(regular_link)(context),
|
||||
Object::RegularLink,
|
||||
),
|
||||
))(input)
|
||||
}
|
||||
|
||||
#[tracing::instrument(ret, level = "debug")]
|
||||
pub fn regular_link_description_object_set<'r, 's>(
|
||||
context: Context<'r, 's>,
|
||||
input: &'s str,
|
||||
) -> Res<&'s str, Object<'s>> {
|
||||
// TODO: minimal set of objects as well as export snippets, inline babel calls, inline source blocks, macros, and statistics cookies. It can also contain another link, but only when it is a plain or angle link. It can contain square brackets, but not ]]
|
||||
alt((parser_with_context!(minimal_set_object)(context),))(input)
|
||||
}
|
||||
|
@ -1,11 +1,87 @@
|
||||
use nom::branch::alt;
|
||||
use nom::bytes::complete::tag;
|
||||
use nom::combinator::verify;
|
||||
use nom::multi::many_till;
|
||||
|
||||
use super::parser_with_context::parser_with_context;
|
||||
use super::util::get_consumed;
|
||||
use super::Context;
|
||||
use super::Object;
|
||||
use super::RegularLink;
|
||||
use crate::error::Res;
|
||||
use crate::parser::exiting::ExitClass;
|
||||
use crate::parser::object_parser::regular_link_description_object_set;
|
||||
use crate::parser::parser_context::ContextElement;
|
||||
use crate::parser::parser_context::ExitMatcherNode;
|
||||
use crate::parser::util::exit_matcher_parser;
|
||||
|
||||
#[tracing::instrument(ret, level = "debug")]
|
||||
pub fn regular_link<'r, 's>(
|
||||
context: Context<'r, 's>,
|
||||
input: &'s str,
|
||||
) -> Res<&'s str, RegularLink<'s>> {
|
||||
alt((
|
||||
parser_with_context!(regular_link_without_description)(context),
|
||||
parser_with_context!(regular_link_with_description)(context),
|
||||
))(input)
|
||||
}
|
||||
|
||||
#[tracing::instrument(ret, level = "debug")]
|
||||
pub fn regular_link_without_description<'r, 's>(
|
||||
context: Context<'r, 's>,
|
||||
input: &'s str,
|
||||
) -> Res<&'s str, RegularLink<'s>> {
|
||||
let (remaining, _opening_bracket) = tag("[[")(input)?;
|
||||
let (remaining, _path) = pathreg(context, remaining)?;
|
||||
let (remaining, _closing_bracket) = tag("]]")(remaining)?;
|
||||
let source = get_consumed(input, remaining);
|
||||
Ok((remaining, RegularLink { source }))
|
||||
}
|
||||
|
||||
#[tracing::instrument(ret, level = "debug")]
|
||||
pub fn regular_link_with_description<'r, 's>(
|
||||
context: Context<'r, 's>,
|
||||
input: &'s str,
|
||||
) -> Res<&'s str, RegularLink<'s>> {
|
||||
let (remaining, _opening_bracket) = tag("[[")(input)?;
|
||||
let (remaining, _path) = pathreg(context, remaining)?;
|
||||
let (remaining, _closing_bracket) = tag("][")(remaining)?;
|
||||
let (remaining, _description) = description(context, remaining)?;
|
||||
let (remaining, _closing_bracket) = tag("]]")(remaining)?;
|
||||
let source = get_consumed(input, remaining);
|
||||
Ok((remaining, RegularLink { source }))
|
||||
}
|
||||
|
||||
#[tracing::instrument(ret, level = "debug")]
|
||||
pub fn pathreg<'r, 's>(context: Context<'r, 's>, input: &'s str) -> Res<&'s str, &'s str> {
|
||||
let (remaining, _opening_bracket) = tag("[[")(input)?;
|
||||
// pathreg
|
||||
todo!()
|
||||
}
|
||||
|
||||
#[tracing::instrument(ret, level = "debug")]
|
||||
pub fn description<'r, 's>(
|
||||
context: Context<'r, 's>,
|
||||
input: &'s str,
|
||||
) -> Res<&'s str, Vec<Object<'s>>> {
|
||||
let (remaining, _opening_bracket) = tag("[[")(input)?;
|
||||
let parser_context =
|
||||
context.with_additional_node(ContextElement::ExitMatcherNode(ExitMatcherNode {
|
||||
class: ExitClass::Beta,
|
||||
exit_matcher: &description_end,
|
||||
}));
|
||||
let (remaining, (children, _exit_contents)) = verify(
|
||||
many_till(
|
||||
parser_with_context!(regular_link_description_object_set)(&parser_context),
|
||||
parser_with_context!(exit_matcher_parser)(&parser_context),
|
||||
),
|
||||
|(children, _exit_contents)| !children.is_empty(),
|
||||
)(remaining)?;
|
||||
|
||||
Ok((remaining, children))
|
||||
}
|
||||
|
||||
#[tracing::instrument(ret, level = "debug")]
|
||||
fn description_end<'r, 's>(context: Context<'r, 's>, input: &'s str) -> Res<&'s str, &'s str> {
|
||||
tag("]]")(input)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user