예제 #1
0
 internal static Automaton MakeFractionDigits(int i)
 {
     return
         (Automaton.Minimize(
              new RegExp("[ \t\n\r]*[-+]?[0-9]+(\\.[0-9]{0," + i + "}0*)?[ \t\n\r]*")
              .ToAutomaton()));
 }
예제 #2
0
 internal static Automaton MakeTotalDigits(int i)
 {
     return
         (Automaton.Minimize(
              new RegExp("[ \t\n\r]*[-+]?0*([0-9]{0," + i + "}|((([0-9]\\.*){0," + i + "})&@\\.@)0*)[ \t\n\r]*")
              .ToAutomaton()));
 }
예제 #3
0
        internal static Automaton MakeMinInteger(String n)
        {
            int i = 0;

            while (i + 1 < n.Length && n[i] == '0')
            {
                i++;
            }

            var b = new StringBuilder();

            b.Append("0*");
            MinInteger(n.Substring(i), 0, b);
            b.Append("[0-9]*");
            return(Automaton.Minimize((new RegExp(b.ToString())).ToAutomaton()));
        }
예제 #4
0
        internal static Automaton MakeMaxInteger(String n)
        {
            int i = 0;

            while (i < n.Length && n[i] == '0')
            {
                i++;
            }

            var b = new StringBuilder();

            b.Append("0*(0|");
            if (i < n.Length)
            {
                b.Append("[0-9]{1," + (n.Length - i - 1) + "}|");
            }

            MaxInteger(n.Substring(i), 0, b);
            b.Append(")");
            return(Automaton.Minimize((new RegExp(b.ToString())).ToAutomaton()));
        }
예제 #5
0
        private Automaton ToAutomaton(
            IDictionary <string, Automaton> automata,
            IAutomatonProvider automatonProvider,
            bool minimize)
        {
            IList <Automaton> list;
            Automaton         a = null;

            switch (kind)
            {
            case Kind.RegexpUnion:
                list = new List <Automaton>();
                this.FindLeaves(exp1, Kind.RegexpUnion, list, automata, automatonProvider, minimize);
                this.FindLeaves(exp2, Kind.RegexpUnion, list, automata, automatonProvider, minimize);
                a = BasicOperations.Union(list);
                a.Minimize();
                break;

            case Kind.RegexpConcatenation:
                list = new List <Automaton>();
                this.FindLeaves(exp1, Kind.RegexpConcatenation, list, automata, automatonProvider, minimize);
                this.FindLeaves(exp2, Kind.RegexpConcatenation, list, automata, automatonProvider, minimize);
                a = BasicOperations.Concatenate(list);
                a.Minimize();
                break;

            case Kind.RegexpIntersection:
                a = exp1.ToAutomaton(automata, automatonProvider, minimize)
                    .Intersection(exp2.ToAutomaton(automata, automatonProvider, minimize));
                a.Minimize();
                break;

            case Kind.RegexpOptional:
                a = exp1.ToAutomaton(automata, automatonProvider, minimize).Optional();
                a.Minimize();
                break;

            case Kind.RegexpRepeat:
                a = exp1.ToAutomaton(automata, automatonProvider, minimize).Repeat();
                a.Minimize();
                break;

            case Kind.RegexpRepeatMin:
                a = exp1.ToAutomaton(automata, automatonProvider, minimize).Repeat(min);
                a.Minimize();
                break;

            case Kind.RegexpRepeatMinMax:
                a = exp1.ToAutomaton(automata, automatonProvider, minimize).Repeat(min, max);
                a.Minimize();
                break;

            case Kind.RegexpComplement:
                a = exp1.ToAutomaton(automata, automatonProvider, minimize).Complement();
                a.Minimize();
                break;

            case Kind.RegexpChar:
                a = BasicAutomata.MakeChar(c);
                break;

            case Kind.RegexpCharRange:
                a = BasicAutomata.MakeCharRange(from, to);
                break;

            case Kind.RegexpAnyChar:
                a = BasicAutomata.MakeAnyChar();
                break;

            case Kind.RegexpEmpty:
                a = BasicAutomata.MakeEmpty();
                break;

            case Kind.RegexpString:
                a = BasicAutomata.MakeString(s);
                break;

            case Kind.RegexpAnyString:
                a = BasicAutomata.MakeAnyString();
                break;

            case Kind.RegexpAutomaton:
                Automaton aa = null;
                if (automata != null)
                {
                    automata.TryGetValue(s, out aa);
                }

                if (aa == null && automatonProvider != null)
                {
                    try
                    {
                        aa = automatonProvider.GetAutomaton(s);
                    }
                    catch (IOException e)
                    {
                        throw new ArgumentException(string.Empty, e);
                    }
                }

                if (aa == null)
                {
                    throw new ArgumentException("'" + s + "' not found");
                }

                a = aa.Clone();     // Always clone here (ignore allowMutate).
                break;

            case Kind.RegexpInterval:
                a = BasicAutomata.MakeInterval(min, max, digits);
                break;
            }

            return(a);
        }
예제 #6
0
 internal static Automaton Minimize(Automaton a)
 {
     a.Minimize();
     return(a);
 }
예제 #7
0
 internal static Automaton Minimize(Automaton a)
 {
     a.Minimize();
     return a;
 }