コード例 #1
0
        public DisjunctiveExamplesSpec WitnessRegexPair(GrammarRule rule, DisjunctiveExamplesSpec spec)
        {
            var result = new Dictionary <State, IEnumerable <object> >();

            foreach (KeyValuePair <State, IEnumerable <object> > example in spec.DisjunctiveExamples)
            {
                State inputState = example.Key;
                var   input      = inputState[rule.Body[0]] as string;

                var regexes = new List <Regex2>();
                foreach (int output in example.Value)
                {
                    List <Regex>[] leftMatches, rightMatches;
                    BuildStringMatches(input, out leftMatches, out rightMatches);


                    List <Regex> leftRegex  = leftMatches[output];
                    List <Regex> rightRegex = rightMatches[output];
                    if (leftRegex.Count == 0 || rightRegex.Count == 0)
                    {
                        return(null);
                    }
                    regexes.AddRange(from l in leftRegex
                                     from r in rightRegex
                                     select Regex2.Create(l, r));
                }
                if (regexes.Count == 0)
                {
                    return(null);
                }
                result[inputState] = regexes;
            }
            return(DisjunctiveExamplesSpec.From(result));
        }
コード例 #2
0
        public static int?RelPos(string v, Regex2 rr)
        {
            Regex           left         = rr.Item1;
            Regex           right        = rr.Item2;
            MatchCollection rightMatches = right.Matches(v);
            MatchCollection leftMatches  = left.Matches(v);

            foreach (Match leftMatch in leftMatches)
            {
                foreach (Match rightMatch in rightMatches)
                {
                    if (rightMatch.Index == leftMatch.Index + leftMatch.Length)
                    {
                        return(leftMatch.Index + leftMatch.Length);
                    }
                }
            }
            return(null);
        }
コード例 #3
0
 public static double RR(Regex2 tuple)
 {
     return(1);
 }