/** * 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; }
/** * 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) { automaton.Match(buffer, match); }
/** * 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]); } } }
/** * 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 abstract void Match(ReaderBuffer buffer, TokenMatch match);
/** * Finds the next token on the stream. This method will return * null when end of file has been reached. It will return a * parse exception if no token matched the input stream. * * @return the next token found, or * null if end of file was encountered * * @throws ParseException if the input stream couldn't be read or * parsed correctly */ private Token NextToken() { string str; int line; int column; try { lastMatch.Clear(); var stringMatch = new TokenMatch(); stringDfaMatcher.Match(buffer, stringMatch); if (stringMatch.Length > 0) lastMatch = stringMatch; var nfaMatch = new TokenMatch(); nfaMatcher.Match(buffer, nfaMatch); if (nfaMatch.Length > lastMatch.Length) lastMatch = nfaMatch; var regExpMatch = new TokenMatch(); regExpMatcher.Match(buffer, regExpMatch); if (regExpMatch.Length > lastMatch.Length) lastMatch = regExpMatch; if (lastMatch.Length > 0) { line = buffer.LineNumber; column = buffer.ColumnNumber; str = buffer.Read(lastMatch.Length); return NewToken(lastMatch.Pattern, str, line, column); } else if (buffer.Peek(0) < 0) { return null; } else { line = buffer.LineNumber; column = buffer.ColumnNumber; throw new ParseException( ParseException.ErrorType.UNEXPECTED_CHAR, buffer.Read(1), line, column); } } catch (IOException e) { throw new ParseException(ParseException.ErrorType.IO, e.Message, -1, -1); } }