private static INfa Character(RegexCharacter character) { var start = new NfaState(); var end = new NfaState(); var terminal = new CharacterTerminal(character.Value); var transition = new TerminalNfaTransition( terminal: terminal, target: end); start.AddTransistion(transition); return(new Nfa(start, end)); }
private static INfa Character(RegexCharacterClassCharacter character, bool negate) { var start = new NfaState(); var end = new NfaState(); var terminal = CreateTerminalForCharacter(character.Value, character.IsEscaped, negate); var transition = new TerminalNfaTransition( terminal: terminal, target: end); start.AddTransistion(transition); return(new Nfa(start, end)); }
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)); }