Compare commits
37 Commits
47a440147f
...
360b2d963d
Author | SHA1 | Date | |
---|---|---|---|
![]() |
360b2d963d | ||
![]() |
534c5ded3c | ||
![]() |
bdaf90af03 | ||
![]() |
1a67aac502 | ||
![]() |
9f166278f4 | ||
![]() |
c2222c9102 | ||
![]() |
fc104680eb | ||
![]() |
e40e3ff553 | ||
![]() |
0b465fe290 | ||
![]() |
d5396e311b | ||
![]() |
384242af87 | ||
![]() |
ec755bae8b | ||
![]() |
0b1e06f0d5 | ||
![]() |
bdfa050ee3 | ||
![]() |
ec98e1c3c5 | ||
![]() |
0d0b1b2051 | ||
![]() |
2215c32e57 | ||
![]() |
cf257443b0 | ||
![]() |
62815621e4 | ||
![]() |
7af5359e00 | ||
![]() |
d1184fa1d0 | ||
![]() |
5b146d7c07 | ||
![]() |
926682d513 | ||
![]() |
4c89d6c813 | ||
![]() |
62926bb91d | ||
![]() |
9ab649ebd4 | ||
![]() |
ca1b633a9f | ||
![]() |
f543caee00 | ||
![]() |
409a92333e | ||
![]() |
7a38d1ead3 | ||
![]() |
33c53a14ab | ||
![]() |
65615c64d2 | ||
![]() |
166e59b922 | ||
![]() |
8e357ed3b6 | ||
![]() |
45074e3be3 | ||
![]() |
ee1d8ca321 | ||
![]() |
25531cc443 |
3
org_mode_samples/greater_element/plain_list/checkbox.org
Normal file
3
org_mode_samples/greater_element/plain_list/checkbox.org
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
- [ ] Foo
|
||||||
|
- [-] Bar
|
||||||
|
- [X] Baz
|
1
org_mode_samples/object/text_markup/italic_bold.org
Normal file
1
org_mode_samples/object/text_markup/italic_bold.org
Normal file
@ -0,0 +1 @@
|
|||||||
|
/*foo*/
|
@ -1,4 +1,6 @@
|
|||||||
|
use std::collections::BTreeSet;
|
||||||
use std::fmt::Debug;
|
use std::fmt::Debug;
|
||||||
|
use std::str::FromStr;
|
||||||
|
|
||||||
use super::diff::artificial_diff_scope;
|
use super::diff::artificial_diff_scope;
|
||||||
use super::diff::compare_ast_node;
|
use super::diff::compare_ast_node;
|
||||||
@ -7,9 +9,14 @@ use super::diff::DiffStatus;
|
|||||||
use super::sexp::unquote;
|
use super::sexp::unquote;
|
||||||
use super::sexp::Token;
|
use super::sexp::Token;
|
||||||
use super::util::get_property;
|
use super::util::get_property;
|
||||||
|
use super::util::get_property_numeric;
|
||||||
use super::util::get_property_quoted_string;
|
use super::util::get_property_quoted_string;
|
||||||
use super::util::get_property_unquoted_atom;
|
use super::util::get_property_unquoted_atom;
|
||||||
use crate::types::AstNode;
|
use crate::types::AstNode;
|
||||||
|
use crate::types::CharOffsetInLine;
|
||||||
|
use crate::types::LineNumber;
|
||||||
|
use crate::types::RetainLabels;
|
||||||
|
use crate::types::SwitchNumberLines;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub(crate) enum EmacsField<'s> {
|
pub(crate) enum EmacsField<'s> {
|
||||||
@ -117,6 +124,38 @@ pub(crate) fn compare_property_unquoted_atom<'b, 's, 'x, R, RG: Fn(R) -> Option<
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub(crate) fn compare_property_numeric<
|
||||||
|
'b,
|
||||||
|
's,
|
||||||
|
'x,
|
||||||
|
R,
|
||||||
|
RV: FromStr + PartialEq + Debug,
|
||||||
|
RG: Fn(R) -> Option<RV>,
|
||||||
|
>(
|
||||||
|
_source: &'s str,
|
||||||
|
emacs: &'b Token<'s>,
|
||||||
|
rust_node: R,
|
||||||
|
emacs_field: &'x str,
|
||||||
|
rust_value_getter: RG,
|
||||||
|
) -> Result<ComparePropertiesResult<'b, 's>, Box<dyn std::error::Error + 's>>
|
||||||
|
where
|
||||||
|
<RV as FromStr>::Err: std::error::Error,
|
||||||
|
<RV as FromStr>::Err: 's,
|
||||||
|
{
|
||||||
|
let value = get_property_numeric::<RV>(emacs, emacs_field)?;
|
||||||
|
let rust_value = rust_value_getter(rust_node);
|
||||||
|
if rust_value != value {
|
||||||
|
let this_status = DiffStatus::Bad;
|
||||||
|
let message = Some(format!(
|
||||||
|
"{} mismatch (emacs != rust) {:?} != {:?}",
|
||||||
|
emacs_field, value, rust_value
|
||||||
|
));
|
||||||
|
Ok(ComparePropertiesResult::SelfChange(this_status, message))
|
||||||
|
} else {
|
||||||
|
Ok(ComparePropertiesResult::NoChange)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub(crate) fn compare_property_list_of_quoted_string<
|
pub(crate) fn compare_property_list_of_quoted_string<
|
||||||
'b,
|
'b,
|
||||||
's,
|
's,
|
||||||
@ -174,6 +213,59 @@ pub(crate) fn compare_property_list_of_quoted_string<
|
|||||||
Ok(ComparePropertiesResult::NoChange)
|
Ok(ComparePropertiesResult::NoChange)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub(crate) fn compare_property_set_of_quoted_string<
|
||||||
|
'a,
|
||||||
|
'b,
|
||||||
|
's,
|
||||||
|
'x,
|
||||||
|
R,
|
||||||
|
RV: AsRef<str> + std::fmt::Debug + Ord + 'a + ?Sized,
|
||||||
|
RI: Iterator<Item = &'a RV>,
|
||||||
|
RG: Fn(R) -> Option<RI>,
|
||||||
|
>(
|
||||||
|
_source: &'s str,
|
||||||
|
emacs: &'b Token<'s>,
|
||||||
|
rust_node: R,
|
||||||
|
emacs_field: &'x str,
|
||||||
|
rust_value_getter: RG,
|
||||||
|
) -> Result<ComparePropertiesResult<'b, 's>, Box<dyn std::error::Error>> {
|
||||||
|
let value = get_property(emacs, emacs_field)?
|
||||||
|
.map(Token::as_list)
|
||||||
|
.map_or(Ok(None), |r| r.map(Some))?;
|
||||||
|
let empty = Vec::new();
|
||||||
|
let value = value.unwrap_or(&empty);
|
||||||
|
let rust_value = rust_value_getter(rust_node);
|
||||||
|
let rust_value = if let Some(rust_value) = rust_value {
|
||||||
|
let slices: BTreeSet<&str> = rust_value.map(|rv| rv.as_ref()).collect();
|
||||||
|
slices
|
||||||
|
} else {
|
||||||
|
BTreeSet::new()
|
||||||
|
};
|
||||||
|
let value: Vec<&str> = value
|
||||||
|
.iter()
|
||||||
|
.map(|e| e.as_atom())
|
||||||
|
.collect::<Result<Vec<_>, _>>()?;
|
||||||
|
let value: Vec<String> = value
|
||||||
|
.into_iter()
|
||||||
|
.map(unquote)
|
||||||
|
.collect::<Result<Vec<_>, _>>()?;
|
||||||
|
let value: BTreeSet<&str> = value.iter().map(|e| e.as_str()).collect();
|
||||||
|
let mismatched: Vec<_> = value
|
||||||
|
.symmetric_difference(&rust_value)
|
||||||
|
.map(|val| *val)
|
||||||
|
.collect();
|
||||||
|
if !mismatched.is_empty() {
|
||||||
|
let this_status = DiffStatus::Bad;
|
||||||
|
let message = Some(format!(
|
||||||
|
"{} mismatch. Mismatched values: {}",
|
||||||
|
emacs_field,
|
||||||
|
mismatched.join(", ")
|
||||||
|
));
|
||||||
|
return Ok(ComparePropertiesResult::SelfChange(this_status, message));
|
||||||
|
}
|
||||||
|
Ok(ComparePropertiesResult::NoChange)
|
||||||
|
}
|
||||||
|
|
||||||
pub(crate) fn compare_property_boolean<'b, 's, 'x, R, RG: Fn(R) -> bool>(
|
pub(crate) fn compare_property_boolean<'b, 's, 'x, R, RG: Fn(R) -> bool>(
|
||||||
_source: &'s str,
|
_source: &'s str,
|
||||||
emacs: &'b Token<'s>,
|
emacs: &'b Token<'s>,
|
||||||
@ -196,6 +288,45 @@ pub(crate) fn compare_property_boolean<'b, 's, 'x, R, RG: Fn(R) -> bool>(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub(crate) fn compare_property_single_ast_node<
|
||||||
|
'b,
|
||||||
|
's,
|
||||||
|
'x: 'b + 's,
|
||||||
|
R,
|
||||||
|
RV: std::fmt::Debug,
|
||||||
|
RG: Fn(R) -> Option<RV>,
|
||||||
|
>(
|
||||||
|
source: &'s str,
|
||||||
|
emacs: &'b Token<'s>,
|
||||||
|
rust_node: R,
|
||||||
|
emacs_field: &'x str,
|
||||||
|
rust_value_getter: RG,
|
||||||
|
) -> Result<ComparePropertiesResult<'b, 's>, Box<dyn std::error::Error>>
|
||||||
|
where
|
||||||
|
AstNode<'b, 's>: From<RV>,
|
||||||
|
{
|
||||||
|
let value = get_property(emacs, emacs_field)?;
|
||||||
|
let rust_value = rust_value_getter(rust_node);
|
||||||
|
match (value, rust_value) {
|
||||||
|
(None, None) => {}
|
||||||
|
(None, rv @ Some(_)) | (Some(_), rv @ None) => {
|
||||||
|
let this_status = DiffStatus::Bad;
|
||||||
|
let message = Some(format!(
|
||||||
|
"{} mismatch (emacs != rust) {:?} != {:?}",
|
||||||
|
emacs_field, value, rv
|
||||||
|
));
|
||||||
|
return Ok(ComparePropertiesResult::SelfChange(this_status, message));
|
||||||
|
}
|
||||||
|
(Some(ev), Some(rv)) => {
|
||||||
|
let child_status: Vec<DiffEntry<'b, 's>> =
|
||||||
|
vec![compare_ast_node(source, ev, rv.into())?];
|
||||||
|
let diff_scope = artificial_diff_scope(emacs_field, child_status)?;
|
||||||
|
return Ok(ComparePropertiesResult::DiffEntry(diff_scope));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Ok(ComparePropertiesResult::NoChange)
|
||||||
|
}
|
||||||
|
|
||||||
pub(crate) fn compare_property_list_of_ast_nodes<
|
pub(crate) fn compare_property_list_of_ast_nodes<
|
||||||
'b,
|
'b,
|
||||||
's,
|
's,
|
||||||
@ -249,3 +380,115 @@ where
|
|||||||
}
|
}
|
||||||
Ok(ComparePropertiesResult::NoChange)
|
Ok(ComparePropertiesResult::NoChange)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub(crate) fn compare_property_number_lines<
|
||||||
|
'b,
|
||||||
|
's,
|
||||||
|
'x,
|
||||||
|
'y,
|
||||||
|
R,
|
||||||
|
RG: Fn(R) -> Option<&'y SwitchNumberLines>,
|
||||||
|
>(
|
||||||
|
_source: &'s str,
|
||||||
|
emacs: &'b Token<'s>,
|
||||||
|
rust_node: R,
|
||||||
|
emacs_field: &'x str,
|
||||||
|
rust_value_getter: RG,
|
||||||
|
) -> Result<ComparePropertiesResult<'b, 's>, Box<dyn std::error::Error>> {
|
||||||
|
let number_lines = get_property(emacs, emacs_field)?;
|
||||||
|
let rust_value = rust_value_getter(rust_node);
|
||||||
|
match (number_lines, &rust_value) {
|
||||||
|
(None, None) => {}
|
||||||
|
(Some(number_lines), Some(rust_number_lines)) => {
|
||||||
|
let token_list = number_lines.as_list()?;
|
||||||
|
let number_type = token_list
|
||||||
|
.get(0)
|
||||||
|
.map(Token::as_atom)
|
||||||
|
.map_or(Ok(None), |r| r.map(Some))?
|
||||||
|
.ok_or(":number-lines should have a type.")?;
|
||||||
|
let number_value = token_list
|
||||||
|
.get(2)
|
||||||
|
.map(Token::as_atom)
|
||||||
|
.map_or(Ok(None), |r| r.map(Some))?
|
||||||
|
.map(|val| val.parse::<LineNumber>())
|
||||||
|
.map_or(Ok(None), |r| r.map(Some))?
|
||||||
|
.ok_or(":number-lines should have a value.")?;
|
||||||
|
match (number_type, number_value, rust_number_lines) {
|
||||||
|
("new", emacs_val, SwitchNumberLines::New(rust_val)) if emacs_val == *rust_val => {}
|
||||||
|
("continued", emacs_val, SwitchNumberLines::Continued(rust_val))
|
||||||
|
if emacs_val == *rust_val => {}
|
||||||
|
_ => {
|
||||||
|
let this_status = DiffStatus::Bad;
|
||||||
|
let message = Some(format!(
|
||||||
|
"{} mismatch (emacs != rust) {:?} != {:?}",
|
||||||
|
emacs_field, number_lines, rust_value
|
||||||
|
));
|
||||||
|
return Ok(ComparePropertiesResult::SelfChange(this_status, message));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_ => {
|
||||||
|
let this_status = DiffStatus::Bad;
|
||||||
|
let message = Some(format!(
|
||||||
|
"{} mismatch (emacs != rust) {:?} != {:?}",
|
||||||
|
emacs_field, number_lines, rust_value
|
||||||
|
));
|
||||||
|
return Ok(ComparePropertiesResult::SelfChange(this_status, message));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
Ok(ComparePropertiesResult::NoChange)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) fn compare_property_retain_labels<'b, 's, 'x, 'y, R, RG: Fn(R) -> &'y RetainLabels>(
|
||||||
|
_source: &'s str,
|
||||||
|
emacs: &'b Token<'s>,
|
||||||
|
rust_node: R,
|
||||||
|
emacs_field: &'x str,
|
||||||
|
rust_value_getter: RG,
|
||||||
|
) -> Result<ComparePropertiesResult<'b, 's>, Box<dyn std::error::Error + 's>> {
|
||||||
|
let rust_value = rust_value_getter(rust_node);
|
||||||
|
let retain_labels = get_property_unquoted_atom(emacs, ":retain-labels")?;
|
||||||
|
if let Some(retain_labels) = retain_labels {
|
||||||
|
if retain_labels == "t" {
|
||||||
|
match rust_value {
|
||||||
|
RetainLabels::Yes => {}
|
||||||
|
_ => {
|
||||||
|
let this_status = DiffStatus::Bad;
|
||||||
|
let message = Some(format!(
|
||||||
|
"{} mismatch (emacs != rust) {:?} != {:?}",
|
||||||
|
emacs_field, retain_labels, rust_value
|
||||||
|
));
|
||||||
|
return Ok(ComparePropertiesResult::SelfChange(this_status, message));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
let retain_labels: CharOffsetInLine = get_property_numeric(emacs, ":retain-labels")?.expect("Cannot be None or else the earlier get_property_unquoted_atom would have been None.");
|
||||||
|
match (retain_labels, rust_value) {
|
||||||
|
(e, RetainLabels::Keep(r)) if e == *r => {}
|
||||||
|
_ => {
|
||||||
|
let this_status = DiffStatus::Bad;
|
||||||
|
let message = Some(format!(
|
||||||
|
"{} mismatch (emacs != rust) {:?} != {:?}",
|
||||||
|
emacs_field, retain_labels, rust_value
|
||||||
|
));
|
||||||
|
return Ok(ComparePropertiesResult::SelfChange(this_status, message));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
match rust_value {
|
||||||
|
RetainLabels::No => {}
|
||||||
|
_ => {
|
||||||
|
let this_status = DiffStatus::Bad;
|
||||||
|
let message = Some(format!(
|
||||||
|
"{} mismatch (emacs != rust) {:?} != {:?}",
|
||||||
|
emacs_field, retain_labels, rust_value
|
||||||
|
));
|
||||||
|
return Ok(ComparePropertiesResult::SelfChange(this_status, message));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(ComparePropertiesResult::NoChange)
|
||||||
|
}
|
||||||
|
2680
src/compare/diff.rs
2680
src/compare/diff.rs
File diff suppressed because it is too large
Load Diff
@ -22,9 +22,6 @@ pub(crate) enum ContextElement<'r, 's> {
|
|||||||
/// Stores the name of the current element to prevent directly nesting elements of the same type.
|
/// Stores the name of the current element to prevent directly nesting elements of the same type.
|
||||||
Context(&'r str),
|
Context(&'r str),
|
||||||
|
|
||||||
/// Stores the name of the current object to prevent directly nesting elements of the same type.
|
|
||||||
ContextObject(&'r str),
|
|
||||||
|
|
||||||
/// Indicates if elements should consume the whitespace after them.
|
/// Indicates if elements should consume the whitespace after them.
|
||||||
ConsumeTrailingWhitespace(bool),
|
ConsumeTrailingWhitespace(bool),
|
||||||
|
|
||||||
|
@ -16,6 +16,7 @@ use nom::combinator::verify;
|
|||||||
use nom::multi::many0;
|
use nom::multi::many0;
|
||||||
use nom::multi::many_till;
|
use nom::multi::many_till;
|
||||||
use nom::sequence::tuple;
|
use nom::sequence::tuple;
|
||||||
|
use nom::InputTake;
|
||||||
|
|
||||||
use super::keyword::affiliated_keyword;
|
use super::keyword::affiliated_keyword;
|
||||||
use super::org_source::OrgSource;
|
use super::org_source::OrgSource;
|
||||||
@ -160,7 +161,20 @@ pub(crate) fn example_block<'b, 'g, 'r, 's>(
|
|||||||
) -> Res<OrgSource<'s>, ExampleBlock<'s>> {
|
) -> Res<OrgSource<'s>, ExampleBlock<'s>> {
|
||||||
let (remaining, affiliated_keywords) = many0(affiliated_keyword)(input)?;
|
let (remaining, affiliated_keywords) = many0(affiliated_keyword)(input)?;
|
||||||
let (remaining, _) = lesser_block_begin("example")(context, remaining)?;
|
let (remaining, _) = lesser_block_begin("example")(context, remaining)?;
|
||||||
let (remaining, parameters) = opt(tuple((space1, example_switches)))(remaining)?;
|
let (remaining, parameters) = opt(alt((
|
||||||
|
map(tuple((space1, example_switches)), |(_, switches)| switches),
|
||||||
|
map(space1, |ws: OrgSource<'_>| {
|
||||||
|
let source = ws.take(0);
|
||||||
|
ExampleSrcSwitches {
|
||||||
|
source: source.into(),
|
||||||
|
number_lines: None,
|
||||||
|
retain_labels: RetainLabels::Yes,
|
||||||
|
preserve_indent: None,
|
||||||
|
use_labels: true,
|
||||||
|
label_format: None,
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
)))(remaining)?;
|
||||||
let (remaining, _nl) = recognize(tuple((space0, line_ending)))(remaining)?;
|
let (remaining, _nl) = recognize(tuple((space0, line_ending)))(remaining)?;
|
||||||
let lesser_block_end_specialized = lesser_block_end("example");
|
let lesser_block_end_specialized = lesser_block_end("example");
|
||||||
let contexts = [
|
let contexts = [
|
||||||
@ -174,7 +188,6 @@ pub(crate) fn example_block<'b, 'g, 'r, 's>(
|
|||||||
let parser_context = context.with_additional_node(&contexts[0]);
|
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[1]);
|
||||||
let parser_context = parser_context.with_additional_node(&contexts[2]);
|
let parser_context = parser_context.with_additional_node(&contexts[2]);
|
||||||
let parameters = parameters.map(|(_, parameters)| parameters);
|
|
||||||
|
|
||||||
let (remaining, contents) = content(&parser_context, remaining)?;
|
let (remaining, contents) = content(&parser_context, remaining)?;
|
||||||
let (remaining, _end) = lesser_block_end_specialized(&parser_context, remaining)?;
|
let (remaining, _end) = lesser_block_end_specialized(&parser_context, remaining)?;
|
||||||
@ -185,11 +198,7 @@ pub(crate) fn example_block<'b, 'g, 'r, 's>(
|
|||||||
let (switches, number_lines, preserve_indent, retain_labels, use_labels, label_format) = {
|
let (switches, number_lines, preserve_indent, retain_labels, use_labels, label_format) = {
|
||||||
if let Some(parameters) = parameters {
|
if let Some(parameters) = parameters {
|
||||||
(
|
(
|
||||||
if parameters.source.len() == 0 {
|
Some(parameters.source),
|
||||||
None
|
|
||||||
} else {
|
|
||||||
Some(parameters.source)
|
|
||||||
},
|
|
||||||
parameters.number_lines,
|
parameters.number_lines,
|
||||||
parameters.preserve_indent,
|
parameters.preserve_indent,
|
||||||
parameters.retain_labels,
|
parameters.retain_labels,
|
||||||
|
@ -324,7 +324,7 @@ fn impl_path_plain_end<'b, 'g, 'r, 's>(
|
|||||||
!" \t\r\n[]<>()/".contains(*c) && c.is_ascii_punctuation()
|
!" \t\r\n[]<>()/".contains(*c) && c.is_ascii_punctuation()
|
||||||
}))(input)?;
|
}))(input)?;
|
||||||
|
|
||||||
let disallowed_character = recognize(one_of(" \t\r\n[]<>"))(remaining);
|
let disallowed_character = alt((recognize(one_of(" \t\r\n[]<>")), eof))(remaining);
|
||||||
if disallowed_character.is_ok() {
|
if disallowed_character.is_ok() {
|
||||||
return disallowed_character;
|
return disallowed_character;
|
||||||
}
|
}
|
||||||
|
@ -176,12 +176,13 @@ fn org_mode_table_cell<'b, 'g, 'r, 's>(
|
|||||||
let table_cell_set_object_matcher =
|
let table_cell_set_object_matcher =
|
||||||
parser_with_context!(table_cell_set_object)(&parser_context);
|
parser_with_context!(table_cell_set_object)(&parser_context);
|
||||||
let exit_matcher = parser_with_context!(exit_matcher_parser)(&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, (children, _exit_contents)) = verify(
|
||||||
many_till(table_cell_set_object_matcher, exit_matcher),
|
many_till(table_cell_set_object_matcher, exit_matcher),
|
||||||
|(children, exit_contents)| {
|
|(children, exit_contents)| {
|
||||||
!children.is_empty() || Into::<&str>::into(exit_contents).ends_with("|")
|
!children.is_empty() || Into::<&str>::into(exit_contents).ends_with("|")
|
||||||
},
|
},
|
||||||
)(input)?;
|
)(remaining)?;
|
||||||
|
|
||||||
let (remaining, _tail) = org_mode_table_cell_end(&parser_context, remaining)?;
|
let (remaining, _tail) = org_mode_table_cell_end(&parser_context, remaining)?;
|
||||||
|
|
||||||
|
@ -4,11 +4,14 @@ use nom::character::complete::anychar;
|
|||||||
use nom::character::complete::multispace1;
|
use nom::character::complete::multispace1;
|
||||||
use nom::character::complete::one_of;
|
use nom::character::complete::one_of;
|
||||||
use nom::character::complete::space0;
|
use nom::character::complete::space0;
|
||||||
|
use nom::combinator::all_consuming;
|
||||||
use nom::combinator::map;
|
use nom::combinator::map;
|
||||||
|
use nom::combinator::map_parser;
|
||||||
use nom::combinator::not;
|
use nom::combinator::not;
|
||||||
use nom::combinator::peek;
|
use nom::combinator::peek;
|
||||||
use nom::combinator::recognize;
|
use nom::combinator::recognize;
|
||||||
use nom::combinator::verify;
|
use nom::combinator::verify;
|
||||||
|
use nom::multi::many1;
|
||||||
use nom::multi::many_till;
|
use nom::multi::many_till;
|
||||||
use nom::sequence::terminated;
|
use nom::sequence::terminated;
|
||||||
#[cfg(feature = "tracing")]
|
#[cfg(feature = "tracing")]
|
||||||
@ -17,15 +20,18 @@ use tracing::span;
|
|||||||
use super::object_parser::standard_set_object;
|
use super::object_parser::standard_set_object;
|
||||||
use super::org_source::OrgSource;
|
use super::org_source::OrgSource;
|
||||||
use super::radio_link::RematchObject;
|
use super::radio_link::RematchObject;
|
||||||
use super::util::in_object_section;
|
use super::util::confine_context;
|
||||||
use super::util::maybe_consume_object_trailing_whitespace_if_not_exiting;
|
use super::util::maybe_consume_object_trailing_whitespace_if_not_exiting;
|
||||||
use super::util::org_line_ending;
|
use super::util::org_line_ending;
|
||||||
use super::util::start_of_line;
|
use super::util::start_of_line;
|
||||||
|
use super::util::text_until_exit;
|
||||||
use crate::context::parser_with_context;
|
use crate::context::parser_with_context;
|
||||||
|
use crate::context::Context;
|
||||||
use crate::context::ContextElement;
|
use crate::context::ContextElement;
|
||||||
use crate::context::ContextMatcher;
|
use crate::context::ContextMatcher;
|
||||||
use crate::context::ExitClass;
|
use crate::context::ExitClass;
|
||||||
use crate::context::ExitMatcherNode;
|
use crate::context::ExitMatcherNode;
|
||||||
|
use crate::context::List;
|
||||||
use crate::context::RefContext;
|
use crate::context::RefContext;
|
||||||
use crate::error::CustomError;
|
use crate::error::CustomError;
|
||||||
use crate::error::MyError;
|
use crate::error::MyError;
|
||||||
@ -196,33 +202,30 @@ fn _text_markup_object<'b, 'g, 'r, 's, 'c>(
|
|||||||
input: OrgSource<'s>,
|
input: OrgSource<'s>,
|
||||||
marker_symbol: &'c str,
|
marker_symbol: &'c str,
|
||||||
) -> Res<OrgSource<'s>, Vec<Object<'s>>> {
|
) -> Res<OrgSource<'s>, Vec<Object<'s>>> {
|
||||||
if in_object_section(context, marker_symbol) {
|
|
||||||
return Err(nom::Err::Error(CustomError::MyError(MyError(
|
|
||||||
"Cannot nest objects of the same type".into(),
|
|
||||||
))));
|
|
||||||
}
|
|
||||||
|
|
||||||
let (remaining, _) = pre(context, input)?;
|
let (remaining, _) = pre(context, input)?;
|
||||||
let (remaining, open) = tag(marker_symbol)(remaining)?;
|
let (remaining, open) = tag(marker_symbol)(remaining)?;
|
||||||
let (remaining, _peek_not_whitespace) =
|
let (remaining, _peek_not_whitespace) =
|
||||||
peek(verify(anychar, |c| !c.is_whitespace() && *c != '\u{200B}'))(remaining)?;
|
peek(verify(anychar, |c| !c.is_whitespace() && *c != '\u{200B}'))(remaining)?;
|
||||||
let text_markup_end_specialized = text_markup_end(open.into(), remaining.get_byte_offset());
|
let text_markup_end_specialized = text_markup_end(open.into(), remaining.get_byte_offset());
|
||||||
let contexts = [
|
let contexts = [ContextElement::ExitMatcherNode(ExitMatcherNode {
|
||||||
ContextElement::ContextObject(marker_symbol),
|
class: ExitClass::Gamma,
|
||||||
ContextElement::ExitMatcherNode(ExitMatcherNode {
|
exit_matcher: &text_markup_end_specialized,
|
||||||
class: ExitClass::Gamma,
|
})];
|
||||||
exit_matcher: &text_markup_end_specialized,
|
|
||||||
}),
|
|
||||||
];
|
|
||||||
let parser_context = context.with_additional_node(&contexts[0]);
|
let parser_context = context.with_additional_node(&contexts[0]);
|
||||||
let parser_context = parser_context.with_additional_node(&contexts[1]);
|
|
||||||
|
|
||||||
let (remaining, (children, _exit_contents)) = verify(
|
let initial_context = ContextElement::document_context();
|
||||||
many_till(
|
let initial_context = Context::new(context.get_global_settings(), List::new(&initial_context));
|
||||||
parser_with_context!(standard_set_object)(&parser_context),
|
|
||||||
parser_with_context!(exit_matcher_parser)(&parser_context),
|
let (remaining, children) = map_parser(
|
||||||
|
verify(
|
||||||
|
parser_with_context!(text_until_exit)(&parser_context),
|
||||||
|
|text| text.len() > 0,
|
||||||
),
|
),
|
||||||
|(children, _exit_contents)| !children.is_empty(),
|
confine_context(|i| {
|
||||||
|
all_consuming(many1(parser_with_context!(standard_set_object)(
|
||||||
|
&initial_context,
|
||||||
|
)))(i)
|
||||||
|
}),
|
||||||
)(remaining)?;
|
)(remaining)?;
|
||||||
|
|
||||||
{
|
{
|
||||||
@ -262,25 +265,16 @@ fn _text_markup_string<'b, 'g, 'r, 's, 'c>(
|
|||||||
input: OrgSource<'s>,
|
input: OrgSource<'s>,
|
||||||
marker_symbol: &'c str,
|
marker_symbol: &'c str,
|
||||||
) -> Res<OrgSource<'s>, OrgSource<'s>> {
|
) -> Res<OrgSource<'s>, OrgSource<'s>> {
|
||||||
if in_object_section(context, marker_symbol) {
|
|
||||||
return Err(nom::Err::Error(CustomError::MyError(MyError(
|
|
||||||
"Cannot nest objects of the same type".into(),
|
|
||||||
))));
|
|
||||||
}
|
|
||||||
let (remaining, _) = pre(context, input)?;
|
let (remaining, _) = pre(context, input)?;
|
||||||
let (remaining, open) = tag(marker_symbol)(remaining)?;
|
let (remaining, open) = tag(marker_symbol)(remaining)?;
|
||||||
let (remaining, _peek_not_whitespace) =
|
let (remaining, _peek_not_whitespace) =
|
||||||
peek(verify(anychar, |c| !c.is_whitespace() && *c != '\u{200B}'))(remaining)?;
|
peek(verify(anychar, |c| !c.is_whitespace() && *c != '\u{200B}'))(remaining)?;
|
||||||
let text_markup_end_specialized = text_markup_end(open.into(), remaining.get_byte_offset());
|
let text_markup_end_specialized = text_markup_end(open.into(), remaining.get_byte_offset());
|
||||||
let contexts = [
|
let contexts = [ContextElement::ExitMatcherNode(ExitMatcherNode {
|
||||||
ContextElement::ContextObject(marker_symbol),
|
class: ExitClass::Gamma,
|
||||||
ContextElement::ExitMatcherNode(ExitMatcherNode {
|
exit_matcher: &text_markup_end_specialized,
|
||||||
class: ExitClass::Gamma,
|
})];
|
||||||
exit_matcher: &text_markup_end_specialized,
|
|
||||||
}),
|
|
||||||
];
|
|
||||||
let parser_context = context.with_additional_node(&contexts[0]);
|
let parser_context = context.with_additional_node(&contexts[0]);
|
||||||
let parser_context = parser_context.with_additional_node(&contexts[1]);
|
|
||||||
|
|
||||||
let (remaining, contents) = recognize(verify(
|
let (remaining, contents) = recognize(verify(
|
||||||
many_till(
|
many_till(
|
||||||
|
@ -57,20 +57,6 @@ pub(crate) fn immediate_in_section<'b, 'g, 'r, 's, 'x>(
|
|||||||
false
|
false
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Check if we are below a section of the given section type regardless of depth
|
|
||||||
pub(crate) fn in_object_section<'b, 'g, 'r, 's, 'x>(
|
|
||||||
context: RefContext<'b, 'g, 'r, 's>,
|
|
||||||
section_name: &'x str,
|
|
||||||
) -> bool {
|
|
||||||
for thing in context.iter() {
|
|
||||||
match thing {
|
|
||||||
ContextElement::ContextObject(name) if *name == section_name => return true,
|
|
||||||
_ => {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
false
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Get a slice of the string that was consumed in a parser using the original input to the parser and the remaining input after the parser.
|
/// Get a slice of the string that was consumed in a parser using the original input to the parser and the remaining input after the parser.
|
||||||
pub(crate) fn get_consumed<'s>(input: OrgSource<'s>, remaining: OrgSource<'s>) -> OrgSource<'s> {
|
pub(crate) fn get_consumed<'s>(input: OrgSource<'s>, remaining: OrgSource<'s>) -> OrgSource<'s> {
|
||||||
input.get_until(remaining)
|
input.get_until(remaining)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user