Quote:
Originally Posted by pinterf
It would be nice to have indexing with []
|
I would do this by changing the parser's ParseOOP() function - in the two places it currently calls ParseFunction(), it would instead call a new function ParseIndex(), which would look like this:
Code:
PExpression ScriptParser::Parseindex(PExpression context)
{
PExpression result = ParseFunction(context);
while (tokenizer.IsOperator('[') {
tokenizer.NextToken();
result = new ExpIndex(result, ParseConditional());
Expect(']');
}
return result;
}
This allows things like:
-
x.f(2)[3], where f is a function returning an array (no need to put brackets round
x.f(2))
-
a[1]["white"], where a is a multi-dimensional array
-
a[1].f(2), equivalent to
f(a[1], 2)
ExpIndex is a new Expression subtype whose Evaluate() function calls the built-in ArrayIndex function.