private NFAState ParseAtomModifier(NFAState start, NFAState end) { int min = 0; int max = -1; int firstPos = _pos; // Read min and max switch (ReadChar()) { case '?': min = 0; max = 1; break; case '*': min = 0; max = -1; break; case '+': min = 1; max = -1; break; case '{': min = ReadNumber(); max = min; if (PeekChar(0) == ',') { ReadChar(','); max = -1; if (PeekChar(0) != '}') { max = ReadNumber(); } } ReadChar('}'); if (max == 0 || (max > 0 && min > max)) { throw new RegExpException( RegExpException.ErrorType.INVALID_REPEAT_COUNT, firstPos, _pattern); } break; default: throw new RegExpException( RegExpException.ErrorType.UNEXPECTED_CHARACTER, _pos - 1, _pattern); } // Read possessive or reluctant modifiers if (PeekChar(0) == '?') { throw new RegExpException( RegExpException.ErrorType.UNSUPPORTED_SPECIAL_CHARACTER, _pos, _pattern); } else if (PeekChar(0) == '+') { throw new RegExpException( RegExpException.ErrorType.UNSUPPORTED_SPECIAL_CHARACTER, _pos, _pattern); } // Handle supported repeaters if (min == 0 && max == 1) { return(start.AddOut(new NFAEpsilonTransition(end))); } else if (min == 0 && max == -1) { if (end.Outgoing.Length == 0) { end.MergeInto(start); } else { end.AddOut(new NFAEpsilonTransition(start)); } return(start); } else if (min == 1 && max == -1) { if (start.Outgoing.Length == 1 && end.Outgoing.Length == 0 && end.Incoming.Length == 1 && start.Outgoing[0] == end.Incoming[0]) { end.AddOut(start.Outgoing[0].Copy(end)); } else { end.AddOut(new NFAEpsilonTransition(start)); } return(end); } else { throw new RegExpException( RegExpException.ErrorType.INVALID_REPEAT_COUNT, firstPos, _pattern); } }
public NFANonWordTransition(NFAState state) : base(state) { }
public override NFATransition Copy(NFAState state) { return(new NFANonWordTransition(state)); }
public override NFATransition Copy(NFAState state) { return(new NFAWhitespaceTransition(state)); }
public NFANonWhitespaceTransition(NFAState state) : base(state) { }
public override NFATransition Copy(NFAState state) { return(new NFADigitTransition(state)); }
public NFANonDigitTransition(NFAState state) : base(state) { }
public override NFATransition Copy(NFAState state) { return(new NFACharTransition(_match, state)); }
public NFADotTransition(NFAState state) : base(state) { }
public NFACharTransition(char match, NFAState state) : base(state) { _match = match; }
public override NFATransition Copy(NFAState state) { return(new NFAEpsilonTransition(state)); }
public NFAEpsilonTransition(NFAState state) : base(state) { }
public abstract NFATransition Copy(NFAState state);
protected NFATransition(NFAState state) { this.State = state; this.State.AddIn(this); }