public override Node VisitCallExpression(DustParser.CallExpressionContext context)
        {
            string name = context.functionName().GetText();

            CallParameter[] parameters = context.callParameterList().callParameter().Select(Visit).Cast <CallParameter>().ToArray();
            Function        function   = visitorContext.GetFunction(name);

            if (function == null)
            {
                visitorContext.ErrorHandler.ThrowError(new SyntaxError($"Function '{name}' is not defined", context.functionName().GetRange()));

                return(null);
            }

            if (function.Parameters.Length != parameters.Length)
            {
                visitorContext.ErrorHandler.ThrowError(new SyntaxError($"Function '{function.Name}' has {function.Parameters.Length} parameters but is called with {parameters.Length}", context.callParameterList().GetRange()));

                return(null);
            }

            return(new CallExpression(function, parameters, context.GetRange()));
        }
Exemple #2
0
 /// <summary>
 /// Visit a parse tree produced by the <c>CallExpression</c>
 /// labeled alternative in <see cref="DustParser.expression"/>.
 /// <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 VisitCallExpression([NotNull] DustParser.CallExpressionContext context)
 {
     return(VisitChildren(context));
 }
Exemple #3
0
 /// <summary>
 /// Exit a parse tree produced by the <c>CallExpression</c>
 /// labeled alternative in <see cref="DustParser.expression"/>.
 /// <para>The default implementation does nothing.</para>
 /// </summary>
 /// <param name="context">The parse tree.</param>
 public virtual void ExitCallExpression([NotNull] DustParser.CallExpressionContext context)
 {
 }