Class Match<E>

  • Type Parameters:
    E -
    Direct Known Subclasses:
    Match.FinalMatch, Match.IntermediateMatch

    public abstract class Match<E>
    extends java.lang.Object
    A class to represent a match. Each part of the regular expression is matched to a sequence of tokens. A match also stores information about the range of tokens matched and the matching groups in the match.
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      protected static class  Match.FinalMatch<E>
      A match representation that has efficient method calls but is immutable.
      static class  Match.Group<E>
      A captured group in a matched expression.
      protected static class  Match.IntermediateMatch<E>
      A match representation that is mutable but many method calls compute values instead of returning stored values.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected java.util.List<Match.Group<E>> pairs  
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      protected Match()  
      protected Match​(Match<E> match)  
    • Constructor Detail

      • Match

        protected Match()
      • Match

        protected Match​(Match<E> match)
    • Method Detail

      • addAll

        public boolean addAll​(java.util.Collection<Match.Group<E>> pairs)
      • add

        public boolean add​(Expression<E> expr,
                           E token,
                           int pos)
        Convenience method for add(new Group(expr, token, pos)).
        Parameters:
        expr -
        token -
        pos -
        Returns:
      • isEmpty

        public boolean isEmpty()
        True iff this match contains no pairs. This should only happen on an IntermediateMatch that has not had any pairs added to it yet.
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • toMultilineString

        public java.lang.String toMultilineString()
      • startIndex

        public abstract int startIndex()
        Returns:
        the index of the first token matched (inclusive start).
      • endIndex

        public abstract int endIndex()
        Returns:
        the index one past of the last token matched (exclusive end).
      • pairs

        public java.util.List<Match.Group<E>> pairs()
        Pairs differ from the matching groups in that each regular expression element has a pair to associate the element with the text matched. For example, 'a*' might be associated with 'a a a a'.
        Returns:
        all pairs in this match.
      • groups

        public abstract java.util.List<Match.Group<E>> groups()
        Returns:
        all matching groups (named and unnamed).
      • tokens

        public abstract java.util.List<E> tokens()
        Returns:
        all matched tokens.
      • length

        public int length()
        Returns:
        the number of tokens in the match.
      • group

        public Match.Group<E> group​(java.lang.String name)
        Retrieve a group by name.
        Parameters:
        name - the name of the group to retrieve.
        Returns:
        the associated group.