Ejemplo n.º 1
0
        /// <summary>
        /// Creates a new bottom up rewriter instance with no initial rewrite rule definitions.
        /// Collection initializer syntax can be used for the Leaves, Rules, and Fallbacks properties.
        /// </summary>
        /// <param name="sourceNodeComparer">Equality comparer used to compare source tree nodes during construction of the rule table and during tree matching.</param>
        public BottomUpRewriter(IEqualityComparer <TSourceNodeType> sourceNodeComparer)
        {
            if (sourceNodeComparer == null)
            {
                throw new ArgumentNullException(nameof(sourceNodeComparer));
            }

            _wildcardFactory = new TWildcardFactory();

            Leaves           = new LeafCollection <TSource, TTarget>();
            Leaves.Added    += OnLeafAdded;
            Rules            = new RuleCollection <TSource, TTarget>();
            Rules.Added     += OnRuleAdded;
            Fallbacks        = new FallbackCollection <TSource, TTarget>();
            Fallbacks.Added += OnFallbackAdded;

            _forest        = new Dictionary <TSource, int>();
            _wildcards     = new Dictionary <TSource, int>(new EqualityComparerByType <TSource>());
            _constants     = new Dictionary <TSource, int>();
            _states        = new Dictionary <TSourceNodeType, NAryMap <int, int> >(sourceNodeComparer);
            _leafTests     = new Dictionary <Func <TSource, bool>, int>();
            _fallbackTests = new Dictionary <Func <TSource, bool>, int>();
            _finals        = new Dictionary <int, RuleBase <TSource, TTarget> >();
        }
Ejemplo n.º 2
0
 internal ExpressionRewriterLeafCollection(LeafCollection <ExpressionTreeBase, TTarget> leaves) => _leaves = leaves;