Add ParseError:err_type and ParseError::position.

This commit is contained in:
Stephen Chung
2022-07-29 09:42:30 +08:00
parent 6fab9f5b63
commit ea38185cac
19 changed files with 147 additions and 104 deletions

View File

@@ -7,10 +7,10 @@ fn test_tokens_disabled() {
engine.disable_symbol("if"); // disable the 'if' keyword
assert!(matches!(
*engine
engine
.compile("let x = if true { 42 } else { 0 };")
.expect_err("should error")
.0,
.err_type(),
ParseErrorType::Reserved(err) if err == "if"
));
@@ -20,12 +20,12 @@ fn test_tokens_disabled() {
*engine
.compile("let x = 40 + 2; x += 1;")
.expect_err("should error")
.0,
.err_type(),
ParseErrorType::UnknownOperator("+=".to_string())
);
assert!(matches!(
*engine.compile("let x = += 0;").expect_err("should error").0,
engine.compile("let x = += 0;").expect_err("should error").err_type(),
ParseErrorType::Reserved(err) if err == "+="
));
}