コード例 #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);
            }
        }
コード例 #2
0
        //*
        // * Returns the length of a matching string starting at the
        // * specified position. The number of matches to skip can also
        // * be specified, but numbers higher than zero (0) cause a
        // * failed match for any element that doesn't attempt to
        // * combine other elements.
        // *
        // * @param m the matcher being used
        // * @param input the input character stream to match
        // * @param start the starting position
        // * @param skip the number of matches to skip
        // *
        // * @return the length of the longest matching string, or
        // * -1 if no match was found
        // *
        // * @throws IOException if an I/O error occurred
        //

        public override int Match(Matcher m, LookAheadReader input, int start, int skip)
        {
            int c = 0;

            if (skip != 0)
            {
                return(-1);
            }
            for (int i = 0; i <= value.Length - 1; i++)
            {
                c = input.Peek(start + i);
                if (c < 0)
                {
                    m.SetReadEndOfString();
                    return(-1);
                }
                if (m.IsCaseInsensitive())
                {
                    c = Convert.ToInt32(Char.ToLower(Convert.ToChar(c)));
                }
                if (c != Convert.ToInt32(value[i]))
                {
                    return(-1);
                }
            }
            return(value.Length);
        }
コード例 #3
0
        //*
        // * Checks if the automaton matches an input stream. The
        // * matching will be performed from a specified position. This
        // * method will not read any characters from the stream, just
        // * peek ahead. The comparison can be done either in
        // * case-sensitive or case-insensitive mode.
        // *
        // * @param input the input stream to check
        // * @param pos the starting position
        // * @param caseInsensitive the case-insensitive flag
        // *
        // * @return the match value, or
        // * null if no match was found
        // *
        // * @throws IOException if an I/O error occurred
        //

        public object MatchFrom(LookAheadReader input, int pos, bool caseInsensitive)
        {
            object    result = null;
            Automaton state  = default(Automaton);
            int       c      = 0;

            c = input.Peek(pos);
            if (tree != null && c >= 0)
            {
                state = tree.Find(Convert.ToChar(c), caseInsensitive);
                if (state != null)
                {
                    result = state.MatchFrom(input, pos + 1, caseInsensitive);
                }
            }
            return((result == null) ? value : result);
        }
コード例 #4
0
        //*
        // * Returns the length of a matching string starting at the
        // * specified position. The number of matches to skip can also be
        // * specified, but numbers higher than zero (0) cause a failed
        // * match for any element that doesn't attempt to combine other
        // * elements.
        // *
        // * @param m the matcher being used
        // * @param input the input character stream to match
        // * @param start the starting position
        // * @param skip the number of matches to skip
        // *
        // * @return the length of the matching string, or
        // * -1 if no match was found
        // *
        // * @throws IOException if an I/O error occurred
        //

        public override int Match(Matcher m, LookAheadReader input, int start, int skip)
        {
            int c = 0;

            if (skip != 0)
            {
                return(-1);
            }
            c = input.Peek(start);
            if (c < 0)
            {
                m.SetReadEndOfString();
                return(-1);
            }
            if (m.IsCaseInsensitive())
            {
                c = Convert.ToInt32(Char.ToLower(Convert.ToChar(c)));
            }
            return(InSet(Convert.ToChar(c)) ? 1 : -1);
        }