private IEnumerable <SymbolMarked> buildConfiguration(string containerName, bool enabled)
            {
                if (entity.IsSymbol())
                {
                    RhsSymbol sym = entity.AsSymbol();
                    yield return(new SymbolMarked(
                                     // (used only for repetition, so typenames will be real -- comment is left over from killing projection)
                                     sym.Renamed(containerName ?? sym.ObjName),
                                     enabled
                                     ));
                }
                else if (entity.IsGroup())
                {
                    RhsGroup group = entity.AsGroup();

                    for (int i = 0; i < entity.Count; ++i)
                    {
                        foreach (SymbolMarked result in subSelectors[i].buildConfiguration(group.ObjName, enabled &&
                                                                                           (i == indexCounter.Value || modeCounter.Value == RhsEntitySelector.SelectionEnum.All)))
                        {
                            yield return(result);
                        }
                    }
                }
                else
                {
                    throw new NotImplementedException();
                }
            }
 internal SymbolMarked(RhsSymbol symbol, bool isEnabled)
 {
     this.Symbol    = symbol;
     this.IsEnabled = isEnabled;
 }
Пример #3
0
        private AltRule createSeed(SymbolPosition position,
                                   List <Production> productions,
                                   bool doubled,  // should we double the seed right at the start
                                   string lhsSymbolName,
                                   IEnumerable <string> elementTypeNames,
                                   params RhsSymbol[] symbols)
        {
            RhsSymbol[] init_symbols = symbols.Where(it => !it.SkipInitially).ToArray();

            var main_code = new CodeBody().AddWithIdentifier(CodeWords.New, " ");

            main_code.Append(makeTupleListCode(position, elementTypeNames));
            main_code.AddSnippet("(");

            IEnumerable <CodeBody> code_lists
                = elementTypeNames.Select(it => new CodeBody().AddWithIdentifier(CodeWords.New, " ", CodeWords.List, "<", it, ">{")).ToList();

            // purpose: to handle names in doubled seed mode
            Dictionary <RhsSymbol, string[]> obj_name_substs = new Dictionary <RhsSymbol, string[]>();

            {
                IEnumerable <RhsSymbol> named_symbols = symbols.Where(it => it.ObjName != null);

                if (named_symbols.Any())
                {
                    foreach (Tuple <RhsSymbol, CodeBody> tuple in named_symbols.SyncZip(code_lists))
                    {
                        RhsSymbol nsymbol    = tuple.Item1;
                        CodeBody  lcode      = tuple.Item2;
                        bool      double_sym = doubled && !nsymbol.SkipInitially;

                        string[] name_subst = new string[double_sym ? 2 : 1];
                        obj_name_substs.Add(nsymbol, name_subst);

                        // if we double the element, we have to come up with new names
                        if (double_sym)
                        {
                            name_subst[0] = AutoNames.Double1 + nsymbol.ObjName + "__";
                            name_subst[1] = AutoNames.Double2 + nsymbol.ObjName + "__";
                        }
                        else
                        {
                            name_subst[0] = nsymbol.ObjName;
                        }

                        for (int i = 0; i < (double_sym ? 2 : 1); ++i)
                        {
                            if (i == 1)
                            {
                                lcode.AddSnippet(",");
                            }

                            if (double_sym)
                            {
                                lcode.AddIdentifier(name_subst[i]);
                            }
                            else
                            {
                                lcode.AddIdentifier(nsymbol.ObjName);
                            }
                        }
                    }
                }
            }

            foreach (Tuple <CodeBody, int> code_pair in code_lists.ZipWithIndex())
            {
                code_pair.Item1.AddSnippet("}");

                if (code_pair.Item2 > 0)
                {
                    main_code.AddSnippet(",");
                }
                main_code.Append(code_pair.Item1);
            }

            main_code.AddSnippet(")");

            // in case of doubled seed we have to rename the symbols
            // otherwise just make shallow copies without renaming
            // but since we already set proxy name correctly, we can use shared code for both cases
            var seed_symbols = new LinkedList <RhsSymbol>();

            for (int i = 0; i < (doubled ? 2 : 1); ++i)
            {
                foreach (RhsSymbol sym in (i == 0 ? init_symbols : symbols))
                {
                    if (sym.ObjName == null)
                    {
                        seed_symbols.AddLast(sym.ShallowClone());
                    }
                    else
                    {
                        int s_idx = (i == 1 && sym.SkipInitially) ? 0 : i;
                        seed_symbols.AddLast(sym.Renamed(obj_name_substs[sym][s_idx]));
                    }
                }
            }


            return(AltRule.CreateInternally(position,
                                            // are there any symbols for production
                                            seed_symbols.Any()
                ? new RhsGroup[] { RhsGroup.CreateSequence(position, RepetitionEnum.Once, seed_symbols.Select(it => it.SetSkip(false)).ToArray()) }
                : new RhsGroup[] { },
                                            new CodeMix(CodeMix.SeedComment).AddBody(main_code)));
        }