public void DigitTerminalGetIntervalsShouldReturnSingleIntervalWithZeroToNineRange() { var digitTerminal = new DigitTerminal(); var intervals = digitTerminal.GetIntervals(); Assert.AreEqual(1, intervals.Count); Assert.AreEqual('0', intervals[0].Min); Assert.AreEqual('9', intervals[0].Max); }
static SimpleExpressionGrammar() { var digit = new DigitTerminal(); ProductionExpression E = "E"; E.Rule = E + "+" + E | E + "*" + E | digit; _innerGrammar = new GrammarExpression(E, new[] { E }).ToGrammar(); }
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)); }
public void DigitTerminalGivenNumberShouldMatch() { var digitTerminal = new DigitTerminal(); Assert.IsTrue(digitTerminal.IsMatch('0')); }
public void DigitTerminalGivenLetterShouldFailMatch() { var digitTerminal = new DigitTerminal(); Assert.IsFalse(digitTerminal.IsMatch('a')); }