Compare commits
No commits in common. "360b2d963d448eb738b7d6e2ac9a09efd041ccf3" and "47a440147fedba039b1d545675a0055b25730469" have entirely different histories.
360b2d963d
...
47a440147f
@ -1,3 +0,0 @@
|
|||||||
- [ ] Foo
|
|
||||||
- [-] Bar
|
|
||||||
- [X] Baz
|
|
@ -1 +0,0 @@
|
|||||||
/*foo*/
|
|
@ -1,6 +1,4 @@
|
|||||||
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;
|
||||||
@ -9,14 +7,9 @@ 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> {
|
||||||
@ -124,38 +117,6 @@ 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,
|
||||||
@ -213,59 +174,6 @@ 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>,
|
||||||
@ -288,45 +196,6 @@ 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,
|
||||||
@ -380,115 +249,3 @@ 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)
|
|
||||||
}
|
|
||||||
|
2682
src/compare/diff.rs
2682
src/compare/diff.rs
File diff suppressed because it is too large
Load Diff
@ -22,6 +22,9 @@ 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,7 +16,6 @@ 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;
|
||||||
@ -161,20 +160,7 @@ 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(alt((
|
let (remaining, parameters) = opt(tuple((space1, example_switches)))(remaining)?;
|
||||||
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 = [
|
||||||
@ -188,6 +174,7 @@ 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)?;
|
||||||
@ -198,7 +185,11 @@ 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 {
|
||||||
(
|
(
|
||||||
Some(parameters.source),
|
if parameters.source.len() == 0 {
|
||||||
|
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 = alt((recognize(one_of(" \t\r\n[]<>")), eof))(remaining);
|
let disallowed_character = recognize(one_of(" \t\r\n[]<>"))(remaining);
|
||||||
if disallowed_character.is_ok() {
|
if disallowed_character.is_ok() {
|
||||||
return disallowed_character;
|
return disallowed_character;
|
||||||
}
|
}
|
||||||
|
@ -176,13 +176,12 @@ 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("|")
|
||||||
},
|
},
|
||||||
)(remaining)?;
|
)(input)?;
|
||||||
|
|
||||||
let (remaining, _tail) = org_mode_table_cell_end(&parser_context, remaining)?;
|
let (remaining, _tail) = org_mode_table_cell_end(&parser_context, remaining)?;
|
||||||
|
|
||||||
|
@ -4,14 +4,11 @@ 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")]
|
||||||
@ -20,18 +17,15 @@ 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::confine_context;
|
use super::util::in_object_section;
|
||||||
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;
|
||||||
@ -202,30 +196,33 @@ 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 = [ContextElement::ExitMatcherNode(ExitMatcherNode {
|
let contexts = [
|
||||||
class: ExitClass::Gamma,
|
ContextElement::ContextObject(marker_symbol),
|
||||||
exit_matcher: &text_markup_end_specialized,
|
ContextElement::ExitMatcherNode(ExitMatcherNode {
|
||||||
})];
|
class: ExitClass::Gamma,
|
||||||
let parser_context = context.with_additional_node(&contexts[0]);
|
exit_matcher: &text_markup_end_specialized,
|
||||||
|
|
||||||
let initial_context = ContextElement::document_context();
|
|
||||||
let initial_context = Context::new(context.get_global_settings(), List::new(&initial_context));
|
|
||||||
|
|
||||||
let (remaining, children) = map_parser(
|
|
||||||
verify(
|
|
||||||
parser_with_context!(text_until_exit)(&parser_context),
|
|
||||||
|text| text.len() > 0,
|
|
||||||
),
|
|
||||||
confine_context(|i| {
|
|
||||||
all_consuming(many1(parser_with_context!(standard_set_object)(
|
|
||||||
&initial_context,
|
|
||||||
)))(i)
|
|
||||||
}),
|
}),
|
||||||
|
];
|
||||||
|
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(
|
||||||
|
many_till(
|
||||||
|
parser_with_context!(standard_set_object)(&parser_context),
|
||||||
|
parser_with_context!(exit_matcher_parser)(&parser_context),
|
||||||
|
),
|
||||||
|
|(children, _exit_contents)| !children.is_empty(),
|
||||||
)(remaining)?;
|
)(remaining)?;
|
||||||
|
|
||||||
{
|
{
|
||||||
@ -265,16 +262,25 @@ 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 = [ContextElement::ExitMatcherNode(ExitMatcherNode {
|
let contexts = [
|
||||||
class: ExitClass::Gamma,
|
ContextElement::ContextObject(marker_symbol),
|
||||||
exit_matcher: &text_markup_end_specialized,
|
ContextElement::ExitMatcherNode(ExitMatcherNode {
|
||||||
})];
|
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,6 +57,20 @@ 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