visitIndexingExpr method
Implementation
@override
Object? visitIndexingExpr(Expr.Indexing expr) {
Object? object = evaluate(expr.callee);
if (object is List) {
return object[evaluate(expr.key) as int];
}
if (object is String) {
return object[evaluate(expr.key) as int];
}
if (object is Map) {
return object[evaluate(expr.key) as String];
}
if (object is RegExpMatch) {
return object[evaluate(expr.key) as int];
}
throw RuntimeError(expr.name, "Only list or map can be used in indexing.");
}