示例#1
0
        public void AddUserDefinedLambda(
            ShellParser.FunctionContext ctx
            )
        {
            var lambda = new UserDefinedLambda(ctx);

            foreach (var definition in definitions)
            {
                if (lambda.argList.Count == definition.argList.Count)
                {
                    var tokens = lambda.argList.Zip(definition.argList,
                                                    (t1, t2) => new { LambdaToken = t1, DefinitionToken = t2 }
                                                    );
                    int i = 0;
                    foreach (var tokenPair in tokens)
                    {
                        var lt = tokenPair.LambdaToken;
                        var dt = tokenPair.DefinitionToken;
                        if (lt.Item2 == Specifier.Any || dt.Item2 == Specifier.Any || lt.Item2 == dt.Item2)
                        {
                            i++;
                        }
                    }
                    if (i == lambda.argList.Count)
                    {
                        throw new Shell.Problems.InvalidFunctionDefinition(
                                  new Interpreter.Source(ctx.Start, ctx.Stop),
                                  this, lambda
                                  );
                    }
                }
            }

            definitions.Add(lambda);
        }
示例#2
0
        /// <remark>
        /// function : KW_FUN LPAREN (function_argument (SYM_COMMA function_argument)*)? RPAREN statement_block ;
        /// function_argument : argument_type_specifier IDENTIFIER ;
        /// </remark>
        public UserDefinedLambda(ShellParser.FunctionContext ctx)
        {
            context         = ctx;
            statement_block = context.statement_block();
            for (int i = 0; i < context.function_argument().Length; i++)
            {
                var    arg   = context.function_argument(i);
                string name  = arg.IDENTIFIER().GetText();
                var    token = Shell.Interpreter.Utility.GetTokenOfArgumentTypeSpecifier(arg.argument_type_specifier());

                argList.Add(new Tuple <string, Specifier>(name, Shell.Interpreter.Utility.GetSpecifier(token)));
            }
        }
示例#3
0
 /// <summary>
 /// Visit a parse tree produced by <see cref="ShellParser.function"/>.
 /// <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 VisitFunction([NotNull] ShellParser.FunctionContext context)
 {
     return(VisitChildren(context));
 }