Class TagChunk

java.lang.Object
org.antlr.v4.runtime.tree.pattern.Chunk
org.antlr.v4.runtime.tree.pattern.TagChunk

class TagChunk extends Chunk
Represents a placeholder tag in a tree pattern. A tag can have any of the following forms.
  • expr: An unlabeled placeholder for a parser rule expr.
  • ID: An unlabeled placeholder for a token of type ID.
  • e:expr: A labeled placeholder for a parser rule expr.
  • id:ID: A labeled placeholder for a token of type ID.
This class does not perform any validation on the tag or label names aside from ensuring that the tag is a non-null, non-empty string.
  • Field Details

  • Constructor Details

    • TagChunk

      public TagChunk(String tag)
      Construct a new instance of TagChunk using the specified tag and no label.
      Parameters:
      tag - The tag, which should be the name of a parser rule or token type.
      Throws:
      IllegalArgumentException - if tag is null or empty.
    • TagChunk

      public TagChunk(String label, String tag)
      Construct a new instance of TagChunk using the specified label and tag.
      Parameters:
      label - The label for the tag. If this is null, the TagChunk represents an unlabeled tag.
      tag - The tag, which should be the name of a parser rule or token type.
      Throws:
      IllegalArgumentException - if tag is null or empty.
  • Method Details

    • getTag

      public final String getTag()
      Get the tag for this chunk.
      Returns:
      The tag for the chunk.
    • getLabel

      public final String getLabel()
      Get the label, if any, assigned to this chunk.
      Returns:
      The label assigned to this chunk, or null if no label is assigned to the chunk.
    • toString

      public String toString()
      This method returns a text representation of the tag chunk. Labeled tags are returned in the form label:tag, and unlabeled tags are returned as just the tag name.
      Overrides:
      toString in class Object