Exemplo n.º 1
0
        private void AddActionEntry(Item item, Func <ActionParsingTableEntry, bool> action, string actionDescription, ItemSet set, TerminalExpressionDefinition expressionDefinition)
        {
            ParsingTableSegment segment = GetOrCreateSegment(set);

            ActionParsingTableEntry existingEntry = (ActionParsingTableEntry)segment.Entries.FirstOrDefault(x =>
                                                                                                            x is ActionParsingTableEntry apte &&
                                                                                                            apte.ActionDescription == actionDescription &&
                                                                                                            apte.ExpressionDefinition.IsEqualTo(expressionDefinition));

            if (existingEntry == null)
            {
                segment.Entries.Add(new ActionParsingTableEntry
                {
                    ItemSet = set,
                    ExpressionDefinition = expressionDefinition,
                    Items = new List <Item> {
                        item
                    },
                    ActionDescription = actionDescription,
                    Action            = action
                });
            }
            else
            {
                existingEntry.Items.Add(item);
            }
        }
Exemplo n.º 2
0
        private ParsingTableSegment GetOrCreateSegment(ItemSet set)
        {
            if (Segments.TryGetValue(set.Id, out ParsingTableSegment existingSegment))
            {
                return(existingSegment);
            }

            ParsingTableSegment segment = new ParsingTableSegment
            {
                Set = set
            };

            Segments.Add(set.Id, segment);

            return(segment);
        }