コード例 #1
0
        private static bool TryParseFunctionDeclaration(IdentifierNode identifier, ArgumentSetNode argumentSet, [NotNullWhen(true)] out FunctionDeclaration?declaration)
        {
            declaration = default;
            var functionName = identifier.TextValue;
            var arguments    = argumentSet.Arguments.Select(ParseParameterDeclaration).ToArray();

            // Check for a required parameter that exists after an optional parameter
            var firstOptionalIndex = int.MaxValue;

            for (int argIndex = 0; argIndex < arguments.Length; ++argIndex)
            {
                var arg = arguments[argIndex] ?? throw new NotImplementedException();
                if (arg.Optional)
                {
                    firstOptionalIndex = Math.Min(firstOptionalIndex, argIndex);
                }
                else if (firstOptionalIndex != int.MaxValue)
                {
                    // This is *NOT* optional, yet exists after an optional parameter.
                    throw new NotImplementedException();
                }
            }

            ParameterDeclaration[] nonNullArguments = arguments.Where(arg => arg != null).Select(arg => arg).ToArray() !;
            if (nonNullArguments.Length != arguments.Length)
            {
                return(false);
            }
            declaration = new FunctionDeclaration(returnType: typeof(object), functionName, nonNullArguments);
            return(true);
        }
コード例 #2
0
 public ScopedUserDefinedFunction(FunctionDeclaration declaration, ScopedUserDefinedFunctionDelegate body)
 {
     Body        = body;
     Declaration = declaration;
 }
コード例 #3
0
 public UserDefinedTest(FunctionDeclaration <bool> declaration, UserDefinedTestDelegate body)
 {
     Declaration = declaration;
     Body        = body;
 }
コード例 #4
0
 public UserDefinedFunction(FunctionDeclaration declaration, UserDefinedFunctionDelegate body)
 {
     Declaration = declaration;
     Body        = body;
 }