Compiler that compiles a plural rule abstract syntax tree into a managed dynamic method delegate using an IL code generator.
        public void CompileCompleteRulesTest()
        {
            var parser = new AstTokenParser();
            var compiler = new PluralRuleCompiler();
            foreach (object[] mapping in GetParseCompleteRulesTestData())
            {
                var astRoot = parser.Parse((string)mapping[0]);
                var expectedSeq = (string)mapping[1];
                var dynamicMethod = (PluralRuleEvaluatorDelegate)compiler.CompileToDynamicMethod(astRoot, typeof(PluralRuleEvaluatorDelegate));

                for (int i = 0; i < 200; i++)
                {
                    var expected = int.Parse(expectedSeq[i].ToString());
                    Assert.Equal(expected, dynamicMethod(i));
                }
            }
        }
        public void CompileRulesTest()
        {
            var parser = new AstTokenParser();
            var compiler = new PluralRuleCompiler();
            foreach (object[] mapping in GetParseRulesTestData())
            {
                var astRoot = parser.Parse((string)mapping[1]);
                var dynamicMethod = (PluralRuleEvaluatorDelegate)compiler.CompileToDynamicMethod(astRoot, typeof(PluralRuleEvaluatorDelegate));

                Assert.Equal((int)mapping[2], dynamicMethod(0));
            }
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="CompiledPluralRuleGenerator"/> class using 
 /// given plural rule compiler and given AST token parser.
 /// </summary>
 /// <param name="pluralRuleText"></param>
 /// <param name="parser"></param>
 /// <param name="compiler"></param>
 public CompiledPluralRuleGenerator(string pluralRuleText, AstTokenParser parser, PluralRuleCompiler compiler)
     : base(pluralRuleText, parser)
 {
     this.Compiler = compiler;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="CompiledPluralRuleGenerator"/> class using 
 /// given plural rule compiler and the default AST token parser.
 /// </summary>
 /// <param name="pluralRuleText"></param>
 /// <param name="compiler"></param>
 public CompiledPluralRuleGenerator(string pluralRuleText, PluralRuleCompiler compiler)
     : base(pluralRuleText)
 {
     this.Compiler = compiler;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="CompiledPluralRuleGenerator"/> class using 
 /// given plural rule compiler and given AST token parser.
 /// </summary>
 /// <param name="parser"></param>
 /// <param name="compiler"></param>
 public CompiledPluralRuleGenerator(AstTokenParser parser, PluralRuleCompiler compiler)
     : base(parser)
 {
     this.Compiler = compiler;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="CompiledPluralRuleGenerator"/> class using 
 /// given plural rule compiler and the default AST token parser.
 /// </summary>
 /// <param name="compiler"></param>
 public CompiledPluralRuleGenerator(PluralRuleCompiler compiler)
     : base()
 {
     this.Compiler = compiler;
 }