Fix LexError::ImproperSymbol.

This commit is contained in:
Stephen Chung 2020-11-21 15:15:14 +08:00
parent 611f6151d5
commit eb4636f219
2 changed files with 4 additions and 2 deletions

View File

@ -120,7 +120,7 @@ pub fn from_dynamic<'de, T: Deserialize<'de>>(
impl Error for Box<EvalAltResult> { impl Error for Box<EvalAltResult> {
fn custom<T: fmt::Display>(err: T) -> Self { fn custom<T: fmt::Display>(err: T) -> Self {
EvalAltResult::ErrorParsing( EvalAltResult::ErrorParsing(
ParseErrorType::BadInput(LexError::ImproperSymbol(err.to_string())), ParseErrorType::BadInput(LexError::ImproperSymbol("".to_string(), err.to_string())),
Position::NONE, Position::NONE,
) )
.into() .into()

View File

@ -79,6 +79,7 @@ fn test_custom_syntax() -> Result<(), Box<EvalAltResult>> {
.expect_err("should error") .expect_err("should error")
.0, .0,
ParseErrorType::BadInput(LexError::ImproperSymbol( ParseErrorType::BadInput(LexError::ImproperSymbol(
"!".to_string(),
"Improper symbol for custom syntax at position #1: '!'".to_string() "Improper symbol for custom syntax at position #1: '!'".to_string()
)) ))
); );
@ -100,6 +101,7 @@ fn test_custom_syntax_raw() -> Result<(), Box<EvalAltResult>> {
s => Err(ParseError( s => Err(ParseError(
Box::new(ParseErrorType::BadInput(LexError::ImproperSymbol( Box::new(ParseErrorType::BadInput(LexError::ImproperSymbol(
s.to_string(), s.to_string(),
"".to_string(),
))), ))),
Position::NONE, Position::NONE,
)), )),
@ -128,7 +130,7 @@ fn test_custom_syntax_raw() -> Result<(), Box<EvalAltResult>> {
assert_eq!(engine.eval::<INT>("(hello kitty) + foo")?, 1041); assert_eq!(engine.eval::<INT>("(hello kitty) + foo")?, 1041);
assert_eq!( assert_eq!(
*engine.compile("hello hey").expect_err("should error").0, *engine.compile("hello hey").expect_err("should error").0,
ParseErrorType::BadInput(LexError::ImproperSymbol("hey".to_string())) ParseErrorType::BadInput(LexError::ImproperSymbol("hey".to_string(), "".to_string()))
); );
Ok(()) Ok(())