Class RuleTagToken

java.lang.Object
org.antlr.v4.runtime.tree.pattern.RuleTagToken
All Implemented Interfaces:
Token

public class RuleTagToken extends Object implements Token
A Token object representing an entire subtree matched by a parser rule; e.g., <expr>. These tokens are created for TagChunk chunks where the tag corresponds to a parser rule.
  • Field Details

    • ruleName

      private final String ruleName
      This is the backing field for getRuleName().
    • bypassTokenType

      private final int bypassTokenType
      The token type for the current token. This is the token type assigned to the bypass alternative for the rule during ATN deserialization.
    • label

      private final String label
      This is the backing field for getLabel().
  • Constructor Details

    • RuleTagToken

      public RuleTagToken(String ruleName, int bypassTokenType)
      Constructs a new instance of RuleTagToken with the specified rule name and bypass token type and no label.
      Parameters:
      ruleName - The name of the parser rule this rule tag matches.
      bypassTokenType - The bypass token type assigned to the parser rule.
      Throws:
      IllegalArgumentException - if ruleName is null or empty.
    • RuleTagToken

      public RuleTagToken(String ruleName, int bypassTokenType, String label)
      Constructs a new instance of RuleTagToken with the specified rule name, bypass token type, and label.
      Parameters:
      ruleName - The name of the parser rule this rule tag matches.
      bypassTokenType - The bypass token type assigned to the parser rule.
      label - The label associated with the rule tag, or null if the rule tag is unlabeled.
      Throws:
      IllegalArgumentException - if ruleName is null or empty.
  • Method Details

    • getRuleName

      public final String getRuleName()
      Gets the name of the rule associated with this rule tag.
      Returns:
      The name of the parser rule associated with this rule tag.
    • getLabel

      public final String getLabel()
      Gets the label associated with the rule tag.
      Returns:
      The name of the label associated with the rule tag, or null if this is an unlabeled rule tag.
    • getChannel

      public int getChannel()
      Return the channel this token. Each token can arrive at the parser on a different channel, but the parser only "tunes" to a single channel. The parser ignores everything not on DEFAULT_CHANNEL.

      Rule tag tokens are always placed on the Token.DEFAULT_CHANNEL.

      Specified by:
      getChannel in interface Token
    • getText

      public String getText()
      Get the text of the token.

      This method returns the rule tag formatted with < and > delimiters.

      Specified by:
      getText in interface Token
    • getType

      public int getType()
      Get the token type of the token

      Rule tag tokens have types assigned according to the rule bypass transitions created during ATN deserialization.

      Specified by:
      getType in interface Token
    • getLine

      public int getLine()
      The line number on which the 1st character of this token was matched, line=1..n

      The implementation for RuleTagToken always returns 0.

      Specified by:
      getLine in interface Token
    • getCharPositionInLine

      public int getCharPositionInLine()
      The index of the first character of this token relative to the beginning of the line at which it occurs, 0..n-1

      The implementation for RuleTagToken always returns -1.

      Specified by:
      getCharPositionInLine in interface Token
    • getTokenIndex

      public int getTokenIndex()
      An index from 0..n-1 of the token object in the input stream. This must be valid in order to print token streams and use TokenRewriteStream. Return -1 to indicate that this token was conjured up since it doesn't have a valid index.

      The implementation for RuleTagToken always returns -1.

      Specified by:
      getTokenIndex in interface Token
    • getStartIndex

      public int getStartIndex()
      The starting character index of the token This method is optional; return -1 if not implemented.

      The implementation for RuleTagToken always returns -1.

      Specified by:
      getStartIndex in interface Token
    • getStopIndex

      public int getStopIndex()
      The last character index of the token. This method is optional; return -1 if not implemented.

      The implementation for RuleTagToken always returns -1.

      Specified by:
      getStopIndex in interface Token
    • getTokenSource

      public TokenSource getTokenSource()
      Gets the TokenSource which created this token.

      The implementation for RuleTagToken always returns null.

      Specified by:
      getTokenSource in interface Token
    • getInputStream

      public CharStream getInputStream()
      Gets the CharStream from which this token was derived.

      The implementation for RuleTagToken always returns null.

      Specified by:
      getInputStream in interface Token
    • toString

      public String toString()

      The implementation for RuleTagToken returns a string of the form ruleName:bypassTokenType.

      Overrides:
      toString in class Object