Allow chaining of indexing (one level) and dotting.

This commit is contained in:
Stephen Chung
2020-03-07 22:50:46 +08:00
parent df6950f8f7
commit eed7bef974
3 changed files with 178 additions and 74 deletions

View File

@@ -19,6 +19,8 @@ pub enum EvalAltResult {
ErrorFunctionArgsMismatch(String, usize, usize, Position),
/// Non-boolean operand encountered for boolean operator. Wrapped value is the operator.
ErrorBooleanArgMismatch(String, Position),
/// Non-character value encountered where a character is required.
ErrorCharMismatch(Position),
/// Array access out-of-bounds.
/// Wrapped values are the current number of elements in the array and the index number.
ErrorArrayBounds(usize, i64, Position),
@@ -64,6 +66,7 @@ impl Error for EvalAltResult {
"Function call with wrong number of arguments"
}
Self::ErrorBooleanArgMismatch(_, _) => "Boolean operator expects boolean operands",
Self::ErrorCharMismatch(_) => "Character expected",
Self::ErrorIndexExpr(_) => "Indexing into an array or string expects an integer index",
Self::ErrorIndexingType(_, _) => {
"Indexing can only be performed on an array or a string"
@@ -131,6 +134,9 @@ impl std::fmt::Display for EvalAltResult {
Self::ErrorBooleanArgMismatch(op, pos) => {
write!(f, "{} operator expects boolean operands ({})", op, pos)
}
Self::ErrorCharMismatch(pos) => {
write!(f, "string indexing expects a character value ({})", pos)
}
Self::ErrorArrayBounds(_, index, pos) if *index < 0 => {
write!(f, "{}: {} < 0 ({})", desc, index, pos)
}