Compare commits
35 Commits
28f12a04f7
...
v0.1.13
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
59222c58b1 | ||
|
|
4d95a7f244 | ||
|
|
5a8159eed7 | ||
|
|
e24fcb9ded | ||
|
|
4b94dc60d2 | ||
|
|
2046603d01 | ||
|
|
30412361e1 | ||
|
|
e846c85188 | ||
|
|
99b74095e6 | ||
|
|
6b802d36bf | ||
|
|
33ca43ca40 | ||
|
|
f5280a3090 | ||
|
|
c28d8ccea4 | ||
|
|
9690545901 | ||
|
|
eba4fb94cf | ||
|
|
565978225a | ||
|
|
cce9ca87fa | ||
|
|
683c523ece | ||
|
|
7a4dc20dc9 | ||
|
|
022dda06eb | ||
|
|
7b88a2d248 | ||
|
|
fce5b92091 | ||
|
|
45a506334c | ||
|
|
e47901a67f | ||
|
|
7430daa768 | ||
|
|
6ce25c8a3b | ||
|
|
7b8fa1eb4a | ||
|
|
ffa5349f25 | ||
|
|
bb472b63cc | ||
|
|
57f566a7a1 | ||
|
|
2181993246 | ||
|
|
60d1ecfa75 | ||
|
|
3962db12a8 | ||
|
|
f192507cd9 | ||
|
|
252be3e001 |
@@ -2,7 +2,7 @@
|
||||
|
||||
[package]
|
||||
name = "organic"
|
||||
version = "0.1.12"
|
||||
version = "0.1.13"
|
||||
authors = ["Tom Alexander <tom@fizz.buzz>"]
|
||||
description = "An org-mode parser."
|
||||
edition = "2021"
|
||||
|
||||
0
org_mode_samples/document/empty.org
Normal file
0
org_mode_samples/document/empty.org
Normal file
4
org_mode_samples/document/only_line_breaks.org
Normal file
4
org_mode_samples/document/only_line_breaks.org
Normal file
@@ -0,0 +1,4 @@
|
||||
|
||||
|
||||
|
||||
|
||||
5
org_mode_samples/document/post_blank.org
Normal file
5
org_mode_samples/document/post_blank.org
Normal file
@@ -0,0 +1,5 @@
|
||||
* foo
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,3 +1,32 @@
|
||||
* Empty
|
||||
:PROPERTIES:
|
||||
:END:
|
||||
* Single new line
|
||||
:PROPERTIES:
|
||||
|
||||
:END:
|
||||
* Single line with spaces
|
||||
:PROPERTIES:
|
||||
|
||||
:END:
|
||||
* Many lines, first line without spaces
|
||||
:PROPERTIES:
|
||||
|
||||
|
||||
|
||||
|
||||
:END:
|
||||
* Many lines, first line with spaces
|
||||
:PROPERTIES:
|
||||
|
||||
|
||||
|
||||
|
||||
:END:
|
||||
* Many lines, first line with spaces, later line with spaces
|
||||
:PROPERTIES:
|
||||
|
||||
|
||||
|
||||
|
||||
:END:
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
: foo
|
||||
:
|
||||
: bar
|
||||
@@ -0,0 +1,6 @@
|
||||
1. foo
|
||||
#+begin_src text
|
||||
|
||||
#+end_src
|
||||
|
||||
2. baz
|
||||
3
org_mode_samples/object/target/simple.org
Normal file
3
org_mode_samples/object/target/simple.org
Normal file
@@ -0,0 +1,3 @@
|
||||
<<FOO>> bar
|
||||
|
||||
[[FOO][baz]]
|
||||
@@ -0,0 +1,5 @@
|
||||
* foo
|
||||
|
||||
** bar
|
||||
|
||||
* baz
|
||||
@@ -139,7 +139,7 @@ fn assert_post_blank<'b, 's, S: StandardProperties<'s> + ?Sized>(
|
||||
.post_blank
|
||||
.ok_or("Token should have a post-blank.")?;
|
||||
if rust_post_blank as usize != emacs_post_blank {
|
||||
Err(format!("Rust post-blank (in chars) {rust_post_blank} does not match emacs post-blank ({emacs_post_blank})", rust_post_blank = rust_post_blank, emacs_post_blank = emacs_post_blank))?;
|
||||
Err(format!("Rust post-blank {rust_post_blank} does not match emacs post-blank ({emacs_post_blank})", rust_post_blank = rust_post_blank, emacs_post_blank = emacs_post_blank))?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
@@ -285,7 +285,7 @@ where
|
||||
pub(crate) fn compare_children<'b, 's, 'x, RC>(
|
||||
source: &'s str,
|
||||
emacs: &'b Token<'s>,
|
||||
rust_children: &'x Vec<RC>,
|
||||
rust_children: &'x [RC],
|
||||
child_status: &mut Vec<DiffEntry<'b, 's>>,
|
||||
this_status: &mut DiffStatus,
|
||||
message: &mut Option<String>,
|
||||
|
||||
@@ -27,7 +27,7 @@ pub(crate) fn record_event(event_type: EventType, input: OrgSource<'_>) {
|
||||
pub fn report(original_document: &str) {
|
||||
let mut db = GLOBAL_DATA.lock().unwrap();
|
||||
let db = db.get_or_insert_with(HashMap::new);
|
||||
let mut results: Vec<_> = db.iter().map(|(k, v)| (k, v)).collect();
|
||||
let mut results: Vec<_> = db.iter().collect();
|
||||
results.sort_by_key(|(_k, v)| *v);
|
||||
// This would put the most common at the top, but that is a pain when there is already a lot of output from the parser.
|
||||
// results.sort_by(|(_ak, av), (_bk, bv)| bv.cmp(av));
|
||||
|
||||
@@ -63,6 +63,7 @@ pub(crate) fn broken_end<'b, 'g, 'r, 's>(
|
||||
match paragraph.children.first_mut() {
|
||||
Some(Object::PlainText(plain_text)) => {
|
||||
plain_text.source = input.get_until_end_of_str(plain_text.source).into();
|
||||
paragraph.contents = Some(input.get_until_end_of_str(plain_text.source).into());
|
||||
}
|
||||
Some(obj) => {
|
||||
panic!("Unhandled first object type inside bullshitium {:?}", obj);
|
||||
@@ -73,14 +74,18 @@ pub(crate) fn broken_end<'b, 'g, 'r, 's>(
|
||||
};
|
||||
Ok((remaining, paragraph))
|
||||
} else {
|
||||
let (remaining, _trailing_ws) =
|
||||
let (remaining, post_blank) =
|
||||
maybe_consume_trailing_whitespace_if_not_exiting(context, lead_in_remaining)?;
|
||||
|
||||
let body = Into::<&str>::into(input.get_until(lead_in_remaining));
|
||||
|
||||
Ok((
|
||||
remaining,
|
||||
Paragraph::of_text(
|
||||
input.get_until(remaining).into(),
|
||||
input.get_until(lead_in_remaining).into(),
|
||||
body,
|
||||
if !body.is_empty() { Some(body) } else { None },
|
||||
post_blank.map(Into::<&str>::into),
|
||||
),
|
||||
))
|
||||
}
|
||||
@@ -119,6 +124,7 @@ pub(crate) fn broken_dynamic_block<'b, 'g, 'r, 's>(
|
||||
match paragraph.children.first_mut() {
|
||||
Some(Object::PlainText(plain_text)) => {
|
||||
plain_text.source = input.get_until_end_of_str(plain_text.source).into();
|
||||
paragraph.contents = Some(input.get_until_end_of_str(plain_text.source).into());
|
||||
}
|
||||
Some(obj) => {
|
||||
panic!("Unhandled first object type inside bullshitium {:?}", obj);
|
||||
@@ -129,14 +135,18 @@ pub(crate) fn broken_dynamic_block<'b, 'g, 'r, 's>(
|
||||
};
|
||||
Ok((remaining, paragraph))
|
||||
} else {
|
||||
let (remaining, _trailing_ws) =
|
||||
let (remaining, post_blank) =
|
||||
maybe_consume_trailing_whitespace_if_not_exiting(context, lead_in_remaining)?;
|
||||
|
||||
let body = Into::<&str>::into(input.get_until(lead_in_remaining));
|
||||
|
||||
Ok((
|
||||
remaining,
|
||||
Paragraph::of_text(
|
||||
input.get_until(remaining).into(),
|
||||
input.get_until(lead_in_remaining).into(),
|
||||
body,
|
||||
if !body.is_empty() { Some(body) } else { None },
|
||||
post_blank.map(Into::<&str>::into),
|
||||
),
|
||||
))
|
||||
}
|
||||
|
||||
@@ -82,7 +82,7 @@ fn clock_timestamp<'b, 'g, 'r, 's>(
|
||||
|(timestamp, duration)| (timestamp, duration.map(Into::<&str>::into)),
|
||||
),
|
||||
map(
|
||||
parser_with_context!(inactive_timestamp)(context),
|
||||
parser_with_context!(inactive_timestamp(true))(context),
|
||||
|timestamp| (timestamp, None),
|
||||
),
|
||||
))(input)
|
||||
|
||||
@@ -31,7 +31,7 @@ where
|
||||
let (remaining, value) = recognize(tuple((tag("%%("), is_not("\r\n"))))(remaining)?;
|
||||
let (remaining, _eol) = org_line_ending(remaining)?;
|
||||
|
||||
let (remaining, _trailing_ws) =
|
||||
let (remaining, post_blank) =
|
||||
maybe_consume_trailing_whitespace_if_not_exiting(context, remaining)?;
|
||||
let source = get_consumed(input, remaining);
|
||||
Ok((
|
||||
@@ -43,6 +43,7 @@ where
|
||||
affiliated_keywords,
|
||||
),
|
||||
value: Into::<&str>::into(value),
|
||||
post_blank: post_blank.map(Into::<&str>::into),
|
||||
},
|
||||
))
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ use std::path::Path;
|
||||
use nom::combinator::all_consuming;
|
||||
use nom::combinator::opt;
|
||||
use nom::multi::many0;
|
||||
use nom::InputTake;
|
||||
|
||||
use super::headline::heading;
|
||||
use super::in_buffer_settings::apply_in_buffer_settings;
|
||||
@@ -181,8 +182,10 @@ fn _document<'b, 'g, 'r, 's>(
|
||||
let zeroth_section_matcher = parser_with_context!(zeroth_section)(context);
|
||||
let heading_matcher = parser_with_context!(heading(0))(context);
|
||||
let (remaining, _blank_lines) = many0(blank_line)(input)?;
|
||||
let contents_begin = remaining;
|
||||
let (remaining, zeroth_section) = opt(zeroth_section_matcher)(remaining)?;
|
||||
let (remaining, children) = many0(heading_matcher)(remaining)?;
|
||||
let contents = get_consumed(contents_begin, remaining);
|
||||
let source = get_consumed(input, remaining);
|
||||
Ok((
|
||||
remaining,
|
||||
@@ -192,6 +195,11 @@ fn _document<'b, 'g, 'r, 's>(
|
||||
path: None,
|
||||
zeroth_section,
|
||||
children,
|
||||
contents: if contents.len() > 0 {
|
||||
Into::<&str>::into(contents)
|
||||
} else {
|
||||
Into::<&str>::into(remaining.take(0))
|
||||
},
|
||||
},
|
||||
))
|
||||
}
|
||||
|
||||
@@ -13,7 +13,9 @@ use nom::sequence::tuple;
|
||||
|
||||
use super::affiliated_keyword::parse_affiliated_keywords;
|
||||
use super::org_source::OrgSource;
|
||||
use super::paragraph::empty_paragraph;
|
||||
use super::util::maybe_consume_trailing_whitespace_if_not_exiting;
|
||||
use crate::context::bind_context;
|
||||
use crate::context::parser_with_context;
|
||||
use crate::context::ContextElement;
|
||||
use crate::context::ExitClass;
|
||||
@@ -22,7 +24,6 @@ use crate::context::RefContext;
|
||||
use crate::error::CustomError;
|
||||
use crate::error::Res;
|
||||
use crate::parser::element_parser::element;
|
||||
use crate::parser::util::blank_line;
|
||||
use crate::parser::util::exit_matcher_parser;
|
||||
use crate::parser::util::get_consumed;
|
||||
use crate::parser::util::immediate_in_section;
|
||||
@@ -31,7 +32,6 @@ use crate::parser::util::WORD_CONSTITUENT_CHARACTERS;
|
||||
use crate::types::Drawer;
|
||||
use crate::types::Element;
|
||||
use crate::types::Keyword;
|
||||
use crate::types::Paragraph;
|
||||
|
||||
#[cfg_attr(
|
||||
feature = "tracing",
|
||||
@@ -107,23 +107,14 @@ fn children<'b, 'g, 'r, 's>(
|
||||
let element_matcher = parser_with_context!(element(true))(context);
|
||||
let exit_matcher = parser_with_context!(exit_matcher_parser)(context);
|
||||
|
||||
let (remaining, children) = match tuple((
|
||||
not(exit_matcher),
|
||||
blank_line,
|
||||
many_till(blank_line, exit_matcher),
|
||||
))(input)
|
||||
if let Ok((remaining, (_not_exit, empty_para))) =
|
||||
tuple((not(exit_matcher), bind_context!(empty_paragraph, context)))(input)
|
||||
{
|
||||
Ok((remain, (_not_immediate_exit, first_line, (_trailing_whitespace, _exit_contents)))) => {
|
||||
let source = get_consumed(input, remain);
|
||||
let element = Element::Paragraph(Paragraph::of_text(source.into(), first_line.into()));
|
||||
(remain, vec![element])
|
||||
}
|
||||
Err(_) => {
|
||||
let (remaining, (children, _exit_contents)) =
|
||||
many_till(element_matcher, exit_matcher)(input)?;
|
||||
(remaining, children)
|
||||
}
|
||||
};
|
||||
return Ok((remaining, vec![Element::Paragraph(empty_para)]));
|
||||
}
|
||||
|
||||
let (remaining, (children, _exit_contents)) = many_till(element_matcher, exit_matcher)(input)?;
|
||||
|
||||
Ok((remaining, children))
|
||||
}
|
||||
|
||||
|
||||
@@ -6,20 +6,20 @@ use nom::character::complete::anychar;
|
||||
use nom::character::complete::line_ending;
|
||||
use nom::character::complete::space0;
|
||||
use nom::character::complete::space1;
|
||||
use nom::combinator::consumed;
|
||||
use nom::combinator::eof;
|
||||
use nom::combinator::not;
|
||||
use nom::combinator::opt;
|
||||
use nom::combinator::peek;
|
||||
use nom::combinator::recognize;
|
||||
use nom::multi::many0;
|
||||
use nom::multi::many_till;
|
||||
use nom::sequence::preceded;
|
||||
use nom::sequence::tuple;
|
||||
|
||||
use super::affiliated_keyword::parse_affiliated_keywords;
|
||||
use super::greater_block::leading_blank_lines_end;
|
||||
use super::org_source::OrgSource;
|
||||
use super::paragraph::empty_paragraph;
|
||||
use super::util::maybe_consume_trailing_whitespace_if_not_exiting;
|
||||
use crate::context::bind_context;
|
||||
use crate::context::parser_with_context;
|
||||
use crate::context::ContextElement;
|
||||
use crate::context::ExitClass;
|
||||
@@ -28,7 +28,6 @@ use crate::context::RefContext;
|
||||
use crate::error::CustomError;
|
||||
use crate::error::Res;
|
||||
use crate::parser::element_parser::element;
|
||||
use crate::parser::util::blank_line;
|
||||
use crate::parser::util::exit_matcher_parser;
|
||||
use crate::parser::util::get_consumed;
|
||||
use crate::parser::util::immediate_in_section;
|
||||
@@ -36,7 +35,6 @@ use crate::parser::util::start_of_line;
|
||||
use crate::types::DynamicBlock;
|
||||
use crate::types::Element;
|
||||
use crate::types::Keyword;
|
||||
use crate::types::Paragraph;
|
||||
|
||||
#[cfg_attr(
|
||||
feature = "tracing",
|
||||
@@ -81,23 +79,25 @@ where
|
||||
let element_matcher = parser_with_context!(element(true))(&parser_context);
|
||||
let exit_matcher = parser_with_context!(exit_matcher_parser)(&parser_context);
|
||||
not(exit_matcher)(remaining)?;
|
||||
let (remaining, leading_blank_lines) = opt(consumed(tuple((
|
||||
blank_line,
|
||||
many0(preceded(not(exit_matcher), blank_line)),
|
||||
))))(remaining)?;
|
||||
let leading_blank_lines =
|
||||
leading_blank_lines.map(|(source, (first_line, _remaining_lines))| {
|
||||
Element::Paragraph(Paragraph::of_text(source.into(), first_line.into()))
|
||||
});
|
||||
let contents_begin = remaining;
|
||||
let blank_line_context = ContextElement::ExitMatcherNode(ExitMatcherNode {
|
||||
class: ExitClass::Alpha,
|
||||
exit_matcher: &leading_blank_lines_end,
|
||||
});
|
||||
let blank_line_context = parser_context.with_additional_node(&blank_line_context);
|
||||
|
||||
let (remaining, leading_blank_lines) =
|
||||
opt(bind_context!(empty_paragraph, &blank_line_context))(remaining)?;
|
||||
let (remaining, (mut children, _exit_contents)) =
|
||||
many_till(element_matcher, exit_matcher)(remaining)?;
|
||||
if let Some(lines) = leading_blank_lines {
|
||||
children.insert(0, lines);
|
||||
children.insert(0, Element::Paragraph(lines));
|
||||
}
|
||||
let contents = get_consumed(contents_begin, remaining);
|
||||
|
||||
let (remaining, _end) = dynamic_block_end(&parser_context, remaining)?;
|
||||
|
||||
let (remaining, _trailing_ws) =
|
||||
let (remaining, post_blank) =
|
||||
maybe_consume_trailing_whitespace_if_not_exiting(context, remaining)?;
|
||||
let source = get_consumed(input, remaining);
|
||||
Ok((
|
||||
@@ -111,6 +111,12 @@ where
|
||||
block_name: name.into(),
|
||||
parameters: parameters.map(|val| val.into()),
|
||||
children,
|
||||
contents: if contents.len() > 0 {
|
||||
Some(Into::<&str>::into(contents))
|
||||
} else {
|
||||
None
|
||||
},
|
||||
post_blank: post_blank.map(Into::<&str>::into),
|
||||
},
|
||||
))
|
||||
}
|
||||
|
||||
@@ -2,12 +2,15 @@ use nom::branch::alt;
|
||||
use nom::bytes::complete::tag;
|
||||
use nom::character::complete::anychar;
|
||||
use nom::character::complete::space0;
|
||||
use nom::combinator::map;
|
||||
use nom::combinator::not;
|
||||
use nom::combinator::peek;
|
||||
use nom::combinator::recognize;
|
||||
use nom::multi::many0;
|
||||
use nom::multi::many_till;
|
||||
use nom::sequence::preceded;
|
||||
use nom::sequence::tuple;
|
||||
use nom::InputTake;
|
||||
|
||||
use super::affiliated_keyword::parse_affiliated_keywords;
|
||||
use super::org_source::OrgSource;
|
||||
@@ -35,28 +38,25 @@ pub(crate) fn fixed_width_area<'b, 'g, 'r, 's, AK>(
|
||||
where
|
||||
AK: IntoIterator<Item = Keyword<'s>>,
|
||||
{
|
||||
let fixed_width_area_line_matcher = parser_with_context!(fixed_width_area_line)(context);
|
||||
let exit_matcher = parser_with_context!(exit_matcher_parser)(context);
|
||||
let (remaining, first_line) = fixed_width_area_line_matcher(remaining)?;
|
||||
let (remaining, mut remaining_lines) =
|
||||
many0(preceded(not(exit_matcher), fixed_width_area_line_matcher))(remaining)?;
|
||||
let (remaining, first_line) = fixed_width_area_line(remaining)?;
|
||||
let (remaining, remaining_lines) = many0(preceded(
|
||||
not(tuple((org_line_ending, exit_matcher))),
|
||||
map(
|
||||
tuple((org_line_ending, fixed_width_area_line)),
|
||||
|(_line_ending, line_contents)| line_contents,
|
||||
),
|
||||
))(remaining)?;
|
||||
|
||||
let (remaining, _trailing_ws) =
|
||||
let post_blank_begin = remaining;
|
||||
let (remaining, _first_line_break) = org_line_ending(remaining)?;
|
||||
let (remaining, _additional_post_blank) =
|
||||
maybe_consume_trailing_whitespace_if_not_exiting(context, remaining)?;
|
||||
let post_blank = get_consumed(post_blank_begin, remaining);
|
||||
let source = get_consumed(input, remaining);
|
||||
let mut value = Vec::with_capacity(remaining_lines.len() + 1);
|
||||
let last_line = remaining_lines.pop();
|
||||
if let Some(last_line) = last_line {
|
||||
value.push(Into::<&str>::into(first_line));
|
||||
value.extend(remaining_lines.into_iter().map(Into::<&str>::into));
|
||||
let last_line = Into::<&str>::into(last_line);
|
||||
// Trim the line ending from the final line.
|
||||
value.push(&last_line[..(last_line.len() - 1)])
|
||||
} else {
|
||||
// Trim the line ending from the only line.
|
||||
let only_line = Into::<&str>::into(first_line);
|
||||
value.push(&only_line[..(only_line.len() - 1)])
|
||||
}
|
||||
value.push(Into::<&str>::into(first_line));
|
||||
value.extend(remaining_lines.into_iter().map(Into::<&str>::into));
|
||||
Ok((
|
||||
remaining,
|
||||
FixedWidthArea {
|
||||
@@ -66,25 +66,24 @@ where
|
||||
affiliated_keywords,
|
||||
),
|
||||
value,
|
||||
post_blank: if post_blank.len() > 0 {
|
||||
Some(Into::<&str>::into(post_blank))
|
||||
} else {
|
||||
None
|
||||
},
|
||||
},
|
||||
))
|
||||
}
|
||||
|
||||
#[cfg_attr(
|
||||
feature = "tracing",
|
||||
tracing::instrument(ret, level = "debug", skip(_context))
|
||||
)]
|
||||
fn fixed_width_area_line<'b, 'g, 'r, 's>(
|
||||
_context: RefContext<'b, 'g, 'r, 's>,
|
||||
input: OrgSource<'s>,
|
||||
) -> Res<OrgSource<'s>, OrgSource<'s>> {
|
||||
#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))]
|
||||
fn fixed_width_area_line<'s>(input: OrgSource<'s>) -> Res<OrgSource<'s>, OrgSource<'s>> {
|
||||
start_of_line(input)?;
|
||||
let (remaining, _) = tuple((space0, tag(":")))(input)?;
|
||||
if let Ok((remaining, line_break)) = org_line_ending(remaining) {
|
||||
return Ok((remaining, line_break));
|
||||
if let Ok((_remain, _line_break)) = org_line_ending(remaining) {
|
||||
return Ok((remaining, remaining.take(0)));
|
||||
}
|
||||
let (remaining, _) = tag(" ")(remaining)?;
|
||||
let (remaining, value) = recognize(many_till(anychar, org_line_ending))(remaining)?;
|
||||
let (remaining, value) = recognize(many_till(anychar, peek(org_line_ending)))(remaining)?;
|
||||
Ok((remaining, value))
|
||||
}
|
||||
|
||||
|
||||
@@ -5,22 +5,21 @@ use nom::character::complete::anychar;
|
||||
use nom::character::complete::line_ending;
|
||||
use nom::character::complete::space0;
|
||||
use nom::character::complete::space1;
|
||||
use nom::combinator::consumed;
|
||||
use nom::combinator::eof;
|
||||
use nom::combinator::not;
|
||||
use nom::combinator::opt;
|
||||
use nom::combinator::peek;
|
||||
use nom::combinator::recognize;
|
||||
use nom::combinator::verify;
|
||||
use nom::multi::many0;
|
||||
use nom::multi::many_till;
|
||||
use nom::sequence::preceded;
|
||||
use nom::sequence::tuple;
|
||||
|
||||
use super::affiliated_keyword::parse_affiliated_keywords;
|
||||
use super::org_source::OrgSource;
|
||||
use super::paragraph::empty_paragraph;
|
||||
use super::util::in_section;
|
||||
use super::util::maybe_consume_trailing_whitespace_if_not_exiting;
|
||||
use crate::context::bind_context;
|
||||
use crate::context::parser_with_context;
|
||||
use crate::context::ContextElement;
|
||||
use crate::context::ContextMatcher;
|
||||
@@ -37,7 +36,6 @@ use crate::parser::util::start_of_line;
|
||||
use crate::types::CenterBlock;
|
||||
use crate::types::Element;
|
||||
use crate::types::Keyword;
|
||||
use crate::types::Paragraph;
|
||||
use crate::types::QuoteBlock;
|
||||
use crate::types::SpecialBlock;
|
||||
|
||||
@@ -102,7 +100,7 @@ fn center_block<'b, 'g, 'r, 's, AK>(
|
||||
where
|
||||
AK: IntoIterator<Item = Keyword<'s>>,
|
||||
{
|
||||
let (remaining, (source, children)) = greater_block_body(
|
||||
let (remaining, body) = greater_block_body(
|
||||
context,
|
||||
input,
|
||||
pre_affiliated_keywords_input,
|
||||
@@ -112,12 +110,14 @@ where
|
||||
Ok((
|
||||
remaining,
|
||||
Element::CenterBlock(CenterBlock {
|
||||
source,
|
||||
source: body.source,
|
||||
affiliated_keywords: parse_affiliated_keywords(
|
||||
context.get_global_settings(),
|
||||
affiliated_keywords,
|
||||
),
|
||||
children,
|
||||
children: body.children,
|
||||
contents: body.contents,
|
||||
post_blank: body.post_blank,
|
||||
}),
|
||||
))
|
||||
}
|
||||
@@ -135,7 +135,7 @@ fn quote_block<'b, 'g, 'r, 's, AK>(
|
||||
where
|
||||
AK: IntoIterator<Item = Keyword<'s>>,
|
||||
{
|
||||
let (remaining, (source, children)) = greater_block_body(
|
||||
let (remaining, body) = greater_block_body(
|
||||
context,
|
||||
input,
|
||||
pre_affiliated_keywords_input,
|
||||
@@ -145,12 +145,14 @@ where
|
||||
Ok((
|
||||
remaining,
|
||||
Element::QuoteBlock(QuoteBlock {
|
||||
source,
|
||||
source: body.source,
|
||||
affiliated_keywords: parse_affiliated_keywords(
|
||||
context.get_global_settings(),
|
||||
affiliated_keywords,
|
||||
),
|
||||
children,
|
||||
children: body.children,
|
||||
contents: body.contents,
|
||||
post_blank: body.post_blank,
|
||||
}),
|
||||
))
|
||||
}
|
||||
@@ -196,7 +198,7 @@ where
|
||||
AK: IntoIterator<Item = Keyword<'s>>,
|
||||
{
|
||||
let (remaining, parameters) = opt(tuple((space1, parameters)))(input)?;
|
||||
let (remaining, (source, children)) = greater_block_body(
|
||||
let (remaining, body) = greater_block_body(
|
||||
context,
|
||||
remaining,
|
||||
pre_affiliated_keywords_input,
|
||||
@@ -206,18 +208,28 @@ where
|
||||
Ok((
|
||||
remaining,
|
||||
Element::SpecialBlock(SpecialBlock {
|
||||
source,
|
||||
source: body.source,
|
||||
affiliated_keywords: parse_affiliated_keywords(
|
||||
context.get_global_settings(),
|
||||
affiliated_keywords,
|
||||
),
|
||||
children,
|
||||
children: body.children,
|
||||
block_type: name,
|
||||
parameters: parameters.map(|(_, parameters)| Into::<&str>::into(parameters)),
|
||||
contents: body.contents,
|
||||
post_blank: body.post_blank,
|
||||
}),
|
||||
))
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
struct GreaterBlockBody<'s> {
|
||||
source: &'s str,
|
||||
children: Vec<Element<'s>>,
|
||||
contents: Option<&'s str>,
|
||||
post_blank: Option<&'s str>,
|
||||
}
|
||||
|
||||
#[cfg_attr(
|
||||
feature = "tracing",
|
||||
tracing::instrument(ret, level = "debug", skip(context))
|
||||
@@ -228,7 +240,7 @@ fn greater_block_body<'c, 'b, 'g, 'r, 's>(
|
||||
pre_affiliated_keywords_input: OrgSource<'s>,
|
||||
name: &'c str,
|
||||
context_name: &'c str,
|
||||
) -> Res<OrgSource<'s>, (&'s str, Vec<Element<'s>>)> {
|
||||
) -> Res<OrgSource<'s>, GreaterBlockBody<'s>> {
|
||||
if in_section(context, context_name) {
|
||||
return Err(nom::Err::Error(CustomError::Static(
|
||||
"Cannot nest objects of the same element",
|
||||
@@ -250,28 +262,43 @@ fn greater_block_body<'c, 'b, 'g, 'r, 's>(
|
||||
let element_matcher = parser_with_context!(element(true))(&parser_context);
|
||||
let exit_matcher = parser_with_context!(exit_matcher_parser)(&parser_context);
|
||||
not(exit_matcher)(remaining)?;
|
||||
let (remaining, leading_blank_lines) = opt(consumed(tuple((
|
||||
blank_line,
|
||||
many0(preceded(not(exit_matcher), blank_line)),
|
||||
))))(remaining)?;
|
||||
let leading_blank_lines =
|
||||
leading_blank_lines.map(|(source, (first_line, _remaining_lines))| {
|
||||
Element::Paragraph(Paragraph::of_text(source.into(), first_line.into()))
|
||||
});
|
||||
let contents_begin = remaining;
|
||||
|
||||
let blank_line_context = ContextElement::ExitMatcherNode(ExitMatcherNode {
|
||||
class: ExitClass::Alpha,
|
||||
exit_matcher: &leading_blank_lines_end,
|
||||
});
|
||||
let blank_line_context = parser_context.with_additional_node(&blank_line_context);
|
||||
|
||||
let (remaining, leading_blank_lines) =
|
||||
opt(bind_context!(empty_paragraph, &blank_line_context))(remaining)?;
|
||||
let (remaining, (mut children, _exit_contents)) =
|
||||
many_till(element_matcher, exit_matcher)(remaining)?;
|
||||
if let Some(lines) = leading_blank_lines {
|
||||
children.insert(0, lines);
|
||||
children.insert(0, Element::Paragraph(lines));
|
||||
}
|
||||
let contents = get_consumed(contents_begin, remaining);
|
||||
|
||||
let (remaining, _end) = exit_with_name(&parser_context, remaining)?;
|
||||
|
||||
// Not checking if parent exit matcher is causing exit because the greater_block_end matcher asserts we matched a full greater block
|
||||
|
||||
let (remaining, _trailing_ws) =
|
||||
let (remaining, post_blank) =
|
||||
maybe_consume_trailing_whitespace_if_not_exiting(context, remaining)?;
|
||||
let source = get_consumed(pre_affiliated_keywords_input, remaining);
|
||||
Ok((remaining, (Into::<&str>::into(source), children)))
|
||||
Ok((
|
||||
remaining,
|
||||
GreaterBlockBody {
|
||||
source: Into::<&str>::into(source),
|
||||
children,
|
||||
contents: if contents.len() > 0 {
|
||||
Some(Into::<&str>::into(contents))
|
||||
} else {
|
||||
None
|
||||
},
|
||||
post_blank: post_blank.map(Into::<&str>::into),
|
||||
},
|
||||
))
|
||||
}
|
||||
|
||||
#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))]
|
||||
@@ -307,3 +334,14 @@ fn _greater_block_end<'b, 'g, 'r, 's, 'c>(
|
||||
let source = get_consumed(input, remaining);
|
||||
Ok((remaining, source))
|
||||
}
|
||||
|
||||
#[cfg_attr(
|
||||
feature = "tracing",
|
||||
tracing::instrument(ret, level = "debug", skip(_context))
|
||||
)]
|
||||
pub(crate) fn leading_blank_lines_end<'b, 'g, 'r, 's, 'c>(
|
||||
_context: RefContext<'b, 'g, 'r, 's>,
|
||||
input: OrgSource<'s>,
|
||||
) -> Res<OrgSource<'s>, OrgSource<'s>> {
|
||||
recognize(not(blank_line))(input)
|
||||
}
|
||||
|
||||
@@ -66,6 +66,8 @@ fn _heading<'b, 'g, 'r, 's>(
|
||||
let (remaining, pre_headline) = headline(context, input, parent_star_count)?;
|
||||
let section_matcher = bind_context!(section, context);
|
||||
let heading_matcher = bind_context!(heading(pre_headline.star_count), context);
|
||||
let (contents_begin, _) = opt(many0(blank_line))(remaining)?;
|
||||
let maybe_post_blank = get_consumed(remaining, contents_begin);
|
||||
let (remaining, maybe_section) =
|
||||
opt(map(section_matcher, DocumentElement::Section))(remaining)?;
|
||||
let (remaining, _ws) = opt(tuple((start_of_line, many0(blank_line))))(remaining)?;
|
||||
@@ -82,7 +84,8 @@ fn _heading<'b, 'g, 'r, 's>(
|
||||
}
|
||||
children.insert(0, section);
|
||||
}
|
||||
let remaining = if children.is_empty() {
|
||||
let has_children = !children.is_empty();
|
||||
let remaining = if !has_children {
|
||||
// Support empty headings
|
||||
let (remain, _ws) = many0(blank_line)(remaining)?;
|
||||
remain
|
||||
@@ -91,6 +94,7 @@ fn _heading<'b, 'g, 'r, 's>(
|
||||
};
|
||||
let is_archived = pre_headline.tags.contains(&"ARCHIVE");
|
||||
|
||||
let contents = get_consumed(contents_begin, remaining);
|
||||
let source = get_consumed(input, remaining);
|
||||
Ok((
|
||||
remaining,
|
||||
@@ -112,6 +116,16 @@ fn _heading<'b, 'g, 'r, 's>(
|
||||
scheduled,
|
||||
deadline,
|
||||
closed,
|
||||
contents: if contents.len() > 0 {
|
||||
Some(Into::<&str>::into(contents))
|
||||
} else {
|
||||
None
|
||||
},
|
||||
post_blank: if has_children {
|
||||
None
|
||||
} else {
|
||||
Some(Into::<&str>::into(maybe_post_blank))
|
||||
},
|
||||
},
|
||||
))
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ where
|
||||
space0,
|
||||
alt((line_ending, eof)),
|
||||
)))(remaining)?;
|
||||
let (remaining, _trailing_ws) =
|
||||
let (remaining, post_blank) =
|
||||
maybe_consume_trailing_whitespace_if_not_exiting(context, remaining)?;
|
||||
let source = get_consumed(input, remaining);
|
||||
Ok((
|
||||
@@ -49,6 +49,7 @@ where
|
||||
context.get_global_settings(),
|
||||
affiliated_keywords,
|
||||
),
|
||||
post_blank: post_blank.map(Into::<&str>::into),
|
||||
},
|
||||
))
|
||||
}
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
use nom::branch::alt;
|
||||
use nom::character::complete::space1;
|
||||
use nom::combinator::consumed;
|
||||
use nom::combinator::eof;
|
||||
use nom::combinator::opt;
|
||||
use nom::combinator::recognize;
|
||||
use nom::combinator::verify;
|
||||
use nom::multi::many1;
|
||||
@@ -13,6 +15,7 @@ use super::org_source::OrgSource;
|
||||
use super::util::blank_line;
|
||||
use super::util::get_consumed;
|
||||
use super::util::maybe_consume_trailing_whitespace_if_not_exiting;
|
||||
use super::util::org_line_ending;
|
||||
use crate::context::parser_with_context;
|
||||
use crate::context::ContextElement;
|
||||
use crate::context::ExitClass;
|
||||
@@ -72,6 +75,57 @@ where
|
||||
))
|
||||
}
|
||||
|
||||
#[cfg_attr(
|
||||
feature = "tracing",
|
||||
tracing::instrument(ret, level = "debug", skip(context))
|
||||
)]
|
||||
pub(crate) fn empty_paragraph<'b, 'g, 'r, 's>(
|
||||
context: RefContext<'b, 'g, 'r, 's>,
|
||||
input: OrgSource<'s>,
|
||||
) -> Res<OrgSource<'s>, Paragraph<'s>> {
|
||||
// If it is just a single newline then source, contents, and post-blank are "\n".
|
||||
// If it has multiple newlines then contents is the first "\n" and post-blank is all the new lines.
|
||||
// If there are any spaces on the first line then post-blank excludes the first line.
|
||||
|
||||
let exit_matcher = parser_with_context!(exit_matcher_parser)(context);
|
||||
|
||||
let (remaining, first_line_with_spaces) =
|
||||
opt(recognize(tuple((space1, org_line_ending))))(input)?;
|
||||
|
||||
let post_blank_begin = remaining;
|
||||
|
||||
if let Some(first_line_with_spaces) = first_line_with_spaces {
|
||||
let (remaining, _additional_lines) =
|
||||
recognize(many_till(blank_line, exit_matcher))(remaining)?;
|
||||
let post_blank = get_consumed(post_blank_begin, remaining);
|
||||
let source = get_consumed(input, remaining);
|
||||
Ok((
|
||||
remaining,
|
||||
Paragraph::of_text(
|
||||
Into::<&str>::into(source),
|
||||
Into::<&str>::into(first_line_with_spaces),
|
||||
Some(Into::<&str>::into(first_line_with_spaces)),
|
||||
Some(Into::<&str>::into(post_blank)),
|
||||
),
|
||||
))
|
||||
} else {
|
||||
let (remaining, first_line) = blank_line(remaining)?;
|
||||
let (remaining, _additional_lines) =
|
||||
recognize(many_till(blank_line, exit_matcher))(remaining)?;
|
||||
let post_blank = get_consumed(post_blank_begin, remaining);
|
||||
let source = get_consumed(input, remaining);
|
||||
Ok((
|
||||
remaining,
|
||||
Paragraph::of_text(
|
||||
Into::<&str>::into(source),
|
||||
Into::<&str>::into(first_line),
|
||||
Some(Into::<&str>::into(first_line)),
|
||||
Some(Into::<&str>::into(post_blank)),
|
||||
),
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg_attr(
|
||||
feature = "tracing",
|
||||
tracing::instrument(ret, level = "debug", skip(context))
|
||||
@@ -99,6 +153,7 @@ mod tests {
|
||||
use crate::context::List;
|
||||
use crate::parser::element_parser::element;
|
||||
use crate::parser::org_source::OrgSource;
|
||||
use crate::parser::paragraph::empty_paragraph;
|
||||
use crate::types::StandardProperties;
|
||||
|
||||
#[test]
|
||||
@@ -115,4 +170,17 @@ mod tests {
|
||||
assert_eq!(first_paragraph.get_source(), "foo bar baz\n\n");
|
||||
assert_eq!(second_paragraph.get_source(), "lorem ipsum");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn paragraph_whitespace() {
|
||||
let input = OrgSource::new("\n");
|
||||
let global_settings = GlobalSettings::default();
|
||||
let initial_context = ContextElement::document_context();
|
||||
let initial_context = Context::new(&global_settings, List::new(&initial_context));
|
||||
let paragraph_matcher = bind_context!(empty_paragraph, &initial_context);
|
||||
let (remaining, paragraph) = paragraph_matcher(input).expect("Parse paragraph");
|
||||
assert_eq!(Into::<&str>::into(remaining), "");
|
||||
assert_eq!(paragraph.get_source(), "\n");
|
||||
assert_eq!(paragraph.get_contents(), Some("\n"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ use nom::character::complete::multispace1;
|
||||
use nom::character::complete::one_of;
|
||||
use nom::character::complete::space0;
|
||||
use nom::character::complete::space1;
|
||||
use nom::combinator::consumed;
|
||||
use nom::combinator::eof;
|
||||
use nom::combinator::map;
|
||||
use nom::combinator::not;
|
||||
@@ -152,6 +153,7 @@ where
|
||||
let mut children = Vec::new();
|
||||
let mut first_item_indentation: Option<IndentationLevel> = None;
|
||||
let mut first_item_list_type: Option<PlainListType> = None;
|
||||
let contents_begin = remaining;
|
||||
let mut remaining = remaining;
|
||||
|
||||
// The final list item does not consume trailing blank lines (which instead get consumed by the list). We have three options here:
|
||||
@@ -195,7 +197,8 @@ where
|
||||
)));
|
||||
}
|
||||
|
||||
let (remaining, _trailing_ws) =
|
||||
let contents = get_consumed(contents_begin, remaining);
|
||||
let (remaining, post_blank) =
|
||||
maybe_consume_trailing_whitespace_if_not_exiting(context, remaining)?;
|
||||
let source = get_consumed(input, remaining);
|
||||
Ok((
|
||||
@@ -208,6 +211,8 @@ where
|
||||
),
|
||||
list_type: first_item_list_type.expect("Plain lists require at least one element."),
|
||||
children: children.into_iter().map(|(_start, item)| item).collect(),
|
||||
contents: Some(Into::<&str>::into(contents)),
|
||||
post_blank: post_blank.map(Into::<&str>::into),
|
||||
},
|
||||
))
|
||||
}
|
||||
@@ -265,7 +270,7 @@ fn plain_list_item<'b, 'g, 'r, 's>(
|
||||
let maybe_contentless_item: Res<OrgSource<'_>, ()> =
|
||||
detect_contentless_item_contents(&parser_context, remaining);
|
||||
if let Ok((_rem, _ws)) = maybe_contentless_item {
|
||||
let (remaining, _trailing_ws) = if tuple((
|
||||
let (remaining, post_blank) = if tuple((
|
||||
blank_line,
|
||||
bind_context!(final_item_whitespace_cutoff, context),
|
||||
))(remaining)
|
||||
@@ -291,6 +296,12 @@ fn plain_list_item<'b, 'g, 'r, 's>(
|
||||
.unwrap_or(Vec::new()),
|
||||
pre_blank: 0,
|
||||
children: Vec::new(),
|
||||
contents: None,
|
||||
post_blank: if post_blank.len() > 0 {
|
||||
Some(Into::<&str>::into(post_blank))
|
||||
} else {
|
||||
None
|
||||
},
|
||||
},
|
||||
),
|
||||
));
|
||||
@@ -301,13 +312,13 @@ fn plain_list_item<'b, 'g, 'r, 's>(
|
||||
.filter(|b| *b == b'\n')
|
||||
.count();
|
||||
|
||||
let (remaining, (children, _exit_contents)) = many_till(
|
||||
let (remaining, (contents, (children, _exit_contents))) = consumed(many_till(
|
||||
include_input(bind_context!(element(true), &parser_context)),
|
||||
bind_context!(exit_matcher_parser, &parser_context),
|
||||
)(remaining)?;
|
||||
))(remaining)?;
|
||||
|
||||
// We have to use the parser_context here to include the whitespace cut-off
|
||||
let (remaining, _trailing_ws) =
|
||||
let (remaining, post_blank) =
|
||||
maybe_consume_trailing_whitespace_if_not_exiting(&final_whitespace_context, remaining)?;
|
||||
|
||||
let source = get_consumed(input, remaining);
|
||||
@@ -329,6 +340,12 @@ fn plain_list_item<'b, 'g, 'r, 's>(
|
||||
pre_blank: PlainListItemPreBlank::try_from(pre_blank)
|
||||
.expect("pre-blank cannot be larger than 2."),
|
||||
children: children.into_iter().map(|(_start, item)| item).collect(),
|
||||
contents: if contents.len() > 0 {
|
||||
Some(contents.into())
|
||||
} else {
|
||||
None
|
||||
},
|
||||
post_blank: post_blank.map(Into::<&str>::into),
|
||||
},
|
||||
),
|
||||
));
|
||||
|
||||
@@ -33,7 +33,7 @@ pub(crate) fn planning<'b, 'g, 'r, 's>(
|
||||
many1(parser_with_context!(planning_parameter)(context))(remaining)?;
|
||||
let (remaining, _trailing_ws) = tuple((space0, org_line_ending))(remaining)?;
|
||||
|
||||
let (remaining, _trailing_ws) =
|
||||
let (remaining, post_blank) =
|
||||
maybe_consume_trailing_whitespace_if_not_exiting(context, remaining)?;
|
||||
let source = get_consumed(input, remaining);
|
||||
|
||||
@@ -62,6 +62,7 @@ pub(crate) fn planning<'b, 'g, 'r, 's>(
|
||||
scheduled,
|
||||
deadline,
|
||||
closed,
|
||||
post_blank: post_blank.map(Into::<&str>::into),
|
||||
},
|
||||
))
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ use nom::character::complete::anychar;
|
||||
use nom::character::complete::line_ending;
|
||||
use nom::character::complete::space0;
|
||||
use nom::character::complete::space1;
|
||||
use nom::combinator::consumed;
|
||||
use nom::combinator::eof;
|
||||
use nom::combinator::opt;
|
||||
use nom::combinator::recognize;
|
||||
@@ -64,14 +65,11 @@ pub(crate) fn property_drawer<'b, 'g, 'r, 's>(
|
||||
let parser_context = context.with_additional_node(&contexts[0]);
|
||||
let parser_context = parser_context.with_additional_node(&contexts[1]);
|
||||
let parser_context = parser_context.with_additional_node(&contexts[2]);
|
||||
|
||||
let node_property_matcher = parser_with_context!(node_property)(&parser_context);
|
||||
let exit_matcher = parser_with_context!(exit_matcher_parser)(&parser_context);
|
||||
let (remaining, (children, _exit_contents)) =
|
||||
many_till(node_property_matcher, exit_matcher)(remaining)?;
|
||||
let (remaining, (contents, children)) =
|
||||
consumed(parser_with_context!(children)(&parser_context))(remaining)?;
|
||||
let (remaining, _end) = property_drawer_end(&parser_context, remaining)?;
|
||||
|
||||
let (remaining, _trailing_ws) =
|
||||
let (remaining, post_blank) =
|
||||
maybe_consume_trailing_whitespace_if_not_exiting(context, remaining)?;
|
||||
let source = get_consumed(input, remaining);
|
||||
|
||||
@@ -80,10 +78,31 @@ pub(crate) fn property_drawer<'b, 'g, 'r, 's>(
|
||||
PropertyDrawer {
|
||||
source: source.into(),
|
||||
children,
|
||||
contents: if contents.len() > 0 {
|
||||
Some(contents.into())
|
||||
} else {
|
||||
None
|
||||
},
|
||||
post_blank: post_blank.map(Into::<&str>::into),
|
||||
},
|
||||
))
|
||||
}
|
||||
|
||||
#[cfg_attr(
|
||||
feature = "tracing",
|
||||
tracing::instrument(ret, level = "debug", skip(context))
|
||||
)]
|
||||
fn children<'b, 'g, 'r, 's>(
|
||||
context: RefContext<'b, 'g, 'r, 's>,
|
||||
input: OrgSource<'s>,
|
||||
) -> Res<OrgSource<'s>, Vec<NodeProperty<'s>>> {
|
||||
let node_property_matcher = parser_with_context!(node_property)(context);
|
||||
let exit_matcher = parser_with_context!(exit_matcher_parser)(context);
|
||||
let (remaining, (children, _exit_contents)) =
|
||||
many_till(node_property_matcher, exit_matcher)(input)?;
|
||||
Ok((remaining, children))
|
||||
}
|
||||
|
||||
#[cfg_attr(
|
||||
feature = "tracing",
|
||||
tracing::instrument(ret, level = "debug", skip(_context))
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
use nom::combinator::consumed;
|
||||
use nom::combinator::opt;
|
||||
use nom::combinator::recognize;
|
||||
use nom::combinator::verify;
|
||||
@@ -59,12 +58,12 @@ pub(crate) fn zeroth_section<'b, 'g, 'r, 's>(
|
||||
many0(blank_line),
|
||||
)))(input)?;
|
||||
|
||||
let (remaining, (contents, (mut children, _exit_contents))) = consumed(verify(
|
||||
let (remaining, (mut children, _exit_contents)) = verify(
|
||||
many_till(element_matcher, exit_matcher),
|
||||
|(children, _exit_contents)| {
|
||||
!children.is_empty() || comment_and_property_drawer_element.is_some()
|
||||
},
|
||||
))(remaining)?;
|
||||
)(remaining)?;
|
||||
|
||||
if let Some((comment, property_drawer, _ws)) = comment_and_property_drawer_element {
|
||||
children.insert(0, Element::PropertyDrawer(property_drawer));
|
||||
@@ -81,7 +80,6 @@ pub(crate) fn zeroth_section<'b, 'g, 'r, 's>(
|
||||
remaining,
|
||||
Section {
|
||||
source: source.into(),
|
||||
contents: Some(contents.into()),
|
||||
post_blank: post_blank.map(Into::<&str>::into),
|
||||
children,
|
||||
},
|
||||
@@ -118,12 +116,12 @@ pub(crate) fn section<'b, 'g, 'r, 's>(
|
||||
remaining = remain;
|
||||
input = remain;
|
||||
}
|
||||
let (remaining, (contents, (mut children, _exit_contents))) = consumed(verify(
|
||||
let (remaining, (mut children, _exit_contents)) = verify(
|
||||
many_till(element_matcher, exit_matcher),
|
||||
|(children, _exit_contents)| {
|
||||
!children.is_empty() || property_drawer_element.is_some() || planning_element.is_some()
|
||||
},
|
||||
))(remaining)?;
|
||||
)(remaining)?;
|
||||
if let Some(ele) = property_drawer_element.map(Element::PropertyDrawer) {
|
||||
children.insert(0, ele);
|
||||
}
|
||||
@@ -139,7 +137,6 @@ pub(crate) fn section<'b, 'g, 'r, 's>(
|
||||
remaining,
|
||||
Section {
|
||||
source: source.into(),
|
||||
contents: Some(contents.into()),
|
||||
post_blank: post_blank.map(Into::<&str>::into),
|
||||
children,
|
||||
},
|
||||
|
||||
@@ -3,6 +3,7 @@ use nom::bytes::complete::is_not;
|
||||
use nom::bytes::complete::tag;
|
||||
use nom::character::complete::line_ending;
|
||||
use nom::character::complete::space0;
|
||||
use nom::combinator::consumed;
|
||||
use nom::combinator::not;
|
||||
use nom::combinator::opt;
|
||||
use nom::combinator::peek;
|
||||
@@ -67,13 +68,13 @@ where
|
||||
let org_mode_table_row_matcher = parser_with_context!(org_mode_table_row)(&parser_context);
|
||||
let exit_matcher = parser_with_context!(exit_matcher_parser)(&parser_context);
|
||||
|
||||
let (remaining, (children, _exit_contents)) =
|
||||
many_till(org_mode_table_row_matcher, exit_matcher)(remaining)?;
|
||||
let (remaining, (contents, (children, _exit_contents))) =
|
||||
consumed(many_till(org_mode_table_row_matcher, exit_matcher))(remaining)?;
|
||||
|
||||
let (remaining, formulas) =
|
||||
many0(parser_with_context!(table_formula_keyword)(context))(remaining)?;
|
||||
|
||||
let (remaining, _trailing_ws) =
|
||||
let (remaining, post_blank) =
|
||||
maybe_consume_trailing_whitespace_if_not_exiting(context, remaining)?;
|
||||
let source = get_consumed(input, remaining);
|
||||
|
||||
@@ -87,6 +88,8 @@ where
|
||||
),
|
||||
formulas,
|
||||
children,
|
||||
contents: Into::<&str>::into(contents),
|
||||
post_blank: post_blank.map(Into::<&str>::into),
|
||||
},
|
||||
))
|
||||
}
|
||||
@@ -150,6 +153,7 @@ fn org_mode_table_row_rule<'b, 'g, 'r, 's>(
|
||||
TableRow {
|
||||
source: source.into(),
|
||||
children: Vec::new(),
|
||||
contents: None,
|
||||
},
|
||||
))
|
||||
}
|
||||
@@ -164,8 +168,8 @@ fn org_mode_table_row_regular<'b, 'g, 'r, 's>(
|
||||
) -> Res<OrgSource<'s>, TableRow<'s>> {
|
||||
start_of_line(input)?;
|
||||
let (remaining, _) = tuple((space0, tag("|")))(input)?;
|
||||
let (remaining, children) =
|
||||
many1(parser_with_context!(org_mode_table_cell)(context))(remaining)?;
|
||||
let (remaining, (contents, children)) =
|
||||
consumed(many1(parser_with_context!(org_mode_table_cell)(context)))(remaining)?;
|
||||
let (remaining, _tail) = recognize(tuple((space0, org_line_ending)))(remaining)?;
|
||||
let source = get_consumed(input, remaining);
|
||||
Ok((
|
||||
@@ -173,6 +177,11 @@ fn org_mode_table_row_regular<'b, 'g, 'r, 's>(
|
||||
TableRow {
|
||||
source: source.into(),
|
||||
children,
|
||||
contents: if contents.len() > 0 {
|
||||
Some(Into::<&str>::into(contents))
|
||||
} else {
|
||||
None
|
||||
},
|
||||
},
|
||||
))
|
||||
}
|
||||
@@ -194,12 +203,12 @@ fn org_mode_table_cell<'b, 'g, 'r, 's>(
|
||||
parser_with_context!(table_cell_set_object)(&parser_context);
|
||||
let exit_matcher = parser_with_context!(exit_matcher_parser)(&parser_context);
|
||||
let (remaining, _) = space0(input)?;
|
||||
let (remaining, (children, _exit_contents)) = verify(
|
||||
let (remaining, (contents, (children, _exit_contents))) = consumed(verify(
|
||||
many_till(table_cell_set_object_matcher, exit_matcher),
|
||||
|(children, exit_contents)| {
|
||||
!children.is_empty() || Into::<&str>::into(exit_contents).ends_with('|')
|
||||
},
|
||||
)(remaining)?;
|
||||
))(remaining)?;
|
||||
|
||||
let (remaining, _tail) = org_mode_table_cell_end(&parser_context, remaining)?;
|
||||
|
||||
@@ -210,6 +219,7 @@ fn org_mode_table_cell<'b, 'g, 'r, 's>(
|
||||
TableCell {
|
||||
source: source.into(),
|
||||
children,
|
||||
contents: Into::<&str>::into(contents),
|
||||
},
|
||||
))
|
||||
}
|
||||
|
||||
@@ -46,7 +46,7 @@ pub(crate) fn target<'b, 'g, 'r, 's>(
|
||||
)));
|
||||
}
|
||||
let (remaining, _) = tag(">>")(remaining)?;
|
||||
let (remaining, _trailing_whitespace) =
|
||||
let (remaining, post_blank) =
|
||||
maybe_consume_object_trailing_whitespace_if_not_exiting(context, remaining)?;
|
||||
let source = get_consumed(input, remaining);
|
||||
|
||||
@@ -55,6 +55,7 @@ pub(crate) fn target<'b, 'g, 'r, 's>(
|
||||
Target {
|
||||
source: source.into(),
|
||||
value: body.into(),
|
||||
post_blank: post_blank.map(Into::<&str>::into),
|
||||
},
|
||||
))
|
||||
}
|
||||
|
||||
@@ -53,8 +53,8 @@ pub(crate) fn timestamp<'b, 'g, 'r, 's>(
|
||||
parser_with_context!(inactive_time_range_timestamp)(context),
|
||||
parser_with_context!(active_date_range_timestamp)(context),
|
||||
parser_with_context!(inactive_date_range_timestamp)(context),
|
||||
parser_with_context!(active_timestamp)(context),
|
||||
parser_with_context!(inactive_timestamp)(context),
|
||||
parser_with_context!(active_timestamp(true))(context),
|
||||
parser_with_context!(inactive_timestamp(true))(context),
|
||||
))(input)
|
||||
}
|
||||
|
||||
@@ -126,13 +126,23 @@ fn sexp_end<'b, 'g, 'r, 's>(
|
||||
alt((tag(")>"), recognize(one_of(">\n"))))(input)
|
||||
}
|
||||
|
||||
const fn active_timestamp(
|
||||
allow_post_blank: bool,
|
||||
) -> impl for<'b, 'g, 'r, 's> Fn(
|
||||
RefContext<'b, 'g, 'r, 's>,
|
||||
OrgSource<'s>,
|
||||
) -> Res<OrgSource<'s>, Timestamp<'s>> {
|
||||
move |context, input| impl_active_timestamp(context, input, allow_post_blank)
|
||||
}
|
||||
|
||||
#[cfg_attr(
|
||||
feature = "tracing",
|
||||
tracing::instrument(ret, level = "debug", skip(context))
|
||||
)]
|
||||
fn active_timestamp<'b, 'g, 'r, 's>(
|
||||
fn impl_active_timestamp<'b, 'g, 'r, 's>(
|
||||
context: RefContext<'b, 'g, 'r, 's>,
|
||||
input: OrgSource<'s>,
|
||||
allow_post_blank: bool,
|
||||
) -> Res<OrgSource<'s>, Timestamp<'s>> {
|
||||
let (remaining, _) = tag("<")(input)?;
|
||||
let (remaining, start) = date(context, remaining)?;
|
||||
@@ -160,8 +170,11 @@ fn active_timestamp<'b, 'g, 'r, 's>(
|
||||
)))(remaining)?;
|
||||
let (remaining, _) = tag(">")(remaining)?;
|
||||
|
||||
let (remaining, post_blank) =
|
||||
maybe_consume_object_trailing_whitespace_if_not_exiting(context, remaining)?;
|
||||
let (remaining, post_blank) = if allow_post_blank {
|
||||
maybe_consume_object_trailing_whitespace_if_not_exiting(context, remaining)?
|
||||
} else {
|
||||
(remaining, None)
|
||||
};
|
||||
let source = get_consumed(input, remaining);
|
||||
|
||||
Ok((
|
||||
@@ -181,13 +194,23 @@ fn active_timestamp<'b, 'g, 'r, 's>(
|
||||
))
|
||||
}
|
||||
|
||||
pub(crate) const fn inactive_timestamp(
|
||||
allow_post_blank: bool,
|
||||
) -> impl for<'b, 'g, 'r, 's> Fn(
|
||||
RefContext<'b, 'g, 'r, 's>,
|
||||
OrgSource<'s>,
|
||||
) -> Res<OrgSource<'s>, Timestamp<'s>> {
|
||||
move |context, input| impl_inactive_timestamp(context, input, allow_post_blank)
|
||||
}
|
||||
|
||||
#[cfg_attr(
|
||||
feature = "tracing",
|
||||
tracing::instrument(ret, level = "debug", skip(context))
|
||||
)]
|
||||
pub(crate) fn inactive_timestamp<'b, 'g, 'r, 's>(
|
||||
fn impl_inactive_timestamp<'b, 'g, 'r, 's>(
|
||||
context: RefContext<'b, 'g, 'r, 's>,
|
||||
input: OrgSource<'s>,
|
||||
allow_post_blank: bool,
|
||||
) -> Res<OrgSource<'s>, Timestamp<'s>> {
|
||||
let (remaining, _) = tag("[")(input)?;
|
||||
let (remaining, start) = date(context, remaining)?;
|
||||
@@ -215,8 +238,11 @@ pub(crate) fn inactive_timestamp<'b, 'g, 'r, 's>(
|
||||
)))(remaining)?;
|
||||
let (remaining, _) = tag("]")(remaining)?;
|
||||
|
||||
let (remaining, post_blank) =
|
||||
maybe_consume_object_trailing_whitespace_if_not_exiting(context, remaining)?;
|
||||
let (remaining, post_blank) = if allow_post_blank {
|
||||
maybe_consume_object_trailing_whitespace_if_not_exiting(context, remaining)?
|
||||
} else {
|
||||
(remaining, None)
|
||||
};
|
||||
let source = get_consumed(input, remaining);
|
||||
|
||||
Ok((
|
||||
@@ -244,10 +270,10 @@ fn active_date_range_timestamp<'b, 'g, 'r, 's>(
|
||||
context: RefContext<'b, 'g, 'r, 's>,
|
||||
input: OrgSource<'s>,
|
||||
) -> Res<OrgSource<'s>, Timestamp<'s>> {
|
||||
let (remaining, first_timestamp) = active_timestamp(context, input)?;
|
||||
let (remaining, first_timestamp) = impl_active_timestamp(context, input, false)?;
|
||||
// TODO: Does the space0 at the end of the active/inactive timestamp parsers cause this to be incorrect? I could use a look-behind to make sure the preceding character is not whitespace
|
||||
let (remaining, _separator) = tag("--")(remaining)?;
|
||||
let (remaining, second_timestamp) = active_timestamp(context, remaining)?;
|
||||
let (remaining, second_timestamp) = impl_active_timestamp(context, remaining, false)?;
|
||||
|
||||
let (remaining, post_blank) =
|
||||
maybe_consume_object_trailing_whitespace_if_not_exiting(context, remaining)?;
|
||||
@@ -335,10 +361,10 @@ pub(crate) fn inactive_date_range_timestamp<'b, 'g, 'r, 's>(
|
||||
context: RefContext<'b, 'g, 'r, 's>,
|
||||
input: OrgSource<'s>,
|
||||
) -> Res<OrgSource<'s>, Timestamp<'s>> {
|
||||
let (remaining, first_timestamp) = inactive_timestamp(context, input)?;
|
||||
let (remaining, first_timestamp) = impl_inactive_timestamp(context, input, false)?;
|
||||
// TODO: Does the space0 at the end of the active/inactive timestamp parsers cause this to be incorrect? I could use a look-behind to make sure the preceding character is not whitespace
|
||||
let (remaining, _separator) = tag("--")(remaining)?;
|
||||
let (remaining, second_timestamp) = inactive_timestamp(context, remaining)?;
|
||||
let (remaining, second_timestamp) = impl_inactive_timestamp(context, remaining, false)?;
|
||||
|
||||
let (remaining, post_blank) =
|
||||
maybe_consume_object_trailing_whitespace_if_not_exiting(context, remaining)?;
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
use std::path::PathBuf;
|
||||
|
||||
use super::remove_trailing::RemoveTrailing;
|
||||
use super::Element;
|
||||
use super::NodeProperty;
|
||||
use super::Object;
|
||||
@@ -18,6 +17,7 @@ pub struct Document<'s> {
|
||||
pub path: Option<PathBuf>,
|
||||
pub zeroth_section: Option<Section<'s>>,
|
||||
pub children: Vec<Heading<'s>>,
|
||||
pub contents: &'s str,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
@@ -35,12 +35,13 @@ pub struct Heading<'s> {
|
||||
pub scheduled: Option<Timestamp<'s>>,
|
||||
pub deadline: Option<Timestamp<'s>>,
|
||||
pub closed: Option<Timestamp<'s>>,
|
||||
pub contents: Option<&'s str>,
|
||||
pub post_blank: Option<&'s str>,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Section<'s> {
|
||||
pub source: &'s str,
|
||||
pub contents: Option<&'s str>,
|
||||
pub post_blank: Option<&'s str>,
|
||||
pub children: Vec<Element<'s>>,
|
||||
}
|
||||
@@ -63,35 +64,11 @@ impl<'s> StandardProperties<'s> for Document<'s> {
|
||||
}
|
||||
|
||||
fn get_contents<'b>(&'b self) -> Option<&'s str> {
|
||||
let post_blank = self.get_post_blank();
|
||||
let mut content_lines = self
|
||||
.source
|
||||
.split_inclusive('\n')
|
||||
.remove_trailing(post_blank);
|
||||
let first_line = content_lines.next();
|
||||
let last_line = content_lines.last().or(first_line);
|
||||
match (first_line, last_line) {
|
||||
(None, None) => None,
|
||||
(None, Some(_)) | (Some(_), None) => unreachable!(),
|
||||
(Some(first_line), Some(last_line)) => {
|
||||
let first_line_offset = first_line.as_ptr() as usize;
|
||||
let last_line_offset = last_line.as_ptr() as usize + last_line.len();
|
||||
let source_offset = self.source.as_ptr() as usize;
|
||||
debug_assert!(super::lesser_element::is_slice_of(self.source, first_line));
|
||||
debug_assert!(super::lesser_element::is_slice_of(self.source, last_line));
|
||||
Some(
|
||||
&self.source[(first_line_offset - source_offset)
|
||||
..(last_line_offset - first_line_offset)],
|
||||
)
|
||||
}
|
||||
}
|
||||
Some(self.contents)
|
||||
}
|
||||
|
||||
fn get_post_blank(&self) -> PostBlank {
|
||||
self.into_iter()
|
||||
.last()
|
||||
.map(|child| child.get_post_blank())
|
||||
.unwrap_or(0)
|
||||
0
|
||||
}
|
||||
}
|
||||
|
||||
@@ -101,7 +78,7 @@ impl<'s> StandardProperties<'s> for Section<'s> {
|
||||
}
|
||||
|
||||
fn get_contents<'b>(&'b self) -> Option<&'s str> {
|
||||
self.contents
|
||||
Some(self.source)
|
||||
}
|
||||
|
||||
fn get_post_blank(&self) -> PostBlank {
|
||||
@@ -119,39 +96,15 @@ impl<'s> StandardProperties<'s> for Heading<'s> {
|
||||
}
|
||||
|
||||
fn get_contents<'b>(&'b self) -> Option<&'s str> {
|
||||
let first_child = self.children.first();
|
||||
let last_child = self.children.last();
|
||||
match (first_child, last_child) {
|
||||
(None, None) => None,
|
||||
(None, Some(_)) | (Some(_), None) => unreachable!(),
|
||||
(Some(first_child), Some(last_child)) => {
|
||||
let first_child_offset = first_child.get_source().as_ptr() as usize;
|
||||
let last_child_offset = {
|
||||
let last_child_source = last_child.get_source();
|
||||
last_child_source.as_ptr() as usize + last_child_source.len()
|
||||
};
|
||||
let source_offset = self.source.as_ptr() as usize;
|
||||
debug_assert!(super::lesser_element::is_slice_of(
|
||||
self.source,
|
||||
first_child.get_source()
|
||||
));
|
||||
debug_assert!(super::lesser_element::is_slice_of(
|
||||
self.source,
|
||||
last_child.get_source()
|
||||
));
|
||||
Some(
|
||||
&self.source[(first_child_offset - source_offset)
|
||||
..(last_child_offset - first_child_offset)],
|
||||
)
|
||||
}
|
||||
}
|
||||
self.contents
|
||||
}
|
||||
|
||||
fn get_post_blank(&self) -> PostBlank {
|
||||
self.children
|
||||
.last()
|
||||
.map(|child| child.get_post_blank())
|
||||
self.post_blank
|
||||
.map(|text| text.lines().count())
|
||||
.unwrap_or(0)
|
||||
.try_into()
|
||||
.expect("Too much post-blank to fit into a PostBlank.")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -13,6 +13,8 @@ pub struct PlainList<'s> {
|
||||
pub affiliated_keywords: AffiliatedKeywords<'s>,
|
||||
pub list_type: PlainListType,
|
||||
pub children: Vec<PlainListItem<'s>>,
|
||||
pub contents: Option<&'s str>, // TODO: Can contents ever be None?
|
||||
pub post_blank: Option<&'s str>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
@@ -35,6 +37,8 @@ pub struct PlainListItem<'s> {
|
||||
pub tag: Vec<Object<'s>>,
|
||||
pub pre_blank: PlainListItemPreBlank,
|
||||
pub children: Vec<Element<'s>>,
|
||||
pub contents: Option<&'s str>,
|
||||
pub post_blank: Option<&'s str>,
|
||||
}
|
||||
|
||||
pub type PlainListItemCounter = u16;
|
||||
@@ -52,6 +56,8 @@ pub struct CenterBlock<'s> {
|
||||
pub source: &'s str,
|
||||
pub affiliated_keywords: AffiliatedKeywords<'s>,
|
||||
pub children: Vec<Element<'s>>,
|
||||
pub contents: Option<&'s str>,
|
||||
pub post_blank: Option<&'s str>,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
@@ -59,6 +65,8 @@ pub struct QuoteBlock<'s> {
|
||||
pub source: &'s str,
|
||||
pub affiliated_keywords: AffiliatedKeywords<'s>,
|
||||
pub children: Vec<Element<'s>>,
|
||||
pub contents: Option<&'s str>,
|
||||
pub post_blank: Option<&'s str>,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
@@ -68,6 +76,8 @@ pub struct SpecialBlock<'s> {
|
||||
pub block_type: &'s str,
|
||||
pub parameters: Option<&'s str>,
|
||||
pub children: Vec<Element<'s>>,
|
||||
pub contents: Option<&'s str>,
|
||||
pub post_blank: Option<&'s str>,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
@@ -77,6 +87,8 @@ pub struct DynamicBlock<'s> {
|
||||
pub block_name: &'s str,
|
||||
pub parameters: Option<&'s str>,
|
||||
pub children: Vec<Element<'s>>,
|
||||
pub contents: Option<&'s str>,
|
||||
pub post_blank: Option<&'s str>,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
@@ -103,6 +115,8 @@ pub struct Drawer<'s> {
|
||||
pub struct PropertyDrawer<'s> {
|
||||
pub source: &'s str,
|
||||
pub children: Vec<NodeProperty<'s>>,
|
||||
pub contents: Option<&'s str>,
|
||||
pub post_blank: Option<&'s str>,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
@@ -118,12 +132,15 @@ pub struct Table<'s> {
|
||||
pub affiliated_keywords: AffiliatedKeywords<'s>,
|
||||
pub formulas: Vec<Keyword<'s>>,
|
||||
pub children: Vec<TableRow<'s>>,
|
||||
pub contents: &'s str,
|
||||
pub post_blank: Option<&'s str>,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct TableRow<'s> {
|
||||
pub source: &'s str,
|
||||
pub children: Vec<TableCell<'s>>,
|
||||
pub contents: Option<&'s str>,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
@@ -138,11 +155,15 @@ impl<'s> StandardProperties<'s> for PlainList<'s> {
|
||||
}
|
||||
|
||||
fn get_contents<'b>(&'b self) -> Option<&'s str> {
|
||||
todo!()
|
||||
self.contents
|
||||
}
|
||||
|
||||
fn get_post_blank(&self) -> PostBlank {
|
||||
todo!()
|
||||
self.post_blank
|
||||
.map(|text| text.lines().count())
|
||||
.unwrap_or(0)
|
||||
.try_into()
|
||||
.expect("Too much post-blank to fit into a PostBlank.")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -152,11 +173,15 @@ impl<'s> StandardProperties<'s> for PlainListItem<'s> {
|
||||
}
|
||||
|
||||
fn get_contents<'b>(&'b self) -> Option<&'s str> {
|
||||
todo!()
|
||||
self.contents
|
||||
}
|
||||
|
||||
fn get_post_blank(&self) -> PostBlank {
|
||||
todo!()
|
||||
self.post_blank
|
||||
.map(|text| text.lines().count())
|
||||
.unwrap_or(0)
|
||||
.try_into()
|
||||
.expect("Too much post-blank to fit into a PostBlank.")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -166,11 +191,15 @@ impl<'s> StandardProperties<'s> for CenterBlock<'s> {
|
||||
}
|
||||
|
||||
fn get_contents<'b>(&'b self) -> Option<&'s str> {
|
||||
todo!()
|
||||
self.contents
|
||||
}
|
||||
|
||||
fn get_post_blank(&self) -> PostBlank {
|
||||
todo!()
|
||||
self.post_blank
|
||||
.map(|text| text.lines().count())
|
||||
.unwrap_or(0)
|
||||
.try_into()
|
||||
.expect("Too much post-blank to fit into a PostBlank.")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -180,11 +209,15 @@ impl<'s> StandardProperties<'s> for QuoteBlock<'s> {
|
||||
}
|
||||
|
||||
fn get_contents<'b>(&'b self) -> Option<&'s str> {
|
||||
todo!()
|
||||
self.contents
|
||||
}
|
||||
|
||||
fn get_post_blank(&self) -> PostBlank {
|
||||
todo!()
|
||||
self.post_blank
|
||||
.map(|text| text.lines().count())
|
||||
.unwrap_or(0)
|
||||
.try_into()
|
||||
.expect("Too much post-blank to fit into a PostBlank.")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -194,11 +227,15 @@ impl<'s> StandardProperties<'s> for SpecialBlock<'s> {
|
||||
}
|
||||
|
||||
fn get_contents<'b>(&'b self) -> Option<&'s str> {
|
||||
todo!()
|
||||
self.contents
|
||||
}
|
||||
|
||||
fn get_post_blank(&self) -> PostBlank {
|
||||
todo!()
|
||||
self.post_blank
|
||||
.map(|text| text.lines().count())
|
||||
.unwrap_or(0)
|
||||
.try_into()
|
||||
.expect("Too much post-blank to fit into a PostBlank.")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -208,11 +245,15 @@ impl<'s> StandardProperties<'s> for DynamicBlock<'s> {
|
||||
}
|
||||
|
||||
fn get_contents<'b>(&'b self) -> Option<&'s str> {
|
||||
todo!()
|
||||
self.contents
|
||||
}
|
||||
|
||||
fn get_post_blank(&self) -> PostBlank {
|
||||
todo!()
|
||||
self.post_blank
|
||||
.map(|text| text.lines().count())
|
||||
.unwrap_or(0)
|
||||
.try_into()
|
||||
.expect("Too much post-blank to fit into a PostBlank.")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -258,11 +299,15 @@ impl<'s> StandardProperties<'s> for PropertyDrawer<'s> {
|
||||
}
|
||||
|
||||
fn get_contents<'b>(&'b self) -> Option<&'s str> {
|
||||
todo!()
|
||||
self.contents
|
||||
}
|
||||
|
||||
fn get_post_blank(&self) -> PostBlank {
|
||||
todo!()
|
||||
self.post_blank
|
||||
.map(|text| text.lines().count())
|
||||
.unwrap_or(0)
|
||||
.try_into()
|
||||
.expect("Too much post-blank to fit into a PostBlank.")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -272,11 +317,11 @@ impl<'s> StandardProperties<'s> for NodeProperty<'s> {
|
||||
}
|
||||
|
||||
fn get_contents<'b>(&'b self) -> Option<&'s str> {
|
||||
todo!()
|
||||
None
|
||||
}
|
||||
|
||||
fn get_post_blank(&self) -> PostBlank {
|
||||
todo!()
|
||||
0
|
||||
}
|
||||
}
|
||||
|
||||
@@ -286,11 +331,15 @@ impl<'s> StandardProperties<'s> for Table<'s> {
|
||||
}
|
||||
|
||||
fn get_contents<'b>(&'b self) -> Option<&'s str> {
|
||||
todo!()
|
||||
Some(self.contents)
|
||||
}
|
||||
|
||||
fn get_post_blank(&self) -> PostBlank {
|
||||
todo!()
|
||||
self.post_blank
|
||||
.map(|text| text.lines().count())
|
||||
.unwrap_or(0)
|
||||
.try_into()
|
||||
.expect("Too much post-blank to fit into a PostBlank.")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -300,11 +349,11 @@ impl<'s> StandardProperties<'s> for TableRow<'s> {
|
||||
}
|
||||
|
||||
fn get_contents<'b>(&'b self) -> Option<&'s str> {
|
||||
todo!()
|
||||
self.contents
|
||||
}
|
||||
|
||||
fn get_post_blank(&self) -> PostBlank {
|
||||
todo!()
|
||||
0
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -42,6 +42,7 @@ pub struct Comment<'s> {
|
||||
pub struct TableCell<'s> {
|
||||
pub source: &'s str,
|
||||
pub children: Vec<Object<'s>>,
|
||||
pub contents: &'s str,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
@@ -132,6 +133,7 @@ pub struct DiarySexp<'s> {
|
||||
pub source: &'s str,
|
||||
pub affiliated_keywords: AffiliatedKeywords<'s>,
|
||||
pub value: &'s str,
|
||||
pub post_blank: Option<&'s str>,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
@@ -140,6 +142,7 @@ pub struct Planning<'s> {
|
||||
pub scheduled: Option<Timestamp<'s>>,
|
||||
pub deadline: Option<Timestamp<'s>>,
|
||||
pub closed: Option<Timestamp<'s>>,
|
||||
pub post_blank: Option<&'s str>,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
@@ -147,12 +150,14 @@ pub struct FixedWidthArea<'s> {
|
||||
pub source: &'s str,
|
||||
pub affiliated_keywords: AffiliatedKeywords<'s>,
|
||||
pub value: Vec<&'s str>,
|
||||
pub post_blank: Option<&'s str>,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct HorizontalRule<'s> {
|
||||
pub source: &'s str,
|
||||
pub affiliated_keywords: AffiliatedKeywords<'s>,
|
||||
pub post_blank: Option<&'s str>,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
@@ -199,11 +204,16 @@ impl<'s> Paragraph<'s> {
|
||||
/// Generate a paragraph of the passed in text with no additional properties.
|
||||
///
|
||||
/// This is used for elements that support an "empty" content like greater blocks.
|
||||
pub(crate) fn of_text(source: &'s str, body: &'s str) -> Self {
|
||||
pub(crate) fn of_text(
|
||||
source: &'s str,
|
||||
body: &'s str,
|
||||
contents: Option<&'s str>,
|
||||
post_blank: Option<&'s str>,
|
||||
) -> Self {
|
||||
Paragraph {
|
||||
source,
|
||||
contents: None, // TODO
|
||||
post_blank: None, // TODO
|
||||
contents,
|
||||
post_blank,
|
||||
affiliated_keywords: AffiliatedKeywords::default(),
|
||||
children: vec![Object::PlainText(PlainText { source: body })],
|
||||
}
|
||||
@@ -234,11 +244,11 @@ impl<'s> StandardProperties<'s> for TableCell<'s> {
|
||||
}
|
||||
|
||||
fn get_contents<'b>(&'b self) -> Option<&'s str> {
|
||||
todo!()
|
||||
Some(self.contents)
|
||||
}
|
||||
|
||||
fn get_post_blank(&self) -> PostBlank {
|
||||
todo!()
|
||||
0
|
||||
}
|
||||
}
|
||||
|
||||
@@ -370,11 +380,15 @@ impl<'s> StandardProperties<'s> for DiarySexp<'s> {
|
||||
}
|
||||
|
||||
fn get_contents<'b>(&'b self) -> Option<&'s str> {
|
||||
todo!()
|
||||
None
|
||||
}
|
||||
|
||||
fn get_post_blank(&self) -> PostBlank {
|
||||
todo!()
|
||||
self.post_blank
|
||||
.map(|text| text.lines().count())
|
||||
.unwrap_or(0)
|
||||
.try_into()
|
||||
.expect("Too much post-blank to fit into a PostBlank.")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -384,11 +398,15 @@ impl<'s> StandardProperties<'s> for Planning<'s> {
|
||||
}
|
||||
|
||||
fn get_contents<'b>(&'b self) -> Option<&'s str> {
|
||||
todo!()
|
||||
None
|
||||
}
|
||||
|
||||
fn get_post_blank(&self) -> PostBlank {
|
||||
todo!()
|
||||
self.post_blank
|
||||
.map(|text| text.lines().count())
|
||||
.unwrap_or(0)
|
||||
.try_into()
|
||||
.expect("Too much post-blank to fit into a PostBlank.")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -398,11 +416,15 @@ impl<'s> StandardProperties<'s> for FixedWidthArea<'s> {
|
||||
}
|
||||
|
||||
fn get_contents<'b>(&'b self) -> Option<&'s str> {
|
||||
todo!()
|
||||
None
|
||||
}
|
||||
|
||||
fn get_post_blank(&self) -> PostBlank {
|
||||
todo!()
|
||||
self.post_blank
|
||||
.map(|text| text.lines().count())
|
||||
.unwrap_or(0)
|
||||
.try_into()
|
||||
.expect("Too much post-blank to fit into a PostBlank.")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -412,11 +434,15 @@ impl<'s> StandardProperties<'s> for HorizontalRule<'s> {
|
||||
}
|
||||
|
||||
fn get_contents<'b>(&'b self) -> Option<&'s str> {
|
||||
todo!()
|
||||
None
|
||||
}
|
||||
|
||||
fn get_post_blank(&self) -> PostBlank {
|
||||
todo!()
|
||||
self.post_blank
|
||||
.map(|text| text.lines().count())
|
||||
.unwrap_or(0)
|
||||
.try_into()
|
||||
.expect("Too much post-blank to fit into a PostBlank.")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -488,13 +514,7 @@ impl<'s> Comment<'s> {
|
||||
|
||||
impl<'s> FixedWidthArea<'s> {
|
||||
pub fn get_value(&self) -> String {
|
||||
let final_size = self.value.iter().map(|line| line.len()).sum();
|
||||
let mut ret = String::with_capacity(final_size);
|
||||
for line in &self.value {
|
||||
ret.push_str(line);
|
||||
}
|
||||
|
||||
ret
|
||||
self.value.join("\n")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -266,6 +266,7 @@ pub struct LineBreak<'s> {
|
||||
pub struct Target<'s> {
|
||||
pub source: &'s str,
|
||||
pub value: &'s str,
|
||||
pub post_blank: Option<&'s str>,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
@@ -923,11 +924,15 @@ impl<'s> StandardProperties<'s> for Target<'s> {
|
||||
}
|
||||
|
||||
fn get_contents<'b>(&'b self) -> Option<&'s str> {
|
||||
todo!()
|
||||
None
|
||||
}
|
||||
|
||||
fn get_post_blank(&self) -> PostBlank {
|
||||
todo!()
|
||||
self.post_blank
|
||||
.map(|post_blank| post_blank.chars().count())
|
||||
.unwrap_or(0)
|
||||
.try_into()
|
||||
.expect("Too much post-blank to fit into a PostBlank.")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1009,11 +1014,13 @@ impl<'s> StandardProperties<'s> for PlainText<'s> {
|
||||
}
|
||||
|
||||
fn get_contents<'b>(&'b self) -> Option<&'s str> {
|
||||
todo!()
|
||||
// This field does not actually exist in emacs for plaintext
|
||||
Some(self.source)
|
||||
}
|
||||
|
||||
fn get_post_blank(&self) -> PostBlank {
|
||||
todo!()
|
||||
// This field does not actually exist in emacs for plaintext
|
||||
0
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user