Class: ANTLR3::CommonToken
- Inherits:
-
Struct
- Object
- Struct
- ANTLR3::CommonToken
- Includes:
- Token
- Defined in:
- lib/antlr3/token.rb,
lib/antlr3/token.rb
Overview
The base class for the standard implementation of Token. It is implemented as a simple Struct as tokens are basically simple data structures binding together a bunch of different information and Structs are slightly faster than a standard Object with accessor methods implementation.
By default, ANTLR generated ruby code will provide a customized subclass of CommonToken to track token-type names efficiently for debugging, inspection, and general utility. Thus code generated for a standard combo lexer-parser grammar named XYZ will have a base module named XYZ and a customized CommonToken subclass named XYZ::Token.
Here is the token structure attribute list in order:
-
type
-
channel
-
text
-
input
-
start
-
stop
-
index
-
line
-
column
Constant Summary collapse
- DEFAULT_VALUES =
{ :channel => DEFAULT_CHANNEL, :index => -1, :line => 0, :column => -1 }.freeze
Constants included from Constants
ANTLR3::Constants::BUILT_IN_TOKEN_NAMES, ANTLR3::Constants::DEFAULT, ANTLR3::Constants::DOWN, ANTLR3::Constants::EOF, ANTLR3::Constants::EOF_TOKEN, ANTLR3::Constants::EOR_TOKEN_TYPE, ANTLR3::Constants::HIDDEN, ANTLR3::Constants::INVALID, ANTLR3::Constants::INVALID_NODE, ANTLR3::Constants::INVALID_TOKEN, ANTLR3::Constants::MEMO_RULE_FAILED, ANTLR3::Constants::MEMO_RULE_UNKNOWN, ANTLR3::Constants::MIN_TOKEN_TYPE, ANTLR3::Constants::SKIP_TOKEN, ANTLR3::Constants::UP
Instance Attribute Summary collapse
-
#channel ⇒ Object
Returns the value of attribute channel.
-
#column ⇒ Object
Returns the value of attribute column.
-
#index ⇒ Object
(also: #token_index)
Returns the value of attribute index.
-
#input ⇒ Object
(also: #input_stream)
Returns the value of attribute input.
-
#line ⇒ Object
Returns the value of attribute line.
-
#start ⇒ Object
Returns the value of attribute start.
-
#stop ⇒ Object
Returns the value of attribute stop.
-
#text ⇒ Object
Returns the value of attribute text.
-
#type ⇒ Object
Returns the value of attribute type.
Class Method Summary collapse
- .create(fields = {}) ⇒ Object
-
.from_token(token) ⇒ Object
allows you to make a copy of a token with a different class.
- .token_name(type) ⇒ Object
Instance Method Summary collapse
-
#initialize(type = nil, channel = DEFAULT_CHANNEL, text = nil, input = nil, start = nil, stop = nil, index = -1,, line = 0, column = -1 )) ⇒ CommonToken
constructor
A new instance of CommonToken.
Methods included from Token
#<=>, #=~, #concrete?, #hidden?, #hide!, #imaginary?, #initialize_copy, #inspect, #name, #pretty_print, #range, #source_name, #source_text, #to_i, #to_s
Constructor Details
#initialize(type = nil, channel = DEFAULT_CHANNEL, text = nil, input = nil, start = nil, stop = nil, index = -1,, line = 0, column = -1 )) ⇒ CommonToken
Returns a new instance of CommonToken.
270 271 272 273 274 275 276 277 |
# File 'lib/antlr3/token.rb', line 270 def initialize( type = nil, channel = DEFAULT_CHANNEL, text = nil, input = nil, start = nil, stop = nil, index = -1, line = 0, column = -1 ) super block_given? and yield( self ) self.text.nil? && self.start && self.stop and self.text = self.input.substring( self.start, self.stop ) end |
Instance Attribute Details
#channel ⇒ Object
Returns the value of attribute channel
213 214 215 |
# File 'lib/antlr3/token.rb', line 213 def channel @channel end |
#column ⇒ Object
Returns the value of attribute column
213 214 215 |
# File 'lib/antlr3/token.rb', line 213 def column @column end |
#index ⇒ Object Also known as: token_index
Returns the value of attribute index
213 214 215 |
# File 'lib/antlr3/token.rb', line 213 def index @index end |
#input ⇒ Object Also known as: input_stream
Returns the value of attribute input
213 214 215 |
# File 'lib/antlr3/token.rb', line 213 def input @input end |
#line ⇒ Object
Returns the value of attribute line
213 214 215 |
# File 'lib/antlr3/token.rb', line 213 def line @line end |
#start ⇒ Object
Returns the value of attribute start
213 214 215 |
# File 'lib/antlr3/token.rb', line 213 def start @start end |
#stop ⇒ Object
Returns the value of attribute stop
213 214 215 |
# File 'lib/antlr3/token.rb', line 213 def stop @stop end |
#text ⇒ Object
Returns the value of attribute text
213 214 215 |
# File 'lib/antlr3/token.rb', line 213 def text @text end |
#type ⇒ Object
Returns the value of attribute type
213 214 215 |
# File 'lib/antlr3/token.rb', line 213 def type @type end |
Class Method Details
.create(fields = {}) ⇒ Object
256 257 258 259 260 |
# File 'lib/antlr3/token.rb', line 256 def self.create( fields = {} ) fields = DEFAULT_VALUES.merge( fields ) args = members.map { |name| fields[ name.to_sym ] } new( *args ) end |
.from_token(token) ⇒ Object
allows you to make a copy of a token with a different class
263 264 265 266 267 268 |
# File 'lib/antlr3/token.rb', line 263 def self.from_token( token ) new( token.type, token.channel, token.text ? token.text.clone : nil, token.input, token.start, token.stop, -1, token.line, token.column ) end |
.token_name(type) ⇒ Object
252 253 254 |
# File 'lib/antlr3/token.rb', line 252 def self.token_name( type ) BUILT_IN_TOKEN_NAMES[ type ] end |