Catch more parse errors.

This commit is contained in:
Stephen Chung
2021-07-04 00:15:27 +08:00
parent 69c14e65f3
commit b4da054bab
4 changed files with 72 additions and 20 deletions

View File

@@ -125,6 +125,9 @@ pub enum ParseErrorType {
VariableExpected,
/// An identifier is a reserved keyword.
Reserved(String),
/// An expression is of the wrong type.
/// Wrapped values are the type requested and type of the actual result.
MismatchedType(String, String),
/// Missing an expression. Wrapped value is the expression type.
ExprExpected(String),
/// Defining a doc-comment in an appropriate place (e.g. not at global level).
@@ -230,6 +233,7 @@ impl fmt::Display for ParseErrorType {
Self::DuplicatedSwitchCase => f.write_str("Duplicated switch case"),
Self::DuplicatedVariable(s) => write!(f, "Duplicated variable name '{}'", s),
Self::MismatchedType(r, a) => write!(f, "Expecting {}, not {}", r, a),
Self::ExprExpected(s) => write!(f, "Expecting {} expression", s),
Self::MissingToken(token, s) => write!(f, "Expecting '{}' {}", token, s),
Self::MissingSymbol(s) => f.write_str(s),