Merge branch 'statistics_cookie'
This commit is contained in:
commit
7d73ac4bf6
3
org_mode_samples/statistics_cookie/simple.org
Normal file
3
org_mode_samples/statistics_cookie/simple.org
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
[70%]
|
||||||
|
[3/5]
|
||||||
|
[-3/5]
|
@ -46,6 +46,7 @@ use crate::parser::RadioTarget;
|
|||||||
use crate::parser::RegularLink;
|
use crate::parser::RegularLink;
|
||||||
use crate::parser::Section;
|
use crate::parser::Section;
|
||||||
use crate::parser::SrcBlock;
|
use crate::parser::SrcBlock;
|
||||||
|
use crate::parser::StatisticsCookie;
|
||||||
use crate::parser::StrikeThrough;
|
use crate::parser::StrikeThrough;
|
||||||
use crate::parser::Table;
|
use crate::parser::Table;
|
||||||
use crate::parser::TableCell;
|
use crate::parser::TableCell;
|
||||||
@ -174,6 +175,7 @@ fn compare_object<'s>(
|
|||||||
Object::InlineSourceBlock(obj) => compare_inline_source_block(source, emacs, obj),
|
Object::InlineSourceBlock(obj) => compare_inline_source_block(source, emacs, obj),
|
||||||
Object::LineBreak(obj) => compare_line_break(source, emacs, obj),
|
Object::LineBreak(obj) => compare_line_break(source, emacs, obj),
|
||||||
Object::Target(obj) => compare_target(source, emacs, obj),
|
Object::Target(obj) => compare_target(source, emacs, obj),
|
||||||
|
Object::StatisticsCookie(obj) => compare_statistics_cookie(source, emacs, obj),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1488,3 +1490,26 @@ fn compare_target<'s>(
|
|||||||
children: Vec::new(),
|
children: Vec::new(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn compare_statistics_cookie<'s>(
|
||||||
|
source: &'s str,
|
||||||
|
emacs: &'s Token<'s>,
|
||||||
|
rust: &'s StatisticsCookie<'s>,
|
||||||
|
) -> Result<DiffResult, Box<dyn std::error::Error>> {
|
||||||
|
let mut this_status = DiffStatus::Good;
|
||||||
|
let emacs_name = "statistics-cookie";
|
||||||
|
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(),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
@ -42,6 +42,7 @@ mod radio_link;
|
|||||||
mod regular_link;
|
mod regular_link;
|
||||||
pub mod sexp;
|
pub mod sexp;
|
||||||
mod source;
|
mod source;
|
||||||
|
mod statistics_cookie;
|
||||||
mod table;
|
mod table;
|
||||||
mod target;
|
mod target;
|
||||||
mod text_markup;
|
mod text_markup;
|
||||||
@ -97,6 +98,7 @@ pub use object::PlainText;
|
|||||||
pub use object::RadioLink;
|
pub use object::RadioLink;
|
||||||
pub use object::RadioTarget;
|
pub use object::RadioTarget;
|
||||||
pub use object::RegularLink;
|
pub use object::RegularLink;
|
||||||
|
pub use object::StatisticsCookie;
|
||||||
pub use object::StrikeThrough;
|
pub use object::StrikeThrough;
|
||||||
pub use object::Target;
|
pub use object::Target;
|
||||||
pub use object::Underline;
|
pub use object::Underline;
|
||||||
|
@ -25,6 +25,7 @@ pub enum Object<'s> {
|
|||||||
InlineSourceBlock(InlineSourceBlock<'s>),
|
InlineSourceBlock(InlineSourceBlock<'s>),
|
||||||
LineBreak(LineBreak<'s>),
|
LineBreak(LineBreak<'s>),
|
||||||
Target(Target<'s>),
|
Target(Target<'s>),
|
||||||
|
StatisticsCookie(StatisticsCookie<'s>),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, PartialEq)]
|
#[derive(Debug, PartialEq)]
|
||||||
@ -161,6 +162,11 @@ pub struct Target<'s> {
|
|||||||
pub source: &'s str,
|
pub source: &'s str,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, PartialEq)]
|
||||||
|
pub struct StatisticsCookie<'s> {
|
||||||
|
pub source: &'s str,
|
||||||
|
}
|
||||||
|
|
||||||
impl<'s> Source<'s> for Object<'s> {
|
impl<'s> Source<'s> for Object<'s> {
|
||||||
fn get_source(&'s self) -> &'s str {
|
fn get_source(&'s self) -> &'s str {
|
||||||
match self {
|
match self {
|
||||||
@ -187,6 +193,7 @@ impl<'s> Source<'s> for Object<'s> {
|
|||||||
Object::InlineSourceBlock(obj) => obj.source,
|
Object::InlineSourceBlock(obj) => obj.source,
|
||||||
Object::LineBreak(obj) => obj.source,
|
Object::LineBreak(obj) => obj.source,
|
||||||
Object::Target(obj) => obj.source,
|
Object::Target(obj) => obj.source,
|
||||||
|
Object::StatisticsCookie(obj) => obj.source,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -322,3 +329,9 @@ impl<'s> Source<'s> for Target<'s> {
|
|||||||
self.source
|
self.source
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<'s> Source<'s> for StatisticsCookie<'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::plain_link::plain_link;
|
||||||
use crate::parser::radio_link::radio_link;
|
use crate::parser::radio_link::radio_link;
|
||||||
use crate::parser::radio_link::radio_target;
|
use crate::parser::radio_link::radio_target;
|
||||||
|
use crate::parser::statistics_cookie::statistics_cookie;
|
||||||
use crate::parser::target::target;
|
use crate::parser::target::target;
|
||||||
use crate::parser::text_markup::text_markup;
|
use crate::parser::text_markup::text_markup;
|
||||||
|
|
||||||
@ -29,10 +30,14 @@ pub fn standard_set_object<'r, 's>(
|
|||||||
context: Context<'r, 's>,
|
context: Context<'r, 's>,
|
||||||
input: &'s str,
|
input: &'s str,
|
||||||
) -> Res<&'s str, Object<'s>> {
|
) -> Res<&'s str, Object<'s>> {
|
||||||
// TODO: line breaks, targets (different from radio targets), statistics cookies, subscript and superscript, timestamps.
|
// TODO: subscript and superscript, timestamps.
|
||||||
not(|i| context.check_exit_matcher(i))(input)?;
|
not(|i| context.check_exit_matcher(i))(input)?;
|
||||||
|
|
||||||
alt((
|
alt((
|
||||||
|
map(
|
||||||
|
parser_with_context!(statistics_cookie)(context),
|
||||||
|
Object::StatisticsCookie,
|
||||||
|
),
|
||||||
map(parser_with_context!(target)(context), Object::Target),
|
map(parser_with_context!(target)(context), Object::Target),
|
||||||
map(parser_with_context!(line_break)(context), Object::LineBreak),
|
map(parser_with_context!(line_break)(context), Object::LineBreak),
|
||||||
map(
|
map(
|
||||||
@ -100,6 +105,10 @@ pub fn any_object_except_plain_text<'r, 's>(
|
|||||||
) -> Res<&'s str, Object<'s>> {
|
) -> Res<&'s str, Object<'s>> {
|
||||||
// Used for exit matchers so this does not check exit matcher condition.
|
// Used for exit matchers so this does not check exit matcher condition.
|
||||||
alt((
|
alt((
|
||||||
|
map(
|
||||||
|
parser_with_context!(statistics_cookie)(context),
|
||||||
|
Object::StatisticsCookie,
|
||||||
|
),
|
||||||
map(parser_with_context!(target)(context), Object::Target),
|
map(parser_with_context!(target)(context), Object::Target),
|
||||||
map(parser_with_context!(line_break)(context), Object::LineBreak),
|
map(parser_with_context!(line_break)(context), Object::LineBreak),
|
||||||
map(
|
map(
|
||||||
@ -145,8 +154,12 @@ pub fn regular_link_description_object_set<'r, 's>(
|
|||||||
context: Context<'r, 's>,
|
context: Context<'r, 's>,
|
||||||
input: &'s str,
|
input: &'s str,
|
||||||
) -> Res<&'s str, Object<'s>> {
|
) -> Res<&'s str, Object<'s>> {
|
||||||
// TODO: minimal set of objects as well as export snippets, 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 ]]
|
// TODO: add export snippets. It can also contain another link, but only when it is a plain or angle link. It can contain square brackets, but not ]]
|
||||||
alt((
|
alt((
|
||||||
|
map(
|
||||||
|
parser_with_context!(statistics_cookie)(context),
|
||||||
|
Object::StatisticsCookie,
|
||||||
|
),
|
||||||
map(
|
map(
|
||||||
parser_with_context!(inline_source_block)(context),
|
parser_with_context!(inline_source_block)(context),
|
||||||
Object::InlineSourceBlock,
|
Object::InlineSourceBlock,
|
||||||
|
48
src/parser/statistics_cookie.rs
Normal file
48
src/parser/statistics_cookie.rs
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
use nom::branch::alt;
|
||||||
|
use nom::bytes::complete::tag;
|
||||||
|
use nom::character::complete::space0;
|
||||||
|
use nom::combinator::recognize;
|
||||||
|
use nom::sequence::tuple;
|
||||||
|
|
||||||
|
use super::Context;
|
||||||
|
use crate::error::Res;
|
||||||
|
use crate::parser::parser_with_context::parser_with_context;
|
||||||
|
use crate::parser::StatisticsCookie;
|
||||||
|
|
||||||
|
#[tracing::instrument(ret, level = "debug")]
|
||||||
|
pub fn statistics_cookie<'r, 's>(
|
||||||
|
context: Context<'r, 's>,
|
||||||
|
input: &'s str,
|
||||||
|
) -> Res<&'s str, StatisticsCookie<'s>> {
|
||||||
|
alt((
|
||||||
|
parser_with_context!(percent_statistics_cookie)(context),
|
||||||
|
parser_with_context!(fraction_statistics_cookie)(context),
|
||||||
|
))(input)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tracing::instrument(ret, level = "debug")]
|
||||||
|
pub fn percent_statistics_cookie<'r, 's>(
|
||||||
|
context: Context<'r, 's>,
|
||||||
|
input: &'s str,
|
||||||
|
) -> Res<&'s str, StatisticsCookie<'s>> {
|
||||||
|
let (remaining, source) =
|
||||||
|
recognize(tuple((tag("["), nom::character::complete::u64, tag("%]"))))(input)?;
|
||||||
|
let (remaining, _) = space0(remaining)?;
|
||||||
|
Ok((remaining, StatisticsCookie { source }))
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tracing::instrument(ret, level = "debug")]
|
||||||
|
pub fn fraction_statistics_cookie<'r, 's>(
|
||||||
|
context: Context<'r, 's>,
|
||||||
|
input: &'s str,
|
||||||
|
) -> Res<&'s str, StatisticsCookie<'s>> {
|
||||||
|
let (remaining, source) = recognize(tuple((
|
||||||
|
tag("["),
|
||||||
|
nom::character::complete::u64,
|
||||||
|
tag("/"),
|
||||||
|
nom::character::complete::u64,
|
||||||
|
tag("]"),
|
||||||
|
)))(input)?;
|
||||||
|
let (remaining, _) = space0(remaining)?;
|
||||||
|
Ok((remaining, StatisticsCookie { source }))
|
||||||
|
}
|
@ -64,6 +64,7 @@ impl<'r, 's> Token<'r, 's> {
|
|||||||
Object::InlineSourceBlock(_) => Box::new(std::iter::empty()),
|
Object::InlineSourceBlock(_) => Box::new(std::iter::empty()),
|
||||||
Object::LineBreak(_) => Box::new(std::iter::empty()),
|
Object::LineBreak(_) => Box::new(std::iter::empty()),
|
||||||
Object::Target(_) => Box::new(std::iter::empty()),
|
Object::Target(_) => Box::new(std::iter::empty()),
|
||||||
|
Object::StatisticsCookie(_) => Box::new(std::iter::empty()),
|
||||||
},
|
},
|
||||||
Token::Element(elem) => match elem {
|
Token::Element(elem) => match elem {
|
||||||
Element::Paragraph(inner) => Box::new(inner.children.iter().map(Token::Object)),
|
Element::Paragraph(inner) => Box::new(inner.children.iter().map(Token::Object)),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user