Ejemplo n.º 1
0
        public static DisjunctiveExamplesSpec WitnessRegexPair(GrammarRule rule,
                                                               DisjunctiveExamplesSpec spec)
        {
            var rrExamples = new Dictionary <State, IEnumerable <object> >();

            foreach (State input in spec.ProvidedInputs)
            {
                var v       = (StringRegion)input[rule.Body[0]];
                var regexes = new List <Tuple <RegularExpression, RegularExpression> >();
                foreach (uint pos in spec.DisjunctiveExamples[input])
                {
                    MultiValueDictionary <Token, TokenMatch> rightMatches;
                    if (!v.Cache.TryGetAllMatchesStartingAt(pos, out rightMatches))
                    {
                        continue;
                    }
                    MultiValueDictionary <Token, TokenMatch> leftMatches;
                    if (!v.Cache.TryGetAllMatchesEndingAt(pos, out leftMatches))
                    {
                        continue;
                    }
                    var leftRegexes =
                        leftMatches.Keys.Select(t => RegularExpression.Create(new[] { t }))
                        .Append(Epsilon);
                    var rightRegexes =
                        rightMatches.Keys.Select(t => RegularExpression.Create(new[] { t }))
                        .Append(Epsilon);
                    var regexPairs = from l in leftRegexes
                                     from r in rightRegexes
                                     select Tuple.Create(l, r);

                    regexes.AddRange(regexPairs);
                }
                rrExamples[input] = regexes;
            }
            return(DisjunctiveExamplesSpec.From(rrExamples));
        }