Merge branch 'target'
This commit is contained in:
commit
cb8775f2f4
3
org_mode_samples/target/simple.org
Normal file
3
org_mode_samples/target/simple.org
Normal file
@ -0,0 +1,3 @@
|
||||
foo <<bar>> baz
|
||||
|
||||
lorem << ipsum >> dolar
|
@ -50,6 +50,7 @@ use crate::parser::StrikeThrough;
|
||||
use crate::parser::Table;
|
||||
use crate::parser::TableCell;
|
||||
use crate::parser::TableRow;
|
||||
use crate::parser::Target;
|
||||
use crate::parser::Underline;
|
||||
use crate::parser::Verbatim;
|
||||
use crate::parser::VerseBlock;
|
||||
@ -172,6 +173,7 @@ fn compare_object<'s>(
|
||||
Object::InlineBabelCall(obj) => compare_inline_babel_call(source, emacs, obj),
|
||||
Object::InlineSourceBlock(obj) => compare_inline_source_block(source, emacs, obj),
|
||||
Object::LineBreak(obj) => compare_line_break(source, emacs, obj),
|
||||
Object::Target(obj) => compare_target(source, emacs, obj),
|
||||
}
|
||||
}
|
||||
|
||||
@ -1463,3 +1465,26 @@ fn compare_line_break<'s>(
|
||||
children: Vec::new(),
|
||||
})
|
||||
}
|
||||
|
||||
fn compare_target<'s>(
|
||||
source: &'s str,
|
||||
emacs: &'s Token<'s>,
|
||||
rust: &'s Target<'s>,
|
||||
) -> Result<DiffResult, Box<dyn std::error::Error>> {
|
||||
let mut this_status = DiffStatus::Good;
|
||||
let emacs_name = "target";
|
||||
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(),
|
||||
})
|
||||
}
|
||||
|
@ -43,6 +43,7 @@ mod regular_link;
|
||||
pub mod sexp;
|
||||
mod source;
|
||||
mod table;
|
||||
mod target;
|
||||
mod text_markup;
|
||||
mod token;
|
||||
mod util;
|
||||
@ -97,6 +98,7 @@ pub use object::RadioLink;
|
||||
pub use object::RadioTarget;
|
||||
pub use object::RegularLink;
|
||||
pub use object::StrikeThrough;
|
||||
pub use object::Target;
|
||||
pub use object::Underline;
|
||||
pub use object::Verbatim;
|
||||
pub use source::Source;
|
||||
|
@ -24,6 +24,7 @@ pub enum Object<'s> {
|
||||
InlineBabelCall(InlineBabelCall<'s>),
|
||||
InlineSourceBlock(InlineSourceBlock<'s>),
|
||||
LineBreak(LineBreak<'s>),
|
||||
Target(Target<'s>),
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq)]
|
||||
@ -155,6 +156,11 @@ pub struct LineBreak<'s> {
|
||||
pub source: &'s str,
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq)]
|
||||
pub struct Target<'s> {
|
||||
pub source: &'s str,
|
||||
}
|
||||
|
||||
impl<'s> Source<'s> for Object<'s> {
|
||||
fn get_source(&'s self) -> &'s str {
|
||||
match self {
|
||||
@ -180,6 +186,7 @@ impl<'s> Source<'s> for Object<'s> {
|
||||
Object::InlineBabelCall(obj) => obj.source,
|
||||
Object::InlineSourceBlock(obj) => obj.source,
|
||||
Object::LineBreak(obj) => obj.source,
|
||||
Object::Target(obj) => obj.source,
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -309,3 +316,9 @@ impl<'s> Source<'s> for LineBreak<'s> {
|
||||
self.source
|
||||
}
|
||||
}
|
||||
|
||||
impl<'s> Source<'s> for Target<'s> {
|
||||
fn get_source(&'s self) -> &'s str {
|
||||
self.source
|
||||
}
|
||||
}
|
||||
|
@ -21,6 +21,7 @@ use crate::parser::org_macro::org_macro;
|
||||
use crate::parser::plain_link::plain_link;
|
||||
use crate::parser::radio_link::radio_link;
|
||||
use crate::parser::radio_link::radio_target;
|
||||
use crate::parser::target::target;
|
||||
use crate::parser::text_markup::text_markup;
|
||||
|
||||
#[tracing::instrument(ret, level = "debug")]
|
||||
@ -32,6 +33,7 @@ pub fn standard_set_object<'r, 's>(
|
||||
not(|i| context.check_exit_matcher(i))(input)?;
|
||||
|
||||
alt((
|
||||
map(parser_with_context!(target)(context), Object::Target),
|
||||
map(parser_with_context!(line_break)(context), Object::LineBreak),
|
||||
map(
|
||||
parser_with_context!(inline_source_block)(context),
|
||||
@ -98,6 +100,7 @@ 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!(target)(context), Object::Target),
|
||||
map(parser_with_context!(line_break)(context), Object::LineBreak),
|
||||
map(
|
||||
parser_with_context!(inline_source_block)(context),
|
||||
|
60
src/parser/target.rs
Normal file
60
src/parser/target.rs
Normal file
@ -0,0 +1,60 @@
|
||||
use nom::bytes::complete::tag;
|
||||
use nom::character::complete::anychar;
|
||||
use nom::character::complete::one_of;
|
||||
use nom::character::complete::space0;
|
||||
use nom::combinator::peek;
|
||||
use nom::combinator::recognize;
|
||||
use nom::combinator::verify;
|
||||
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::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::Target;
|
||||
|
||||
#[tracing::instrument(ret, level = "debug")]
|
||||
pub fn target<'r, 's>(context: Context<'r, 's>, input: &'s str) -> Res<&'s str, Target<'s>> {
|
||||
let (remaining, _) = tag("<<")(input)?;
|
||||
let (remaining, _) = peek(verify(anychar, |c| {
|
||||
!c.is_whitespace() && !"<>\n".contains(*c)
|
||||
}))(remaining)?;
|
||||
|
||||
let parser_context =
|
||||
context.with_additional_node(ContextElement::ExitMatcherNode(ExitMatcherNode {
|
||||
class: ExitClass::Beta,
|
||||
exit_matcher: &target_end,
|
||||
}));
|
||||
let (remaining, body) = recognize(many_till(
|
||||
anychar,
|
||||
parser_with_context!(exit_matcher_parser)(&parser_context),
|
||||
))(remaining)?;
|
||||
|
||||
let document_root = context.get_document_root().unwrap();
|
||||
let preceding_character = get_one_before(document_root, remaining)
|
||||
.map(|slice| slice.chars().next())
|
||||
.flatten()
|
||||
.expect("We cannot be at the start of the file because we are inside a target.");
|
||||
if preceding_character.is_whitespace() {
|
||||
return Err(nom::Err::Error(CustomError::MyError(MyError(
|
||||
"Targets cannot end with whitespace.",
|
||||
))));
|
||||
}
|
||||
let (remaining, _) = tag(">>")(remaining)?;
|
||||
let (remaining, _) = space0(remaining)?;
|
||||
let source = get_consumed(input, remaining);
|
||||
|
||||
Ok((remaining, Target { source }))
|
||||
}
|
||||
|
||||
#[tracing::instrument(ret, level = "debug")]
|
||||
fn target_end<'r, 's>(context: Context<'r, 's>, input: &'s str) -> Res<&'s str, &'s str> {
|
||||
recognize(one_of("<>\n"))(input)
|
||||
}
|
@ -63,6 +63,7 @@ impl<'r, 's> Token<'r, 's> {
|
||||
Object::InlineBabelCall(_) => Box::new(std::iter::empty()),
|
||||
Object::InlineSourceBlock(_) => Box::new(std::iter::empty()),
|
||||
Object::LineBreak(_) => Box::new(std::iter::empty()),
|
||||
Object::Target(_) => Box::new(std::iter::empty()),
|
||||
},
|
||||
Token::Element(elem) => match elem {
|
||||
Element::Paragraph(inner) => Box::new(inner.children.iter().map(Token::Object)),
|
||||
|
Loading…
Reference in New Issue
Block a user