diff --git a/src/parser/plain_link.rs b/src/parser/plain_link.rs index 92fd700..4b2c626 100644 --- a/src/parser/plain_link.rs +++ b/src/parser/plain_link.rs @@ -1,18 +1,24 @@ use nom::branch::alt; use nom::bytes::complete::tag; use nom::bytes::complete::tag_no_case; -use nom::bytes::complete::take_while; +use nom::character::complete::anychar; use nom::character::complete::none_of; +use nom::character::complete::one_of; use nom::combinator::eof; use nom::combinator::peek; use nom::combinator::recognize; +use nom::multi::many_till; use super::Context; use crate::error::CustomError; use crate::error::MyError; use crate::error::Res; +use crate::parser::exiting::ExitClass; use crate::parser::object::PlainLink; +use crate::parser::parser_context::ContextElement; +use crate::parser::parser_context::ExitMatcherNode; use crate::parser::parser_with_context::parser_with_context; +use crate::parser::util::exit_matcher_parser; use crate::parser::util::get_consumed; use crate::parser::util::get_one_before; use crate::parser::util::WORD_CONSTITUENT_CHARACTERS; @@ -99,6 +105,19 @@ pub fn protocol<'r, 's>(context: Context<'r, 's>, input: &'s str) -> Res<&'s str #[tracing::instrument(ret, level = "debug")] pub fn path_plain<'r, 's>(context: Context<'r, 's>, input: &'s str) -> Res<&'s str, &'s str> { // TODO: "optionally containing parenthesis-wrapped non-whitespace non-bracket substrings up to a depth of two. The string must end with either a non-punctation non-whitespace character, a forwards slash, or a parenthesis-wrapped substring" - take_while(|c| !" \t\r\n()[]<>".contains(c))(input) - // recognize(many1(none_of(" \t\r\n()[]<>")))(input) + let parser_context = + context.with_additional_node(ContextElement::ExitMatcherNode(ExitMatcherNode { + class: ExitClass::Beta, + exit_matcher: &path_plain_end, + })); + + let exit_matcher = parser_with_context!(exit_matcher_parser)(&parser_context); + + let (remaining, path) = recognize(many_till(anychar, peek(exit_matcher)))(input)?; + Ok((remaining, path)) +} + +#[tracing::instrument(ret, level = "debug")] +fn path_plain_end<'r, 's>(context: Context<'r, 's>, input: &'s str) -> Res<&'s str, &'s str> { + recognize(one_of(" \t\r\n()[]<>"))(input) }