private void initIndexCounter()
 {
     // index counter is really only important for sets, because it tells which one of the elements should be enabled
     if (this.modeCounter.Value == RhsEntitySelector.SelectionEnum.Individuals)
     {
         this.indexCounter = CycleCounter.Create(this.entity.Count);
     }
     else
     {
         this.indexCounter = CycleCounter.Create(-1, 0); // keep the value such it will never match the index of the element
     }
 }
Exemplo n.º 2
0
        private static IEnumerable <IEnumerable <SYMBOL_ENUM> > unAliasProductionRhs(SYMBOL_ENUM symbol,
                                                                                     SYMBOL_ENUM[] expansion,
                                                                                     Production <SYMBOL_ENUM, TREE_NODE> production,
                                                                                     SYMBOL_ENUM startSymbol,
                                                                                     SYMBOL_ENUM syntaxErrorSymbol,
                                                                                     ref UnAliasing change)
        {
            if (production.RhsSymbols.All(it => !it.Equals(symbol)))
            {
                return new[] { production.RhsSymbols }
            }
            ;

            // todo: remove this condition when recovery points will be improved
            if (expansion.Length > 1 &&
                (production.LhsNonTerminal.Equals(startSymbol) || production.RhsSymbols.Any(it => it.Equals(syntaxErrorSymbol))))
            {
                change = UnAliasing.Forbidden;

                return(new[] { production.RhsSymbols });
            }

            change = UnAliasing.Expansion;

            // a lot of memory allocation, but code is much simpler than otherwise

            // for aliased symbol use its expansions, for others -- just the given symbol
            SYMBOL_ENUM[][] replacements = production.RhsSymbols.Select(it => it.Equals(symbol) ? expansion : new[] { it }).ToArray();
            CycleCounter[]  counters     = replacements.Select(it => CycleCounter.Create(it.Length)).ToArray();

            var result = new List <IEnumerable <SYMBOL_ENUM> >();

            do
            {
                // has to pin down collection to avoid local capture
                result.Add(replacements.SyncZip(counters).Select(it => it.Item1[it.Item2.Value]).ToArray());
            }while (counters.Iterate());

            return(result);
        }