/** * Searches for matching token patterns at the start of the * input stream. If a match is found, the token match object * is updated. * * @param buffer the input buffer to check * @param match the token match to update * * @throws IOException if an I/O error occurred */ public override void Match(ReaderBuffer buffer, TokenMatch match) { TokenPattern res = automaton.Match(buffer, ignoreCase); if (res != null) { match.Update(res.Pattern.Length, res); } }
/** * Searches for matching token patterns at the start of the * input stream. If a match is found, the token match object * is updated. * * @param buffer the input buffer to check * @param match the token match to update * * @throws IOException if an I/O error occurred */ public override void Match(ReaderBuffer buffer, TokenMatch match) { for (int i = 0; i < regExps.Length; i++) { int length = regExps[i].Match(buffer); if (length > 0) { match.Update(length, patterns[i]); } } }
/// <summary> /// Checks if this NFA matches the specified input text. The /// matching will be performed from position zero (0) in the /// buffer. This method will not read any characters from the /// stream, just peek ahead. /// </summary> /// <param name="buffer">The input buffer to check</param> /// <param name="match">The token match to update</param> /// <returns>The number of characters matched</returns> /// <exception cref="System.IO.IOException"> /// If an I/O error occurred /// </exception> public int Match(ReaderBuffer buffer, TokenMatch match) { int length = 0; int pos = 1; int peekChar; NFAState state; // The first step of the match loop has been unrolled and // optimized for performance below. this.queue.Clear(); peekChar = buffer.Peek(0); if (peekChar >= 0 && peekChar < 128) { state = this.initialChar[peekChar]; if (state != null) { this.queue.AddLast(state); } } if (peekChar >= 0) { this.initial.MatchTransitions((char)peekChar, this.queue, true); } this.queue.MarkEnd(); peekChar = buffer.Peek(1); // The remaining match loop processes all subsequent states while (!this.queue.Empty) { if (this.queue.Marked) { pos++; peekChar = buffer.Peek(pos); this.queue.MarkEnd(); } state = this.queue.RemoveFirst(); if (state.Value != null) { match.Update(pos, state.Value); } if (peekChar >= 0) { state.MatchTransitions((char)peekChar, this.queue, false); } } return(length); }
/** * Checks if this NFA matches the specified input text. The * matching will be performed from position zero (0) in the * buffer. This method will not read any characters from the * stream, just peek ahead. * * @param buffer the input buffer to check * @param match the token match to update * * @return the number of characters matched, or * zero (0) if no match was found * * @throws IOException if an I/O error occurred */ public int Match(ReaderBuffer buffer, TokenMatch match) { int length = 0; int pos = 1; int peekChar; NFAState state; // The first step of the match loop has been unrolled and // optimized for performance below. this.queue.Clear(); peekChar = buffer.Peek(0); if (0 <= peekChar && peekChar < 128) { state = this.initialChar[peekChar]; if (state != null) { this.queue.AddLast(state); } } if (peekChar >= 0) { this.initial.MatchTransitions((char) peekChar, this.queue, true); } this.queue.MarkEnd(); peekChar = buffer.Peek(1); // The remaining match loop processes all subsequent states while (!this.queue.Empty) { if (this.queue.Marked) { pos++; peekChar = buffer.Peek(pos); this.queue.MarkEnd(); } state = this.queue.RemoveFirst(); if (state.value != null) { match.Update(pos, state.value); } if (peekChar >= 0) { state.MatchTransitions((char) peekChar, this.queue, false); } } return length; }