コード例 #1
0
        //*
        // * 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()
        {
            TokenMatcher m      = default(TokenMatcher);
            string       str    = null;
            int          line   = 0;
            int          column = 0;

            try
            {
                m = FindMatch();
                if (m != null)
                {
                    line   = input.LineNumber;
                    column = input.ColumnNumber;
                    str    = input.ReadString(m.GetMatchedLength());
                    return(new Token(m.GetMatchedPattern(), str, line, column));
                }
                else if (input.Peek() < 0)
                {
                    return(null);
                }
                else
                {
                    line   = input.LineNumber;
                    column = input.ColumnNumber;
                    throw new ParseException(ParseException.ErrorType.UNEXPECTED_CHAR, input.ReadString(1), line, column);
                }
            }
            catch (IOException e)
            {
                throw new ParseException(ParseException.ErrorType.IO, e.Message, -1, -1);
            }
        }