Class CommonToken

    • Constructor Detail

      • CommonToken

        public CommonToken​(int type)
        Constructs a new CommonToken with the specified token type.
        Parameters:
        type - The token type.
      • CommonToken

        public CommonToken​(Pair<TokenSource,​CharStream> source,
                           int type,
                           int channel,
                           int start,
                           int stop)
      • CommonToken

        public CommonToken​(int type,
                           String text)
        Constructs a new CommonToken with the specified token type and text.
        Parameters:
        type - The token type.
        text - The text of the token.
    • Method Detail

      • getType

        public int getType()
        Description copied from interface: Token
        Get the token type of the token
        Specified by:
        getType in interface Token
      • getText

        public String getText()
        Description copied from interface: Token
        Get the text of the token.
        Specified by:
        getText in interface Token
      • setText

        public void setText​(String text)
        Explicitly set the text for this token. If {code text} is not null, then getText() will return this value rather than extracting the text from the input.
        Specified by:
        setText in interface WritableToken
        Parameters:
        text - The explicit text of the token, or null if the text should be obtained from the input along with the start and stop indexes of the token.
      • getLine

        public int getLine()
        Description copied from interface: Token
        The line number on which the 1st character of this token was matched, line=1..n
        Specified by:
        getLine in interface Token
      • getCharPositionInLine

        public int getCharPositionInLine()
        Description copied from interface: Token
        The index of the first character of this token relative to the beginning of the line at which it occurs, 0..n-1
        Specified by:
        getCharPositionInLine in interface Token
      • getChannel

        public int getChannel()
        Description copied from interface: Token
        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.
        Specified by:
        getChannel in interface Token
      • getStartIndex

        public int getStartIndex()
        Description copied from interface: Token
        The starting character index of the token This method is optional; return -1 if not implemented.
        Specified by:
        getStartIndex in interface Token
      • setStartIndex

        public void setStartIndex​(int start)
      • getStopIndex

        public int getStopIndex()
        Description copied from interface: Token
        The last character index of the token. This method is optional; return -1 if not implemented.
        Specified by:
        getStopIndex in interface Token
      • setStopIndex

        public void setStopIndex​(int stop)
      • getTokenIndex

        public int getTokenIndex()
        Description copied from interface: Token
        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.
        Specified by:
        getTokenIndex in interface Token