Esempio n. 1
0
        static RegExpDfa Power1Unlimited(RegExpDfa operand)
        {
            RegExpDfa dfa = new RegExpDfa(operand);

            dfa._finalState.AddTransition(new EmptyTransition(dfa._initialState));
            return(dfa);
        }
Esempio n. 2
0
        static RegExpDfa HardOr(RegExpDfa one, RegExpDfa merged)
        {
            RegExpDfa dfa = new RegExpDfa(one);
            Dictionary <RegExpState, RegExpState> dictionary = new Dictionary <RegExpState, RegExpState>();

            foreach (RegExpState state in merged.GetAllStates())
            {
                RegExpState initialState;
                if (object.ReferenceEquals(merged._initialState, state))
                {
                    initialState = dfa._initialState;
                }
                else if (object.ReferenceEquals(merged._finalState, state))
                {
                    initialState = dfa._finalState;
                }
                else
                {
                    initialState = new RegExpState();
                }
                dictionary.Add(state, initialState);
            }
            foreach (RegExpState state3 in dictionary.Keys)
            {
                foreach (Transition transition in state3.Transitions)
                {
                    RegExpState state4 = dictionary[state3];
                    RegExpState target = dictionary[transition.Target];
                    state4.AddTransition(transition.Copy(target));
                }
            }
            return(dfa);
        }
Esempio n. 3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="operand"></param>
        /// <param name="minMatches"></param>
        /// <param name="maxMatches"></param>
        /// <returns></returns>
        public static RegExpDfa Power(RegExpDfa operand, int minMatches, int maxMatches)
        {
            RegExpDfa empty;

            if (object.ReferenceEquals(operand._initialState, operand._finalState))
            {
                return(operand);
            }
            if (maxMatches == -1)
            {
                if (minMatches == 0)
                {
                    empty = Power0Unlimited(operand);
                }
                else
                {
                    empty = PowerExact(operand, minMatches - 1) & Power1Unlimited(operand);
                }
            }
            else
            {
                empty = PowerExact(operand, minMatches) & PowerOptional(operand, maxMatches - minMatches);
            }
            if (empty == null)
            {
                empty = Empty;
            }
            return(empty);
        }
Esempio n. 4
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="regExp"></param>
 /// <param name="reverseDfa"></param>
 /// <param name="isAutoComplete"></param>
 /// <param name="isOptimistic"></param>
 /// <param name="showPlaceHolders"></param>
 /// <param name="anySymbolPlaceHolder"></param>
 /// <param name="managerCultureInfo"></param>
 public RegExpMaskManager(string regExp, bool reverseDfa, bool isAutoComplete, bool isOptimistic, bool showPlaceHolders, char anySymbolPlaceHolder, CultureInfo managerCultureInfo)
     : base(RegExpMaskManagerState.Empty)
 {
     _logic                = new RegExpMaskLogic(RegExpDfa.Parse(regExp, reverseDfa, managerCultureInfo), isAutoComplete);
     _isOptimistic         = isOptimistic;
     _showPlaceHolders     = showPlaceHolders;
     _anySymbolPlaceHolder = anySymbolPlaceHolder;
     _reverseDfa           = reverseDfa;
 }
Esempio n. 5
0
 static RegExpDfa Power0Unlimited(RegExpDfa operand)
 {
     if (operand.CanReturnFromFinalState())
     {
         operand = HardAnd(operand, EmptyTransitionDfa);
     }
     if (operand.CanReturnToInitialState())
     {
         operand = HardAnd(EmptyTransitionDfa, operand);
     }
     return(HardOr(Empty, operand));
 }
Esempio n. 6
0
        static RegExpDfa PowerOptional(RegExpDfa operand, int count)
        {
            if (count == 0)
            {
                return(null);
            }
            RegExpDfa head = new RegExpDfa(operand);

            if (head.CanReturnFromFinalState())
            {
                head = HardAnd(head, EmptyTransitionDfa);
            }
            if (head.CanReturnToInitialState())
            {
                head = HardAnd(EmptyTransitionDfa, head);
            }
            RegExpDfa dfa2 = new RegExpDfa(operand) | EmptyTransitionDfa;

            for (int i = 1; i < count; i++)
            {
                Dictionary <RegExpState, RegExpState> dictionary = new Dictionary <RegExpState, RegExpState>();
                foreach (RegExpState state in head.GetAllStates())
                {
                    RegExpState initialState;
                    if (object.ReferenceEquals(state, head._finalState))
                    {
                        initialState = dfa2._initialState;
                    }
                    else
                    {
                        initialState = new RegExpState();
                    }
                    dictionary.Add(state, initialState);
                }
                dfa2._initialState = dictionary[head._initialState];
                foreach (RegExpState state3 in dictionary.Keys)
                {
                    foreach (Transition transition in state3.Transitions)
                    {
                        RegExpState state4 = dictionary[state3];
                        RegExpState target = dictionary[transition.Target];
                        state4.AddTransition(transition.Copy(target));
                    }
                }
                dfa2._initialState.AddTransition(new EmptyTransition(dfa2._finalState));
            }
            return(dfa2);
        }
Esempio n. 7
0
        RegExpDfa(RegExpDfa source)
        {
            this._statesCache          = new Dictionary <RegExpDfaWave, RegExpDfaWave>();
            this._stringsToStatesCache = new RegExpStringKeyTable();
            Dictionary <RegExpState, RegExpState> dictionary = new Dictionary <RegExpState, RegExpState>();

            foreach (RegExpState state in source.GetAllStates())
            {
                dictionary.Add(state, new RegExpState());
            }
            this._initialState = dictionary[source._initialState];
            this._finalState   = dictionary[source._finalState];
            foreach (RegExpState state2 in dictionary.Keys)
            {
                foreach (Transition transition in state2.Transitions)
                {
                    Transition transition2 = transition.Copy(dictionary[transition.Target]);
                    dictionary[state2].AddTransition(transition2);
                }
            }
        }
Esempio n. 8
0
        static RegExpDfa HardAnd(RegExpDfa head, RegExpDfa tail)
        {
            RegExpDfa dfa = new RegExpDfa(head);
            Dictionary <RegExpState, RegExpState> dictionary = new Dictionary <RegExpState, RegExpState>();

            foreach (RegExpState state in tail.GetAllStates())
            {
                RegExpState state2 = object.ReferenceEquals(tail._initialState, state) ? dfa._finalState : new RegExpState();
                dictionary.Add(state, state2);
            }
            dfa._finalState = dictionary[tail._finalState];
            foreach (RegExpState state3 in dictionary.Keys)
            {
                foreach (Transition transition in state3.Transitions)
                {
                    RegExpState state4 = dictionary[state3];
                    RegExpState target = dictionary[transition.Target];
                    state4.AddTransition(transition.Copy(target));
                }
            }
            return(dfa);
        }
Esempio n. 9
0
        static RegExpDfa PowerExact(RegExpDfa operand, int power)
        {
            if (power == 0)
            {
                return(null);
            }
            if (power < 0)
            {
                throw new ArgumentException("Incorrect power", "power");
            }
            if (power == 1)
            {
                return(operand);
            }
            int       num = power / 2;
            RegExpDfa dfa = PowerExact(operand, num);

            dfa &= dfa;
            if ((num + num) != power)
            {
                dfa &= operand;
            }
            return(dfa);
        }
Esempio n. 10
0
        object yyparse(IYyInput yyLex)
        {
            int num5;

            if (this._yyMax <= 0)
            {
                this._yyMax = 0x100;
            }
            int index = 0;

            int[]  numArray = new int[this._yyMax];
            object obj2     = null;

            object[] objArray = new object[this._yyMax];
            int      num2     = -1;
            int      num3     = 0;
            int      num4     = 0;

            goto Label_0041;
Label_003B:
            num4++;
Label_0041:
            if (num4 >= numArray.Length)
            {
                int[] array = new int[numArray.Length + this._yyMax];
                numArray.CopyTo(array, 0);
                numArray = array;
                object[] objArray2 = new object[objArray.Length + this._yyMax];
                objArray.CopyTo(objArray2, 0);
                objArray = objArray2;
            }
            numArray[num4] = index;
            objArray[num4] = obj2;
Label_008C:
            if ((num5 = yyDefRed[index]) == 0)
            {
                if (num2 < 0)
                {
                    num2 = yyLex.advance() ? yyLex.token() : 0;
                }
                if ((((num5 = yySindex[index]) != 0) && ((num5 += num2) >= 0)) && ((num5 < yyTable.Length) && (yyCheck[num5] == num2)))
                {
                    index = yyTable[num5];
                    obj2  = yyLex.value();
                    num2  = -1;
                    if (num3 > 0)
                    {
                        num3--;
                    }
                    goto Label_003B;
                }
                if ((((num5 = yyRindex[index]) != 0) && ((num5 += num2) >= 0)) && ((num5 < yyTable.Length) && (yyCheck[num5] == num2)))
                {
                    num5 = yyTable[num5];
                }
                else
                {
                    switch (num3)
                    {
                    case 0:
                        this.yyerror("syntax error");
                        goto Label_016F;

                    case 1:
                    case 2:
                        goto Label_016F;

                    case 3:
                        if (num2 == 0)
                        {
                            this.yyerror("irrecoverable syntax error at end-of-file");
                        }
                        num2 = -1;
                        goto Label_008C;
                    }
                }
            }
            int num6 = (num4 + 1) - yyLen[num5];

            obj2 = (num6 > num4) ? null : objArray[num6];
            switch (num5)
            {
            case 1:
                this._result = (RegExpDfa)objArray[-1 + num4];
                goto Label_05F4;

            case 2:
                this._result = RegExpDfa.Empty;
                goto Label_05F4;

            case 3:
                obj2 = objArray[num4];
                goto Label_05F4;

            case 4:
                obj2 = ((RegExpDfa)objArray[-2 + num4]) | ((RegExpDfa)objArray[num4]);
                goto Label_05F4;

            case 5:
                obj2 = objArray[num4];
                goto Label_05F4;

            case 6:
                if (this._reverseAutomate)
                {
                    obj2 = ((RegExpDfa)objArray[num4]) & ((RegExpDfa)objArray[-1 + num4]);
                }
                else
                {
                    obj2 = ((RegExpDfa)objArray[-1 + num4]) & ((RegExpDfa)objArray[num4]);
                }
                goto Label_05F4;

            case 7:
                obj2 = objArray[num4];
                goto Label_05F4;

            case 8:
                obj2 = objArray[-1 + num4];
                goto Label_05F4;

            case 9:
                obj2 = RegExpDfa.Power((RegExpDfa)objArray[-1 + num4], ((RegExpDupSymbol)objArray[num4])._MinMatches, ((RegExpDupSymbol)objArray[num4])._MaxMatches);
                goto Label_05F4;

            case 10:
                obj2 = new RegExpDfa(new OneSymbolTransition((char)objArray[num4]));
                goto Label_05F4;

            case 11:
                obj2 = new RegExpDfa(new AnySymbolTransition());
                goto Label_05F4;

            case 12:
                obj2 = new RegExpDfa((Transition)objArray[num4]);
                goto Label_05F4;

            case 13:
                obj2 = new RegExpDfa(new DecimalDigitTransition(false));
                goto Label_05F4;

            case 14:
                obj2 = new RegExpDfa(new DecimalDigitTransition(true));
                goto Label_05F4;

            case 15:
                obj2 = new RegExpDfa(new WhiteSpaceTransition(false));
                goto Label_05F4;

            case 0x10:
                obj2 = new RegExpDfa(new WhiteSpaceTransition(true));
                goto Label_05F4;

            case 0x11:
                obj2 = new RegExpDfa(new WordTransition(false));
                goto Label_05F4;

            case 0x12:
                obj2 = new RegExpDfa(new WordTransition(true));
                goto Label_05F4;

            case 0x13:
                obj2 = new RegExpDfa(new UnicodeCategoryTransition((string)objArray[num4], false));
                goto Label_05F4;

            case 20:
                obj2 = new RegExpDfa(new UnicodeCategoryTransition((string)objArray[num4], true));
                goto Label_05F4;

            case 0x15:
                obj2 = new RegExpDupSymbol(0, -1);
                goto Label_05F4;

            case 0x16:
                obj2 = new RegExpDupSymbol(1, -1);
                goto Label_05F4;

            case 0x17:
                obj2 = new RegExpDupSymbol(0, 1);
                goto Label_05F4;

            case 0x18:
                obj2 = new RegExpDupSymbol(objArray[-1 + num4], objArray[-1 + num4]);
                goto Label_05F4;

            case 0x19:
                obj2 = new RegExpDupSymbol(objArray[-2 + num4], -1);
                goto Label_05F4;

            case 0x1a:
                obj2 = new RegExpDupSymbol(objArray[-3 + num4], objArray[-1 + num4]);
                goto Label_05F4;

            case 0x1b:
                obj2 = new BracketTransition(false, ((List <RegExpBracketTransitionRange>)objArray[-1 + num4]).ToArray());
                goto Label_05F4;

            case 0x1c:
                obj2 = new BracketTransition(true, ((List <RegExpBracketTransitionRange>)objArray[-1 + num4]).ToArray());
                goto Label_05F4;

            case 0x1d:
            {
                List <RegExpBracketTransitionRange> list = new List <RegExpBracketTransitionRange>();
                list.Add((RegExpBracketTransitionRange)objArray[num4]);
                obj2 = list;
                goto Label_05F4;
            }

            case 30:
                obj2 = objArray[-1 + num4];
                ((List <RegExpBracketTransitionRange>)obj2).Add((RegExpBracketTransitionRange)objArray[num4]);
                goto Label_05F4;

            case 0x1f:
                obj2 = new RegExpBracketTransitionRange((char)objArray[num4], (char)objArray[num4]);
                goto Label_05F4;

            case 0x20:
                obj2 = new RegExpBracketTransitionRange((char)objArray[-2 + num4], (char)objArray[num4]);
                goto Label_05F4;

            case 0x21:
                obj2 = objArray[num4];
                goto Label_05F4;

            case 0x22:
                obj2 = objArray[num4];
                goto Label_05F4;

            case 0x23:
                obj2 = ((char)objArray[num4]) - '0';
                goto Label_05F4;

            case 0x24:
                obj2 = ((((int)objArray[-1 + num4]) * 10) + ((char)objArray[num4])) - 0x30;
                goto Label_05F4;

            default:
                goto Label_05F4;
            }
Label_016F:
            num3 = 3;
            do
            {
                if ((((num5 = yySindex[numArray[num4]]) != 0) && ((num5 += 0x100) >= 0)) && ((num5 < yyTable.Length) && (yyCheck[num5] == 0x100)))
                {
                    index = yyTable[num5];
                    obj2  = yyLex.value();
                    goto Label_003B;
                }
            }while (--num4 >= 0);
            this.yyerror("irrecoverable syntax error");
            goto Label_008C;
Label_05F4:
            num4 -= yyLen[num5];
            index = numArray[num4];
            int num7 = yyLhs[num5];

            if ((index == 0) && (num7 == 0))
            {
                index = yyFinal;
                if (num2 < 0)
                {
                    num2 = yyLex.advance() ? yyLex.token() : 0;
                }
                if (num2 == 0)
                {
                    return(obj2);
                }
            }
            else if ((((num5 = yyGindex[num7]) != 0) && ((num5 += index) >= 0)) && ((num5 < yyTable.Length) && (yyCheck[num5] == index)))
            {
                index = yyTable[num5];
            }
            else
            {
                index = yyDgoto[num7];
            }
            goto Label_003B;
        }
Esempio n. 11
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="regExp"></param>
 /// <param name="culture"></param>
 /// <param name="isAutoComplete"></param>
 public RegExpMaskLogic(string regExp, CultureInfo culture, bool isAutoComplete) : this(RegExpDfa.Parse(regExp, culture), isAutoComplete)
 {
 }
Esempio n. 12
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="regExp"></param>
 /// <param name="isAutoComplete"></param>
 public RegExpMaskLogic(RegExpDfa regExp, bool isAutoComplete)
 {
     this._IsAutoComplete = true;
     this._regExp         = regExp;
     this._IsAutoComplete = isAutoComplete;
 }