예제 #1
0
        private static int[] ParameterMapping(bool strongParameterCheck, Rule rule, RuleAttribute ruleAttribute, MethodBase methodBase)
        {
#pragma warning disable 612
            int[] parameterMapping;
            if (ruleAttribute.HasConstructorParameterMapping)
            {
                parameterMapping = ruleAttribute.ConstructorParameterMapping;
                if (parameterMapping == null)
                {
                    parameterMapping = new int[ruleAttribute.AllowTruncationForConstructor ? methodBase.GetParameters().Length : rule.SymbolCount];
                    for (int i = 1; i < parameterMapping.Length; i++)
                    {
                        parameterMapping[i] = i;
                    }
                }
            }
            else
            {
                parameterMapping = RuleDeclarationParser.BindMethodBase(ruleAttribute.ParsedRule, methodBase, ruleAttribute.AllowTruncationForConstructor, ruleAttribute.StrictlyMatchParametersOrDefault(strongParameterCheck));
            }
            return(parameterMapping);

#pragma warning restore 612
        }
예제 #2
0
        private void ProcessAttribute <TU>(ICollection <string> errors, bool strongParameterCheck, RuleAttribute ruleAttribute, Type type, TU methodBase, GetFactoryType <TU> getFactoryType) where TU : MethodBase
        {
            Rule rule = ruleAttribute.Bind(Grammar);

            if (rule == null)
            {
                errors.Add(string.Format("Rule {0} not found in grammar", ruleAttribute.Rule));
            }
            else
            {
                try {
                    Type factoryType;
                    TU   factoryConstructor;
                    getFactoryType(methodBase, ruleAttribute, type, out factoryType, out factoryConstructor);
                    int[] parameterMapping = ParameterMapping(strongParameterCheck, rule, ruleAttribute, methodBase);
                    SemanticNonterminalFactory <T> nonterminalFactory = CreateNonterminalFactory(factoryType, factoryConstructor, parameterMapping, rule.SymbolCount);
                    RegisterNonterminalFactory(rule, nonterminalFactory);
                } catch (TargetInvocationException ex) {
                    errors.Add(string.Format("Rule {0} factory problem: {1}", rule, ex.InnerException.Message));
                } catch (Exception ex) {
                    errors.Add(string.Format("Rule {0} factory problem: {1}", rule, ex.Message));
                }
            }
        }