/** * 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(); stringDfaMatcher.Match(buffer, lastMatch); nfaMatcher.Match(buffer, lastMatch); regExpMatcher.Match(buffer, lastMatch); 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); } }