Class: TokenTagToken

Inherits:
CommonToken show all
Defined in:
lib/antlr4/tree/TokenTagToken.rb

Overview

A Token object representing a token of a particular type; e.g., <ID>. These tokens are created for TagChunk chunks where the tag corresponds to a lexer rule or token type.

Constant Summary

Constants inherited from CommonToken

CommonToken::EMPTY_SOURCE

Constants inherited from Token

Token::DEFAULT_CHANNEL, Token::EOF, Token::EPSILON, Token::HIDDEN_CHANNEL, Token::INVALID_TYPE, Token::MIN_USER_TOKEN_TYPE

Instance Attribute Summary collapse

Attributes inherited from Token

#channel, #column, #line, #source, #start, #stop, #text, #tokenIndex, #type

Instance Method Summary collapse

Methods inherited from CommonToken

#clone, #inspect, #text

Methods inherited from Token

#getInputStream, #getTokenSource

Constructor Details

#initialize(tokenName, type, label = nil) ⇒ TokenTagToken

Returns a new instance of TokenTagToken.



17
18
19
20
21
22
# File 'lib/antlr4/tree/TokenTagToken.rb', line 17

def initialize(tokenName, type, label=nil)
    super(type)
    self.tokenName = tokenName
    self.label = label
    @text = getText()
end

Instance Attribute Details

#labelObject

Constructs a new instance of TokenTagToken with the specified token name, type, and label.

the token tag is unlabeled.

Parameters:

  • tokenName

    The token name.

  • type

    The token type.

  • label

    The label associated with the token tag, or null if



16
17
18
# File 'lib/antlr4/tree/TokenTagToken.rb', line 16

def label
  @label
end

#tokenNameObject

Constructs a new instance of TokenTagToken with the specified token name, type, and label.

the token tag is unlabeled.

Parameters:

  • tokenName

    The token name.

  • type

    The token type.

  • label

    The label associated with the token tag, or null if



16
17
18
# File 'lib/antlr4/tree/TokenTagToken.rb', line 16

def tokenName
  @tokenName
end

Instance Method Details

#getTextObject

<p>The implementation for TokenTagToken returns the token tag formatted with < and > delimiters.</p>



25
26
27
28
29
30
31
# File 'lib/antlr4/tree/TokenTagToken.rb', line 25

def getText()
    if self.label.nil?
        return "<" + self.tokenName + ">"
    else
        return "<" + self.label + ":" + self.tokenName + ">"
    end
end

#to_sObject

<p>The implementation for TokenTagToken returns a string of the form tokenName:type.</p>



35
36
37
# File 'lib/antlr4/tree/TokenTagToken.rb', line 35

def to_s
    "#{self.tokenName}:#{self.class}" 
end