Module: ANTLR3::TokenFactory
- Included in:
- AST::TreeAdaptor, Recognizer, TokenScheme
- Defined in:
- lib/antlr3/token.rb
Overview
There are a variety of different entities throughout the ANTLR runtime library that need to create token objects This module serves as a mixin that provides methods for constructing tokens.
Including this module provides a token_class
attribute. Instance of the including class can create tokens using the token class (which defaults to ANTLR3::CommonToken). Token classes are presumed to have an #initialize method that can be called without any parameters and the token objects are expected to have the standard token attributes (see ANTLR3::Token).
Instance Attribute Summary collapse
Instance Method Summary collapse
Instance Attribute Details
#token_class ⇒ Object
353 354 355 356 357 358 359 |
# File 'lib/antlr3/token.rb', line 353 def token_class @token_class ||= begin self.class.token_class rescue self::Token rescue ANTLR3::CommonToken end end |
Instance Method Details
#create_token(*args) ⇒ Object
361 362 363 364 365 366 367 368 369 |
# File 'lib/antlr3/token.rb', line 361 def create_token( *args ) if block_given? token_class.new( *args ) do |*targs| yield( *targs ) end else token_class.new( *args ) end end |