Esempio n. 1
0
        private RuleTrimAttribute(string rule, int trimSymbolIndex, string trimSymbol, ArgumentExceptionDelegate notFoundException) : base(rule)
        {
            if (trimSymbol == null)
            {
                throw new ArgumentNullException("trimSymbol");
            }
            int ruleHandleCount = 0;

            using (IEnumerator <string> ruleHandleEnumerator = RuleDeclarationParser.GetRuleHandleNames(ParsedRule).GetEnumerator()) {
                while (ruleHandleEnumerator.MoveNext())
                {
                    if (trimSymbol.Equals(ruleHandleEnumerator.Current))
                    {
                        if (trimSymbolIndex >= 0)
                        {
                            throw new ArgumentException("The given symbol is ambigious in this rule", "trimSymbol");
                        }
                        trimSymbolIndex = ruleHandleCount;
                    }
                    ruleHandleCount++;
                }
            }
            if ((trimSymbolIndex < 0) || (trimSymbolIndex >= ruleHandleCount))
            {
                throw notFoundException();
            }
            this.trimSymbolIndex = trimSymbolIndex;
        }
		public void NullRuleString() {
			RuleDeclarationParser parser = new RuleDeclarationParser(grammar);
			Rule rule;
			Assert.Throws<ArgumentNullException>(() => {
				parser.TryParse(null, out rule);
			});
		}
Esempio n. 3
0
        public Rule Bind(CompiledGrammar grammar)
        {
            if (grammar == null)
            {
                throw new ArgumentNullException("grammar");
            }
            Rule rule;

            RuleDeclarationParser.TryBindGrammar(parsedRule, grammar, out rule);
            return(rule);
        }
Esempio n. 4
0
 internal RuleAttributeBase(string rule)
 {
     if (string.IsNullOrEmpty(rule))
     {
         throw new ArgumentNullException("rule");
     }
     if (!RuleDeclarationParser.TryParse(rule, out parsedRule))
     {
         throw new ArgumentException(string.Format("The rule {0} contains a syntax error", rule), "rule");
     }
 }
Esempio n. 5
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
        }
		public void ValidRuleStringSimple() {
			RuleDeclarationParser parser = new RuleDeclarationParser(grammar);
			Rule rule;
			Assert.Equal(true, parser.TryParse("<Value> ::= Float", out rule));
			Debug.WriteLine(rule.Definition);
		}
		public void ValidRuleStringEmpty() {
			RuleDeclarationParser parser = new RuleDeclarationParser(grammar);
			Rule rule;
			Assert.Equal(true, parser.TryParse("<Empty> ::=", out rule));
			Debug.WriteLine(rule.Definition);
		}
		public void ValidRuleStringComplex() {
			RuleDeclarationParser parser = new RuleDeclarationParser(grammar);
			Rule rule;
			Assert.True(parser.TryParse("<Value> ::= '(' <Expression> ')'", out rule));
			Debug.WriteLine(rule.Definition);
		}