Try using error formatting

This commit is contained in:
greg 2020-03-07 03:12:24 -08:00
parent b1ffcd709b
commit 34fd29ebca
2 changed files with 10 additions and 2 deletions

View File

@ -1,3 +1,4 @@
#![feature(or_patterns)]
#![feature(trace_macros)] #![feature(trace_macros)]
//#![feature(unrestricted_attribute_tokens)] //#![feature(unrestricted_attribute_tokens)]
#![feature(slice_patterns, box_patterns, box_syntax)] #![feature(slice_patterns, box_patterns, box_syntax)]

View File

@ -215,6 +215,13 @@ fn expression_kind(text: &str) -> ParseResult<ExpressionKind> {
} }
pub fn perform_parsing(input: &str) -> Result<String, String> { pub fn perform_parsing(input: &str) -> Result<String, String> {
let output = expression_kind(input); let output = match expression_kind(input) {
Ok(format!("{:?}", output)) Ok((rest, ast)) => format!("{:?}", ast),
Err(nom::Err::Incomplete(needed)) => format!("Incomplete: {:?}" ,needed),
Err(nom::Err::Error(verbose_error) | nom::Err::Failure(verbose_error)) => {
nom::error::convert_error(input, verbose_error)
}
};
Ok(output)
} }