Ejemplo n.º 1
0
        public void WordTerminalShouldMatchWordCharacters()
        {
            var wordTerminal = new WordTerminal();

            Assert.IsTrue(wordTerminal.IsMatch('a'));
            Assert.IsTrue(wordTerminal.IsMatch('0'));
            Assert.IsTrue(wordTerminal.IsMatch('M'));
            Assert.IsTrue(wordTerminal.IsMatch('_'));
        }
Ejemplo n.º 2
0
        private static ITerminal CreateTerminalForCharacter(char value, bool isEscaped, bool negate)
        {
            ITerminal terminal = null;

            if (!isEscaped)
            {
                terminal = new CharacterTerminal(value);
            }
            else
            {
                switch (value)
                {
                case 's':
                    terminal = new WhitespaceTerminal();
                    break;

                case 'd':
                    terminal = new DigitTerminal();
                    break;

                case 'w':
                    terminal = new WordTerminal();
                    break;

                case 'D':
                    terminal = new DigitTerminal();
                    negate   = !negate;
                    break;

                case 'S':
                    terminal = new WhitespaceTerminal();
                    negate   = !negate;
                    break;

                case 'W':
                    terminal = new WordTerminal();
                    negate   = !negate;
                    break;

                default:
                    terminal = new CharacterTerminal(value);
                    break;
                }
            }

            if (negate)
            {
                terminal = new NegationTerminal(terminal);
            }
            return(terminal);
        }
        private static INfa Character(RegexCharacterClassCharacter character, bool negate)
        {
            var start = new NfaState();
            var end   = new NfaState();

            ITerminal terminal = null;

            if (!character.IsEscaped)
            {
                terminal = new CharacterTerminal(character.Value);
            }
            else
            {
                switch (character.Value)
                {
                case 's':
                    terminal = new WhitespaceTerminal();
                    break;

                case 'd':
                    terminal = new DigitTerminal();
                    break;

                case 'w':
                    terminal = new WordTerminal();
                    break;

                case 'D':
                    terminal = new DigitTerminal();
                    negate   = !negate;
                    break;

                case 'S':
                    terminal = new WhitespaceTerminal();
                    negate   = !negate;
                    break;

                case 'W':
                    terminal = new WordTerminal();
                    negate   = !negate;
                    break;

                default:
                    terminal = new CharacterTerminal(character.Value);
                    break;
                }
            }

            if (negate)
            {
                terminal = new NegationTerminal(terminal);
            }

            var transition = new TerminalNfaTransition(
                terminal: terminal,
                target: end);

            start.AddTransistion(transition);

            return(new Nfa(start, end));
        }