Continue removing MyError.
This commit is contained in:
parent
e776a051ad
commit
20c4a0f8f7
@ -10,11 +10,12 @@ pub enum CustomError {
|
|||||||
Static(&'static str),
|
Static(&'static str),
|
||||||
IO(std::io::Error),
|
IO(std::io::Error),
|
||||||
BoxedError(Box<dyn std::error::Error>),
|
BoxedError(Box<dyn std::error::Error>),
|
||||||
|
Parser(ErrorKind),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<I: std::fmt::Debug> ParseError<I> for CustomError {
|
impl<I: std::fmt::Debug> ParseError<I> for CustomError {
|
||||||
fn from_error_kind(input: I, kind: ErrorKind) -> Self {
|
fn from_error_kind(input: I, kind: ErrorKind) -> Self {
|
||||||
CustomError::Text(format!("{:?} {:?}", kind, input))
|
CustomError::Parser(kind)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn append(_input: I, _kind: ErrorKind, /*mut*/ other: Self) -> Self {
|
fn append(_input: I, _kind: ErrorKind, /*mut*/ other: Self) -> Self {
|
||||||
|
@ -137,7 +137,7 @@ fn _global_prefix_end<'b, 'g, 'r, 's>(
|
|||||||
unreachable!("Exceeded citation global prefix bracket depth.")
|
unreachable!("Exceeded citation global prefix bracket depth.")
|
||||||
}
|
}
|
||||||
if current_depth == 0 {
|
if current_depth == 0 {
|
||||||
let close_bracket = tag::<&str, OrgSource<'_>, CustomError<OrgSource<'_>>>("]")(input);
|
let close_bracket = tag::<_, _, CustomError>("]")(input);
|
||||||
if close_bracket.is_ok() {
|
if close_bracket.is_ok() {
|
||||||
return close_bracket;
|
return close_bracket;
|
||||||
}
|
}
|
||||||
@ -191,7 +191,7 @@ fn _global_suffix_end<'b, 'g, 'r, 's>(
|
|||||||
unreachable!("Exceeded citation global suffix bracket depth.")
|
unreachable!("Exceeded citation global suffix bracket depth.")
|
||||||
}
|
}
|
||||||
if current_depth == 0 {
|
if current_depth == 0 {
|
||||||
let close_bracket = tag::<&str, OrgSource<'_>, CustomError<OrgSource<'_>>>("]")(input);
|
let close_bracket = tag::<_, _, CustomError>("]")(input);
|
||||||
if close_bracket.is_ok() {
|
if close_bracket.is_ok() {
|
||||||
return close_bracket;
|
return close_bracket;
|
||||||
}
|
}
|
||||||
|
@ -150,7 +150,7 @@ fn _key_prefix_end<'b, 'g, 'r, 's>(
|
|||||||
unreachable!("Exceeded citation key prefix bracket depth.")
|
unreachable!("Exceeded citation key prefix bracket depth.")
|
||||||
}
|
}
|
||||||
if current_depth == 0 {
|
if current_depth == 0 {
|
||||||
let close_bracket = tag::<&str, OrgSource<'_>, CustomError<OrgSource<'_>>>("]")(input);
|
let close_bracket = tag::<_, _, CustomError>("]")(input);
|
||||||
if close_bracket.is_ok() {
|
if close_bracket.is_ok() {
|
||||||
return close_bracket;
|
return close_bracket;
|
||||||
}
|
}
|
||||||
@ -180,7 +180,7 @@ fn _key_suffix_end<'b, 'g, 'r, 's>(
|
|||||||
unreachable!("Exceeded citation key suffix bracket depth.")
|
unreachable!("Exceeded citation key suffix bracket depth.")
|
||||||
}
|
}
|
||||||
if current_depth == 0 {
|
if current_depth == 0 {
|
||||||
let close_bracket = tag::<&str, OrgSource<'_>, CustomError<OrgSource<'_>>>("]")(input);
|
let close_bracket = tag::<_, _, CustomError>("]")(input);
|
||||||
if close_bracket.is_ok() {
|
if close_bracket.is_ok() {
|
||||||
return close_bracket;
|
return close_bracket;
|
||||||
}
|
}
|
||||||
|
@ -125,7 +125,7 @@ fn document_org_source<'b, 'g, 'r, 's>(
|
|||||||
.get_global_settings()
|
.get_global_settings()
|
||||||
.file_access
|
.file_access
|
||||||
.read_file(setup_file)
|
.read_file(setup_file)
|
||||||
.map_err(|err| nom::Err::<CustomError<OrgSource<'_>>>::Failure(err.into()))
|
.map_err(|err| nom::Err::<CustomError>::Failure(err.into()))
|
||||||
})
|
})
|
||||||
.collect::<Result<Vec<_>, _>>()?;
|
.collect::<Result<Vec<_>, _>>()?;
|
||||||
for setup_file in setup_files.iter().map(String::as_str) {
|
for setup_file in setup_files.iter().map(String::as_str) {
|
||||||
@ -171,14 +171,14 @@ fn document_org_source<'b, 'g, 'r, 's>(
|
|||||||
let (remaining, mut document) = _document(&parser_context, input)
|
let (remaining, mut document) = _document(&parser_context, input)
|
||||||
.map(|(rem, out)| (Into::<&str>::into(rem), out))?;
|
.map(|(rem, out)| (Into::<&str>::into(rem), out))?;
|
||||||
apply_post_parse_in_buffer_settings(&mut document)
|
apply_post_parse_in_buffer_settings(&mut document)
|
||||||
.map_err(|err| nom::Err::<CustomError<OrgSource<'_>>>::Failure(err.into()))?;
|
.map_err(|err| nom::Err::<CustomError>::Failure(err.into()))?;
|
||||||
return Ok((remaining.into(), document));
|
return Ok((remaining.into(), document));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Find final in-buffer settings that do not impact parsing
|
// Find final in-buffer settings that do not impact parsing
|
||||||
apply_post_parse_in_buffer_settings(&mut document)
|
apply_post_parse_in_buffer_settings(&mut document)
|
||||||
.map_err(|err| nom::Err::<CustomError<OrgSource<'_>>>::Failure(err.into()))?;
|
.map_err(|err| nom::Err::<CustomError>::Failure(err.into()))?;
|
||||||
|
|
||||||
Ok((remaining.into(), document))
|
Ok((remaining.into(), document))
|
||||||
}
|
}
|
||||||
|
@ -57,7 +57,7 @@ fn name<'b, 'g, 'r, 's>(
|
|||||||
) -> Res<OrgSource<'s>, (&'g EntityDefinition<'s>, OrgSource<'s>, bool)> {
|
) -> Res<OrgSource<'s>, (&'g EntityDefinition<'s>, OrgSource<'s>, bool)> {
|
||||||
for entity in context.get_global_settings().entities {
|
for entity in context.get_global_settings().entities {
|
||||||
let result = tuple((
|
let result = tuple((
|
||||||
tag::<_, _, CustomError<_>>(entity.name),
|
tag::<_, _, CustomError>(entity.name),
|
||||||
alt((
|
alt((
|
||||||
verify(map(tag("{}"), |_| true), |_| !entity.name.ends_with(' ')),
|
verify(map(tag("{}"), |_| true), |_| !entity.name.ends_with(' ')),
|
||||||
map(peek(recognize(entity_end)), |_| false),
|
map(peek(recognize(entity_end)), |_| false),
|
||||||
|
@ -231,9 +231,6 @@ fn greater_block_body<'c, 'b, 'g, 'r, 's>(
|
|||||||
context_name: &'c str,
|
context_name: &'c str,
|
||||||
) -> Res<OrgSource<'s>, (&'s str, Vec<Element<'s>>)> {
|
) -> Res<OrgSource<'s>, (&'s str, Vec<Element<'s>>)> {
|
||||||
if in_section(context, context_name) {
|
if in_section(context, context_name) {
|
||||||
return Err(CustomError::Static(
|
|
||||||
"Cannot nest objects of the same element",
|
|
||||||
));
|
|
||||||
return Err(nom::Err::Error(CustomError::Static(
|
return Err(nom::Err::Error(CustomError::Static(
|
||||||
"Cannot nest objects of the same element",
|
"Cannot nest objects of the same element",
|
||||||
)));
|
)));
|
||||||
|
@ -259,7 +259,7 @@ fn heading_keyword<'b, 'g, 'r, 's>(
|
|||||||
.iter()
|
.iter()
|
||||||
.map(String::as_str)
|
.map(String::as_str)
|
||||||
{
|
{
|
||||||
let result = tag::<_, _, CustomError<_>>(todo_keyword)(input);
|
let result = tag::<_, _, CustomError>(todo_keyword)(input);
|
||||||
if let Ok((remaining, ent)) = result {
|
if let Ok((remaining, ent)) = result {
|
||||||
return Ok((remaining, (TodoKeywordType::Todo, ent)));
|
return Ok((remaining, (TodoKeywordType::Todo, ent)));
|
||||||
}
|
}
|
||||||
@ -269,7 +269,7 @@ fn heading_keyword<'b, 'g, 'r, 's>(
|
|||||||
.iter()
|
.iter()
|
||||||
.map(String::as_str)
|
.map(String::as_str)
|
||||||
{
|
{
|
||||||
let result = tag::<_, _, CustomError<_>>(todo_keyword)(input);
|
let result = tag::<_, _, CustomError>(todo_keyword)(input);
|
||||||
if let Ok((remaining, ent)) = result {
|
if let Ok((remaining, ent)) = result {
|
||||||
return Ok((remaining, (TodoKeywordType::Done, ent)));
|
return Ok((remaining, (TodoKeywordType::Done, ent)));
|
||||||
}
|
}
|
||||||
|
@ -35,7 +35,7 @@ pub(crate) fn scan_for_in_buffer_settings<'s>(
|
|||||||
let mut remaining = input;
|
let mut remaining = input;
|
||||||
loop {
|
loop {
|
||||||
// Skip text until possible in_buffer_setting
|
// Skip text until possible in_buffer_setting
|
||||||
let start_of_pound = take_until::<_, _, CustomError<_>>("#+")(remaining);
|
let start_of_pound = take_until::<_, _, CustomError>("#+")(remaining);
|
||||||
let start_of_pound = if let Ok((start_of_pound, _)) = start_of_pound {
|
let start_of_pound = if let Ok((start_of_pound, _)) = start_of_pound {
|
||||||
start_of_pound
|
start_of_pound
|
||||||
} else {
|
} else {
|
||||||
@ -47,7 +47,7 @@ pub(crate) fn scan_for_in_buffer_settings<'s>(
|
|||||||
let (remain, maybe_kw) = match filtered_keyword(in_buffer_settings_key)(start_of_line) {
|
let (remain, maybe_kw) = match filtered_keyword(in_buffer_settings_key)(start_of_line) {
|
||||||
Ok((remain, kw)) => (remain, Some(kw)),
|
Ok((remain, kw)) => (remain, Some(kw)),
|
||||||
Err(_) => {
|
Err(_) => {
|
||||||
let end_of_line = take_until::<_, _, CustomError<_>>("\n")(start_of_pound);
|
let end_of_line = take_until::<_, _, CustomError>("\n")(start_of_pound);
|
||||||
if let Ok((end_of_line, _)) = end_of_line {
|
if let Ok((end_of_line, _)) = end_of_line {
|
||||||
(end_of_line, None)
|
(end_of_line, None)
|
||||||
} else {
|
} else {
|
||||||
|
@ -49,10 +49,8 @@ fn _filtered_keyword<'s, F: Fn(OrgSource<'s>) -> Res<OrgSource<'s>, OrgSource<'s
|
|||||||
// TODO: When key is a member of org-element-parsed-keywords, value can contain the standard set objects, excluding footnote references.
|
// TODO: When key is a member of org-element-parsed-keywords, value can contain the standard set objects, excluding footnote references.
|
||||||
let (remaining, (consumed_input, (_, _, parsed_key, _))) =
|
let (remaining, (consumed_input, (_, _, parsed_key, _))) =
|
||||||
consumed(tuple((space0, tag("#+"), key_parser, tag(":"))))(input)?;
|
consumed(tuple((space0, tag("#+"), key_parser, tag(":"))))(input)?;
|
||||||
if let Ok((remaining, _)) = tuple((
|
if let Ok((remaining, _)) =
|
||||||
space0::<OrgSource<'_>, CustomError<OrgSource<'_>>>,
|
tuple((space0::<_, CustomError>, alt((line_ending, eof))))(remaining)
|
||||||
alt((line_ending, eof)),
|
|
||||||
))(remaining)
|
|
||||||
{
|
{
|
||||||
return Ok((
|
return Ok((
|
||||||
remaining,
|
remaining,
|
||||||
@ -161,10 +159,7 @@ fn plain_affiliated_key<'b, 'g, 'r, 's>(
|
|||||||
) -> Res<OrgSource<'s>, OrgSource<'s>> {
|
) -> Res<OrgSource<'s>, OrgSource<'s>> {
|
||||||
for keyword in context.get_global_settings().element_affiliated_keywords {
|
for keyword in context.get_global_settings().element_affiliated_keywords {
|
||||||
let result = map(
|
let result = map(
|
||||||
tuple((
|
tuple((tag_no_case::<_, _, CustomError>(*keyword), peek(tag(":")))),
|
||||||
tag_no_case::<_, _, CustomError<_>>(*keyword),
|
|
||||||
peek(tag(":")),
|
|
||||||
)),
|
|
||||||
|(key, _)| key,
|
|(key, _)| key,
|
||||||
)(input);
|
)(input);
|
||||||
if let Ok((remaining, ent)) = result {
|
if let Ok((remaining, ent)) = result {
|
||||||
@ -182,7 +177,7 @@ fn dual_affiliated_key<'b, 'g, 'r, 's>(
|
|||||||
) -> Res<OrgSource<'s>, OrgSource<'s>> {
|
) -> Res<OrgSource<'s>, OrgSource<'s>> {
|
||||||
for keyword in context.get_global_settings().element_dual_keywords {
|
for keyword in context.get_global_settings().element_dual_keywords {
|
||||||
let result = recognize(tuple((
|
let result = recognize(tuple((
|
||||||
tag_no_case::<_, _, CustomError<_>>(*keyword),
|
tag_no_case::<_, _, CustomError>(*keyword),
|
||||||
tag("["),
|
tag("["),
|
||||||
optval,
|
optval,
|
||||||
tag("]"),
|
tag("]"),
|
||||||
@ -221,7 +216,7 @@ fn _optval_end<'s>(
|
|||||||
unreachable!("Exceeded optval bracket depth.")
|
unreachable!("Exceeded optval bracket depth.")
|
||||||
}
|
}
|
||||||
if current_depth == 0 {
|
if current_depth == 0 {
|
||||||
let close_bracket = tag::<_, _, CustomError<_>>("]")(input);
|
let close_bracket = tag::<_, _, CustomError>("]")(input);
|
||||||
if close_bracket.is_ok() {
|
if close_bracket.is_ok() {
|
||||||
return close_bracket;
|
return close_bracket;
|
||||||
}
|
}
|
||||||
|
@ -96,7 +96,7 @@ fn org_macro_arg<'b, 'g, 'r, 's>(
|
|||||||
loop {
|
loop {
|
||||||
not(parser_with_context!(exit_matcher_parser)(context))(remaining)?;
|
not(parser_with_context!(exit_matcher_parser)(context))(remaining)?;
|
||||||
not(peek(tag("}}}")))(remaining)?;
|
not(peek(tag("}}}")))(remaining)?;
|
||||||
if peek(tuple((space0::<OrgSource<'_>, CustomError<_>>, tag(")"))))(remaining).is_ok() {
|
if peek(tuple((space0::<_, CustomError>, tag(")"))))(remaining).is_ok() {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -108,7 +108,7 @@ fn org_macro_arg<'b, 'g, 'r, 's>(
|
|||||||
}
|
}
|
||||||
if next_char == '\\' {
|
if next_char == '\\' {
|
||||||
escaping = true;
|
escaping = true;
|
||||||
if peek(tag::<_, _, CustomError<_>>(")"))(new_remaining).is_ok() {
|
if peek(tag::<_, _, CustomError>(")"))(new_remaining).is_ok() {
|
||||||
// Special case for backslash at the end of a macro
|
// Special case for backslash at the end of a macro
|
||||||
remaining = new_remaining;
|
remaining = new_remaining;
|
||||||
break;
|
break;
|
||||||
|
@ -261,7 +261,7 @@ pub(crate) fn protocol<'b, 'g, 'r, 's>(
|
|||||||
input: OrgSource<'s>,
|
input: OrgSource<'s>,
|
||||||
) -> Res<OrgSource<'s>, OrgSource<'s>> {
|
) -> Res<OrgSource<'s>, OrgSource<'s>> {
|
||||||
for link_parameter in context.get_global_settings().link_parameters {
|
for link_parameter in context.get_global_settings().link_parameters {
|
||||||
let result = tag_no_case::<_, _, CustomError<_>>(*link_parameter)(input);
|
let result = tag_no_case::<_, _, CustomError>(*link_parameter)(input);
|
||||||
if let Ok((remaining, ent)) = result {
|
if let Ok((remaining, ent)) = result {
|
||||||
return Ok((remaining, ent));
|
return Ok((remaining, ent));
|
||||||
}
|
}
|
||||||
@ -324,8 +324,7 @@ fn impl_path_plain_end<'b, 'g, 'r, 's>(
|
|||||||
}
|
}
|
||||||
|
|
||||||
if current_depth == 0 {
|
if current_depth == 0 {
|
||||||
let close_parenthesis =
|
let close_parenthesis = tag::<_, _, CustomError>(")")(remaining);
|
||||||
tag::<&str, OrgSource<'_>, CustomError<OrgSource<'_>>>(")")(remaining);
|
|
||||||
if close_parenthesis.is_ok() {
|
if close_parenthesis.is_ok() {
|
||||||
return close_parenthesis;
|
return close_parenthesis;
|
||||||
}
|
}
|
||||||
@ -415,13 +414,13 @@ fn _path_plain_parenthesis_end<'s>(
|
|||||||
unreachable!("Exceeded plain link parenthesis depth.")
|
unreachable!("Exceeded plain link parenthesis depth.")
|
||||||
}
|
}
|
||||||
if current_depth == 0 {
|
if current_depth == 0 {
|
||||||
let close_parenthesis = tag::<&str, OrgSource<'_>, CustomError<OrgSource<'_>>>(")")(input);
|
let close_parenthesis = tag::<_, _, CustomError>(")")(input);
|
||||||
if close_parenthesis.is_ok() {
|
if close_parenthesis.is_ok() {
|
||||||
return close_parenthesis;
|
return close_parenthesis;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if current_depth == 1 {
|
if current_depth == 1 {
|
||||||
let open_parenthesis = tag::<&str, OrgSource<'_>, CustomError<OrgSource<'_>>>("(")(input);
|
let open_parenthesis = tag::<_, _, CustomError>("(")(input);
|
||||||
if open_parenthesis.is_ok() {
|
if open_parenthesis.is_ok() {
|
||||||
return open_parenthesis;
|
return open_parenthesis;
|
||||||
}
|
}
|
||||||
|
@ -91,7 +91,7 @@ impl<'x> RematchObject<'x> for PlainText<'x> {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
let is_not_whitespace = is_not::<&str, &str, CustomError<_>>(" \t\r\n")(goal);
|
let is_not_whitespace = is_not::<_, _, CustomError>(" \t\r\n")(goal);
|
||||||
if let Ok((new_goal, payload)) = is_not_whitespace {
|
if let Ok((new_goal, payload)) = is_not_whitespace {
|
||||||
let (new_remaining, _) = tuple((
|
let (new_remaining, _) = tuple((
|
||||||
tag_no_case(payload),
|
tag_no_case(payload),
|
||||||
@ -107,7 +107,7 @@ impl<'x> RematchObject<'x> for PlainText<'x> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let is_whitespace = recognize(many1(alt((
|
let is_whitespace = recognize(many1(alt((
|
||||||
recognize(one_of::<&str, &str, CustomError<_>>(" \t")),
|
recognize(one_of::<_, _, CustomError>(" \t")),
|
||||||
line_ending,
|
line_ending,
|
||||||
))))(goal);
|
))))(goal);
|
||||||
if let Ok((new_goal, _)) = is_whitespace {
|
if let Ok((new_goal, _)) = is_whitespace {
|
||||||
|
@ -38,7 +38,7 @@ pub(crate) fn detect_subscript_or_superscript<'s>(input: OrgSource<'s>) -> Res<O
|
|||||||
// This does not have to detect all valid subscript/superscript but all that it detects must be valid.
|
// This does not have to detect all valid subscript/superscript but all that it detects must be valid.
|
||||||
let (remaining, _) = one_of("_^")(input)?;
|
let (remaining, _) = one_of("_^")(input)?;
|
||||||
pre(input)?;
|
pre(input)?;
|
||||||
if tag::<_, _, CustomError<_>>("*")(remaining).is_ok() {
|
if tag::<_, _, CustomError>("*")(remaining).is_ok() {
|
||||||
return Ok((input, ()));
|
return Ok((input, ()));
|
||||||
}
|
}
|
||||||
let (remaining, _) = opt(one_of("+-"))(remaining)?;
|
let (remaining, _) = opt(one_of("+-"))(remaining)?;
|
||||||
@ -281,7 +281,7 @@ fn _script_with_parenthesis_end<'s>(
|
|||||||
unreachable!("Exceeded citation key suffix bracket depth.")
|
unreachable!("Exceeded citation key suffix bracket depth.")
|
||||||
}
|
}
|
||||||
if current_depth == 0 {
|
if current_depth == 0 {
|
||||||
let close_parenthesis = tag::<&str, OrgSource<'_>, CustomError<OrgSource<'_>>>(")")(input);
|
let close_parenthesis = tag::<_, _, CustomError>(")")(input);
|
||||||
if close_parenthesis.is_ok() {
|
if close_parenthesis.is_ok() {
|
||||||
return close_parenthesis;
|
return close_parenthesis;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user