Ejemplo n.º 1
0
        public static Automaton MakeMinInteger(string n)
        {
            var i = 0;

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

            var sb = new StringBuilder();

            _ = sb.Append("0*");
            MinInteger(sb, n.Substring(i), 0);
            _ = sb.Append("[0-9]*");
            return(Automaton.Minimize(new RegExp(sb.ToString()).ToAutomaton()));
        }
Ejemplo n.º 2
0
        public static Automaton MakeMaxInteger(string n)
        {
            var i = 0;

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

            var sb = new StringBuilder();

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

            MaxInteger(sb, n.Substring(i), 0);
            _ = sb.Append(")");
            return(Automaton.Minimize(new RegExp(sb.ToString()).ToAutomaton()));
        }
Ejemplo n.º 3
0
        public static Automaton MakeIntegerValue(string value)
        {
            var minus = false;
            var i     = 0;

            while (i < value.Length)
            {
                var c = value[i];
                if (c == '-')
                {
                    minus = true;
                }

                if (c >= '1' && c <= '9')
                {
                    break;
                }

                i++;
            }

            var sb = new StringBuilder();

            _ = sb.Append(value, i, value.Length - i);
            if (sb.Length == 0)
            {
                _ = sb.Append("0");
            }

            var s = minus ? Automaton.MakeChar('-') : Automaton.MakeChar('+').Optional();

            return(Automaton.Minimize(
                       WhitespaceAutomaton.Concatenate(
                           s.Concatenate(Automaton.MakeChar('0').Repeat())
                           .Concatenate(Automaton.MakeString(sb.ToString())))
                       .Concatenate(WhitespaceAutomaton)));
        }
Ejemplo n.º 4
0
 public static Automaton MakeTotalDigits(int i) => Automaton.Minimize(
     new RegExp("[ \t\n\r]*[-+]?0*([0-9]{0," + i + "}|((([0-9]\\.*){0," + i + "})&@\\.@)0*)[ \t\n\r]*")
     .ToAutomaton());
Ejemplo n.º 5
0
 public static Automaton MakeFractionDigits(int i) => Automaton.Minimize(
     new RegExp("[ \t\n\r]*[-+]?[0-9]+(\\.[0-9]{0," + i + "}0*)?[ \t\n\r]*")
     .ToAutomaton());
Ejemplo n.º 6
0
        public static Automaton MakeDecimalValue(string value)
        {
            var minus = false;
            var i     = 0;

            while (i < value.Length)
            {
                var c = value[i];
                if (c == '-')
                {
                    minus = true;
                }

                if ((c >= '1' && c <= '9') || c == '.')
                {
                    break;
                }

                i++;
            }

            var sb1 = new StringBuilder();
            var sb2 = new StringBuilder();
            var p   = value.IndexOf('.', i);

            if (p == -1)
            {
                _ = sb1.Append(value, i, value.Length - i);
            }
            else
            {
                _ = sb1.Append(value, i, p - i);
                i = value.Length - 1;
                while (i > p)
                {
                    var c = value[i];
                    if (c >= '1' && c <= '9')
                    {
                        break;
                    }

                    i--;
                }

                _ = sb2.Append(value, p + 1, i + 1 - (p + 1));
            }

            if (sb1.Length == 0)
            {
                _ = sb1.Append("0");
            }

            var s = minus ? Automaton.MakeChar('-') : Automaton.MakeChar('+').Optional();
            var d = sb2.Length == 0
                ? Automaton.MakeChar('.').Concatenate(Automaton.MakeChar('0').Repeat(1)).Optional()
                : Automaton.MakeChar('.')
                    .Concatenate(Automaton.MakeString(sb2.ToString()))
                    .Concatenate(Automaton.MakeChar('0')
                                 .Repeat());

            return(Automaton.Minimize(WhitespaceAutomaton
                                      .Concatenate(s.Concatenate(Automaton.MakeChar('0').Repeat()).Concatenate(Automaton.MakeString(sb1.ToString())).Concatenate(d))
                                      .Concatenate(WhitespaceAutomaton)));
        }
Ejemplo n.º 7
0
 public static Automaton Minimize(Automaton a)
 {
     a.Minimize();
     return(a);
 }