예제 #1
0
        //*
        // * Returns a description of the token pattern with the
        // * specified id.
        // *
        // * @param id the token pattern id
        // *
        // * @return the token pattern description, or
        // * null if not present
        //

        public string GetPatternDescription(int id)
        {
            TokenPattern       pattern = default(TokenPattern);
            RegExpTokenMatcher re      = default(RegExpTokenMatcher);

            pattern = stringMatcher.GetPattern(id);
            if (pattern != null)
            {
                return(pattern.ToShortString());
            }
            for (int i = 0; i <= regexpMatchers.Count - 1; i++)
            {
                re = (RegExpTokenMatcher)regexpMatchers[i];
                if (re.GetPattern().Id == id)
                {
                    return(re.GetPattern().ToShortString());
                }
            }
            return(null);
        }
예제 #2
0
        //*
        // * Finds the longest token match from the current buffer
        // * position. This method will return the token matcher for the
        // * best match, or null if no match was found. As a side
        // * effect, this method will also set the end of buffer flag.
        // *
        // * @return the token mathcher with the longest match, or
        // * null if no match was found
        // *
        // * @throws IOException if an I/O error occurred
        //

        private TokenMatcher FindMatch()
        {
            TokenMatcher       bestMatch  = null;
            int                bestLength = 0;
            RegExpTokenMatcher re         = default(RegExpTokenMatcher);

            // Check string matches
            if (stringMatcher.Match(input))
            {
                bestMatch  = stringMatcher;
                bestLength = bestMatch.GetMatchedLength();
            }
            for (int i = 0; i <= regexpMatchers.Count - 1; i++)
            {
                // Check regular expression matches
                re = (RegExpTokenMatcher)regexpMatchers[i];
                if (re.Match() && re.GetMatchedLength() > bestLength)
                {
                    bestMatch  = re;
                    bestLength = re.GetMatchedLength();
                }
            }
            return(bestMatch);
        }