Esempio n. 1
0
 public ENFA_Regex_Match(ENFA_Regex_Transition transition, bool consumesChar)
 {
     _transition   = transition;
     _consumesChar = consumesChar;
 }
Esempio n. 2
0
        private void AddCharacterGroup(ENFA_Regex_Transition activeTransition, StreamReader reader)
        {
            bool exit = false;

            if (PeekNextChar(reader) == Constants.RightSquareBracket)
            {
                ThrowBuildException(ErrorText.CharacterClassEmpty);
            }
            while (!exit)
            {
                char?nextChar     = NextCharInStream(reader);
                char?tempNextChar = PeekNextChar(reader);
                if (!nextChar.HasValue)
                {
                    exit = true;
                }
                else
                {
                    if (nextChar.Value == Constants.RightSquareBracket)
                    {
                        exit = true;
                    }
                    else if (nextChar.Value == Constants.Backslash)
                    {
                        if (tempNextChar.Value == 'n')
                        {
                            ConsumeNextChar(reader);// Consume New Line
                            activeTransition.AddLiteral(Constants.NewLine);
                        }
                        else if (tempNextChar.Value == 'v')
                        {
                            ConsumeNextChar(reader);// Consume Vertical Tab
                            activeTransition.AddLiteral(Constants.VerticalTab);
                        }
                        else if (tempNextChar.Value == 't')
                        {
                            ConsumeNextChar(reader);// Consume Horizontal Tab
                            activeTransition.AddLiteral(Constants.HorizontalTab);
                        }
                        else if (tempNextChar.Value == Constants.Backslash)
                        {
                            ConsumeNextChar(reader);// Consume Backslash
                            activeTransition.AddLiteral(Constants.Backslash);
                        }
                        else if (tempNextChar.Value == 'f')
                        {
                            ConsumeNextChar(reader);// Consume Form Feed
                            activeTransition.AddLiteral(Constants.FormFeed);
                        }
                        else if (tempNextChar.Value == 'r')
                        {
                            ConsumeNextChar(reader);// Consume Carriage Return
                            activeTransition.AddLiteral(Constants.CarriageReturn);
                        }
                        else if (tempNextChar.Value == '0')
                        {
                            ConsumeNextChar(reader);// Consume Null Char
                            activeTransition.AddLiteral(Constants.NullChar);
                        }
                        else if (tempNextChar.Value == 'a')
                        {
                            ConsumeNextChar(reader);// Consume Alert
                            activeTransition.AddLiteral(Constants.Alert);
                        }
                        else if (tempNextChar.Value == 'e')
                        {
                            ConsumeNextChar(reader);// Consume Escape
                            activeTransition.AddLiteral(Constants.Escape);
                        }
                        else if (tempNextChar.Value == 'y')
                        {
                            ConsumeNextChar(reader);// Consume Backspace
                            activeTransition.AddLiteral(Constants.Backspace);
                        }
                        else
                        {
                            ThrowBuildException(ErrorText.CharacterClassEscapedWithoutBeingExpectedTo);
                        }
                    }
                    else
                    {
                        if (tempNextChar.HasValue && tempNextChar.Value == Constants.HyphenMinusSign)
                        {
                            /* Char range */
                            ConsumeNextChar(reader);// Consume Hyphen Minus Sign
                            char?endRange = NextCharInStream(reader);
                            if (!endRange.HasValue)
                            {
                                ThrowBuildException(ErrorText.CharacterRangeHasNoEndValue);
                            }
                            int lowCounter  = (int)nextChar.Value;
                            int highCounter = (int)endRange.Value;
                            if (lowCounter > highCounter)
                            {
                                int temp = lowCounter;
                                lowCounter  = highCounter;
                                highCounter = temp;
                            }
                            for (int counter = lowCounter; counter <= highCounter; counter += 1)
                            {
                                activeTransition.AddLiteral((char)counter);
                            }
                        }
                        else
                        {
                            activeTransition.AddLiteral(nextChar.Value);
                        }
                    }
                }
            }
        }