Beispiel #1
0
 /// <summary>
 /// Constructs a regex to symbolic finite automata converter
 /// </summary>
 /// <param name="solver">solver for character constraints</param>
 /// <param name="categorizer">maps unicode categories to corresponding character conditions</param>
 internal RegexToAutomatonConverter(ICharAlgebra <S> solver, IUnicodeCategoryTheory <S> categorizer)
 {
     this.solver      = solver;
     this.categorizer = categorizer;
     description.Add(solver.True, "");
     description.Add(solver.False, "[]");
     this.automBuilder = new RegexToAutomatonBuilder <RegexNode, S>(solver, ConvertNode);
     //this.converterHelper.Callback = (node, start, end) => ConvertNode(node, start, end);
 }
Beispiel #2
0
 /// <summary>
 /// Constructs a regex to symbolic finite automata converter
 /// </summary>
 /// <param name="solver">solver for character constraints</param>
 public RegexToAutomatonConverter(ICharAlgebra <S> solver)
 {
     this.solver      = solver;
     this.categorizer = new UnicodeCategoryTheory <S>(solver);
     description.Add(solver.True, "");
     description.Add(solver.False, "[]");
     this.automBuilder = new RegexToAutomatonBuilder <RegexNode, S>(solver, ConvertNode);
     //this.converterHelper.Callback = ConvertNode;
 }
Beispiel #3
0
        //public SymbolicRegexBuilder<S> SRBuilder
        //{
        //    get
        //    {
        //        return srBuilder;
        //    }
        //}

        /// <summary>
        /// Constructs a regex to symbolic finite automata converter
        /// </summary>
        /// <param name="solver">solver for character constraints</param>
        /// <param name="categorizer">maps unicode categories to corresponding character conditions</param>
        internal RegexToAutomatonConverter(ICharAlgebra <S> solver, IUnicodeCategoryTheory <S> categorizer = null)
        {
            this.solver      = solver;
            this.categorizer = (categorizer == null ? new UnicodeCategoryTheory <S>(solver) : categorizer);
            description.Add(solver.True, ".");
            //"[]" does not unfortunately parse as a valid regex
            //description.Add(solver.False, "[0-[0]]");
            description.Add(solver.False, "[]");
            this.automBuilder = new RegexToAutomatonBuilder <RegexNode, S>(solver, ConvertNode);
            this.srBuilder    = new SymbolicRegexBuilder <S>((ICharAlgebra <S>)solver);
            //this.converterHelper.Callback = (node, start, end) => ConvertNode(node, start, end);
        }
Beispiel #4
0
        internal static string ToRegexCharSet(BDD label, IUnicodeCategoryTheory <BDD> categorizer, CharSetSolver solver)
        {
            if (categorizer.CategoryCondition(8) == label)
            {
                return(@"\d");
            }
            if (solver.MkNot(categorizer.CategoryCondition(8)) == label)
            {
                return(@"\D");
            }
            if (categorizer.WordLetterCondition == label)
            {
                return(@"\w");
            }
            if (solver.MkNot(categorizer.WordLetterCondition) == label)
            {
                return(@"\W");
            }
            if (categorizer.WhiteSpaceCondition == label)
            {
                return(@"\s");
            }
            if (solver.MkNot(categorizer.WhiteSpaceCondition) == label)
            {
                return(@"\S");
            }
            for (int i = 0; i < categorizer.UnicodeCategoryStandardAbbreviations.Length; i++)
            {
                if (categorizer.CategoryCondition(i) == label)
                {
                    return(@"\P{" + categorizer.UnicodeCategoryStandardAbbreviations[i] + "}");
                }
            }

            var ranges = solver.ToRanges(label);

            if (ranges.Length == 1 && ranges[0].Item1 == ranges[0].Item2)
            {
                return(StringUtility.Escape((char)ranges[0].Item1));
            }

            var res = new StringBuilder("[");

            for (int i = 0; i < ranges.Length; i++)
            {
                var range = ranges[i];
                if (range.Item1 == range.Item2)
                {
                    res.Append(StringUtility.EscapeWithNumericSpace((char)range.Item1));
                }
                else if (range.Item1 == range.Item2 - 1)
                {
                    res.Append(StringUtility.EscapeWithNumericSpace((char)range.Item1));
                    res.Append(StringUtility.EscapeWithNumericSpace((char)range.Item2));
                }
                else
                {
                    res.Append(StringUtility.EscapeWithNumericSpace((char)range.Item1));
                    res.Append("-");
                    res.Append(StringUtility.EscapeWithNumericSpace((char)range.Item2));
                }
            }
            res.Append("]");
            return(res.ToString());
        }
Beispiel #5
0
        //public SymbolicRegexBuilder<S> SRBuilder
        //{
        //    get
        //    {
        //        return srBuilder;
        //    }
        //}

        /// <summary>
        /// Constructs a regex to symbolic finite automata converter
        /// </summary>
        /// <param name="solver">solver for character constraints</param>
        /// <param name="categorizer">maps unicode categories to corresponding character conditions</param>
        public RegexToAutomatonConverter(ICharAlgebra <S> solver, IUnicodeCategoryTheory <S> categorizer = null)
        {
            this.solver      = solver;
            this.categorizer = (categorizer == null ? new UnicodeCategoryTheory <S>(solver) : categorizer);
            this.srBuilder   = new SymbolicRegexBuilder <S>((ICharAlgebra <S>)solver);
        }