Merge branch 'angle_link'
All checks were successful
semver Build semver has succeeded
rustfmt Build rustfmt has succeeded
rust-test Build rust-test has succeeded

This commit is contained in:
Tom Alexander 2023-07-13 23:02:27 -04:00
commit f65e659052
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE
7 changed files with 148 additions and 6 deletions

View File

@ -0,0 +1,25 @@
non-link text
<eww://foo>
<rmail://foo>
<mhe://foo>
<irc://foo>
<info://foo>
<gnus://foo>
<docview://foo>
<bibtex://foo>
<bbdb://foo>
<w3m://foo>
<doi://foo>
<file+sys://foo>
<file+emacs://foo>
<shell://foo>
<news://foo>
<mailto://foo>
<https://foo>
<http://foo>
<ftp://foo>
<help://foo>
<file://foo>
<elisp://foo>
<randomfakeprotocl://foo>
non-link text

View File

@ -1,6 +1,7 @@
use super::util::assert_bounds;
use super::util::assert_name;
use crate::parser::sexp::Token;
use crate::parser::AngleLink;
use crate::parser::Bold;
use crate::parser::Clock;
use crate::parser::Code;
@ -150,6 +151,7 @@ fn compare_object<'s>(
Object::RadioLink(obj) => compare_radio_link(source, emacs, obj),
Object::RadioTarget(obj) => compare_radio_target(source, emacs, obj),
Object::PlainLink(obj) => compare_plain_link(source, emacs, obj),
Object::AngleLink(obj) => compare_angle_link(source, emacs, obj),
}
}
@ -1188,3 +1190,26 @@ fn compare_plain_link<'s>(
children: Vec::new(),
})
}
fn compare_angle_link<'s>(
source: &'s str,
emacs: &'s Token<'s>,
rust: &'s AngleLink<'s>,
) -> Result<DiffResult, Box<dyn std::error::Error>> {
let mut this_status = DiffStatus::Good;
let emacs_name = "link";
if assert_name(emacs, emacs_name).is_err() {
this_status = DiffStatus::Bad;
}
if assert_bounds(source, emacs, rust).is_err() {
this_status = DiffStatus::Bad;
}
Ok(DiffResult {
status: this_status,
name: emacs_name.to_owned(),
message: None,
children: Vec::new(),
})
}

53
src/parser/angle_link.rs Normal file
View File

@ -0,0 +1,53 @@
use nom::bytes::complete::tag;
use nom::character::complete::anychar;
use nom::combinator::peek;
use nom::combinator::recognize;
use nom::multi::many_till;
use super::Context;
use crate::error::Res;
use crate::parser::exiting::ExitClass;
use crate::parser::parser_context::ContextElement;
use crate::parser::parser_context::ExitMatcherNode;
use crate::parser::parser_with_context::parser_with_context;
use crate::parser::plain_link::protocol;
use crate::parser::util::exit_matcher_parser;
use crate::parser::util::get_consumed;
use crate::parser::AngleLink;
#[tracing::instrument(ret, level = "debug")]
pub fn angle_link<'r, 's>(context: Context<'r, 's>, input: &'s str) -> Res<&'s str, AngleLink<'s>> {
let (remaining, _) = tag("<")(input)?;
let (remaining, proto) = protocol(context, remaining)?;
let (remaining, _separator) = tag(":")(remaining)?;
let (remaining, path) = path_angle(context, remaining)?;
let (remaining, _) = tag(">")(remaining)?;
let source = get_consumed(input, remaining);
Ok((
remaining,
AngleLink {
source,
link_type: proto,
path,
},
))
}
#[tracing::instrument(ret, level = "debug")]
fn path_angle<'r, 's>(context: Context<'r, 's>, input: &'s str) -> Res<&'s str, &'s str> {
let parser_context =
context.with_additional_node(ContextElement::ExitMatcherNode(ExitMatcherNode {
class: ExitClass::Beta,
exit_matcher: &path_angle_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_angle_end<'r, 's>(context: Context<'r, 's>, input: &'s str) -> Res<&'s str, &'s str> {
tag(">")(input)
}

View File

@ -1,3 +1,4 @@
mod angle_link;
mod clock;
mod comment;
mod diary_sexp;
@ -64,6 +65,7 @@ pub use lesser_element::Planning;
pub use lesser_element::SrcBlock;
pub use lesser_element::TableCell;
pub use lesser_element::VerseBlock;
pub use object::AngleLink;
pub use object::Bold;
pub use object::Code;
pub use object::Italic;

View File

@ -6,6 +6,7 @@ pub enum Object<'s> {
RadioLink(RadioLink<'s>),
RadioTarget(RadioTarget<'s>),
PlainLink(PlainLink<'s>),
AngleLink(AngleLink<'s>),
Bold(Bold<'s>),
Italic(Italic<'s>),
Underline(Underline<'s>),
@ -80,6 +81,13 @@ pub struct PlainLink<'s> {
pub path: &'s str,
}
#[derive(Debug, PartialEq)]
pub struct AngleLink<'s> {
pub source: &'s str,
pub link_type: &'s str,
pub path: &'s str,
}
impl<'s> Source<'s> for Object<'s> {
fn get_source(&'s self) -> &'s str {
match self {
@ -94,6 +102,7 @@ impl<'s> Source<'s> for Object<'s> {
Object::RadioLink(obj) => obj.source,
Object::RadioTarget(obj) => obj.source,
Object::PlainLink(obj) => obj.source,
Object::AngleLink(obj) => obj.source,
}
}
}
@ -157,3 +166,9 @@ impl<'s> Source<'s> for PlainLink<'s> {
self.source
}
}
impl<'s> Source<'s> for AngleLink<'s> {
fn get_source(&'s self) -> &'s str {
self.source
}
}

View File

@ -7,6 +7,7 @@ use super::plain_text::plain_text;
use super::regular_link::regular_link;
use super::Context;
use crate::error::Res;
use crate::parser::angle_link::angle_link;
use crate::parser::object::Object;
use crate::parser::plain_link::plain_link;
use crate::parser::radio_link::radio_link;
@ -33,6 +34,7 @@ pub fn standard_set_object<'r, 's>(
Object::RegularLink,
),
map(parser_with_context!(plain_link)(context), Object::PlainLink),
map(parser_with_context!(angle_link)(context), Object::AngleLink),
map(parser_with_context!(plain_text)(context), Object::PlainText),
))(input)
}
@ -69,6 +71,7 @@ pub fn any_object_except_plain_text<'r, 's>(
Object::RegularLink,
),
map(parser_with_context!(plain_link)(context), Object::PlainLink),
map(parser_with_context!(angle_link)(context), Object::AngleLink),
))(input)
}

View File

@ -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;
@ -36,7 +42,7 @@ pub fn plain_link<'r, 's>(context: Context<'r, 's>, input: &'s str) -> Res<&'s s
}
#[tracing::instrument(ret, level = "debug")]
pub fn pre<'r, 's>(context: Context<'r, 's>, input: &'s str) -> Res<&'s str, ()> {
fn pre<'r, 's>(context: Context<'r, 's>, input: &'s str) -> Res<&'s str, ()> {
let document_root = context.get_document_root().unwrap();
let preceding_character = get_one_before(document_root, input)
.map(|slice| slice.chars().next())
@ -56,7 +62,7 @@ pub fn pre<'r, 's>(context: Context<'r, 's>, input: &'s str) -> Res<&'s str, ()>
}
#[tracing::instrument(ret, level = "debug")]
pub fn post<'r, 's>(context: Context<'r, 's>, input: &'s str) -> Res<&'s str, ()> {
fn post<'r, 's>(context: Context<'r, 's>, input: &'s str) -> Res<&'s str, ()> {
let (remaining, _) = alt((eof, recognize(none_of(WORD_CONSTITUENT_CHARACTERS))))(input)?;
Ok((remaining, ()))
}
@ -97,8 +103,21 @@ 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> {
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)
}