Exemple #1
0
        void SerializeAndPrintStats(RegexMatcher matcher, string info)
        {
            var t = System.Environment.TickCount;

            matcher.Serialize("test.soap", new SoapFormatter());
            t = System.Environment.TickCount - t;
            Console.WriteLine("{1} serializaton time={0}ms", t, info);
        }
Exemple #2
0
        void GenerateBatch(string file, string batch_name, bool simplify)
        {
            Regex[]          regexes   = Array.ConvertAll(File.ReadAllLines(file), x => new Regex(x, RegexOptions.Singleline));
            List <string>    regexes2  = new List <string>();
            HashSet <string> regexes2_ = new HashSet <string>();
            string           dir       = "../../../../Automata.Tests/Samples/";
            string           dir_batch = dir + batch_name;

            if (!Directory.Exists(dir_batch))
            {
                Directory.CreateDirectory(dir_batch);
            }

            //Predicate<SymbolicRegexNode<ulong>> isNonMonadic = node =>
            //{
            //    return (
            //      node.kind == SymbolicRegexKind.Loop &&
            //      node.left.kind != SymbolicRegexKind.Singleton &&
            //      !node.IsStar &&
            //      !node.IsMaybe &&
            //      !node.IsPlus);
            //};

            //Predicate<SymbolicRegexNode<ulong>> isCountingLoop = node =>
            //{
            //    return (node.kind == SymbolicRegexKind.Loop &&
            //    !node.IsStar &&
            //      !node.IsMaybe &&
            //      !node.IsPlus);
            //};

            //int nrOfCountingLoops = 0;

            for (int i = 0; i < regexes.Length; i++)
            {
                var          regex = regexes[i];
                RegexMatcher m     = null;
                string       reasonwhynot;
                if (regex.IsCompileSupported(out reasonwhynot))
                {
                    m = regex.Compile(true, false);
                    //if (m.Pattern.ExistsNode(isCountingLoop))
                    {
                        //nrOfCountingLoops += 1;
                        //bool monadic = !m.Pattern.ExistsNode(isNonMonadic);
                        //if (monadic)
                        {
                            var s = new FileStream(dir_batch + "/r" + (regexes2.Count).ToString() + ".soap", FileMode.Create);
                            if (simplify)
                            {
                                m.SerializeSimplified(s, new SoapFormatter());
                            }
                            else
                            {
                                m.Serialize(s, new SoapFormatter());
                            }
                            s.Close();
                            var s2 = new FileStream(dir_batch + "/r" + (regexes2.Count).ToString() + ".soap", FileMode.Open);
                            var m2 = (SymbolicRegexUInt64) new SoapFormatter().Deserialize(s2);
                            s2.Close();
                            //var aut = m2.Pattern.Explore();
                            var r2 = m2.Pattern.ToString();
                            if (regexes2_.Add(r2))
                            {
                                regexes2.Add(r2);
                            }
                        }
                    }
                }
            }
            File.WriteAllLines(dir + batch_name + ".txt", regexes2.ToArray());
        }