private static Expression GetMemberExpression(IList <ParseNode> nodes, int start, Expression context)
{
Debug.Assert(nodes.Count >= 3 && nodes.Count % 2 == 1);
Expression result;
if (start == 0)
{
result = GetInnerAST(nodes, context);
}
else
{
var @operator = nodes[start - 1].Token;
var baseExpr = GetMemberExpression(nodes, start - 2, context);
if (@operator.Type == TokenType.DOT)
{
var child = nodes[start].Nodes[0];
if (child.Token.Type == TokenType.FunctionCall)
{
result = GetFunctionAST(child.Nodes, baseExpr, false, context);
}
else if (child.Token.Type == TokenType.IDENTIFIER)
{
var fieldName = nodes[start].Nodes[0].Token.Text;
result = Expression.Dynamic(DLRUtil.GetFieldPropertyBinder(fieldName), typeof(object), baseExpr);
}
else
{
throw new InvalidOperationException("Invalid children, expect either Property or Method call at this point");
}
}
else if (@operator.Type == TokenType.LBRACKET)
{
var indexExpr = nodes[start].GetAST(context);
result = Expression.Dynamic(DLRUtil.GetIndexBinder(),
typeof(object),
baseExpr,
indexExpr);
}
else
{
throw new InvalidOperationException();
}
}
return(result);
}