Beispiel #1
0
        public override AstNode VisitMethodCall(StannumParser.MethodCallContext context)
        {
            var arguments = new List <Expr>();

            if (!(Visit(context.Subject) is Expr subject))
            {
                throw new Exception("Unrecognized expression!");
            }

            arguments.Add(subject);

            if (!(Visit(context.Field) is Identifier field))
            {
                throw new Exception("Unrecognized identifier!");
            }

            var callee = new BinaryExpr(subject, ".", field);

            for (var i = 0; i < context._Args.Count; i += 1)
            {
                if (!(Visit(context._Args[i]) is Expr argument))
                {
                    throw new Exception("Unrecognized expression!");
                }

                arguments.Add(argument);
            }

            return(new CallExpr(callee, arguments));
        }
Beispiel #2
0
 /// <summary>
 /// Visit a parse tree produced by the <c>MethodCall</c>
 /// labeled alternative in <see cref="StannumParser.accessOrCall"/>.
 /// <para>
 /// The default implementation returns the result of calling <see cref="AbstractParseTreeVisitor{Result}.VisitChildren(IRuleNode)"/>
 /// on <paramref name="context"/>.
 /// </para>
 /// </summary>
 /// <param name="context">The parse tree.</param>
 /// <return>The visitor result.</return>
 public virtual Result VisitMethodCall([NotNull] StannumParser.MethodCallContext context)
 {
     return(VisitChildren(context));
 }