Class: Antlr4ruby::CommonTokenFactory

Inherits:
Object
  • Object
show all
Defined in:
lib/antlr4ruby/common_token_factory.rb

Constant Summary collapse

DEFAULT =
CommonTokenFactory.new

Instance Method Summary collapse

Constructor Details

#initialize(copy_text = false) ⇒ CommonTokenFactory

Returns a new instance of CommonTokenFactory.



9
10
11
# File 'lib/antlr4ruby/common_token_factory.rb', line 9

def initialize(copy_text = false)
  @copy_text = copy_text
end

Instance Method Details

#create(type:, text:, source: nil, channel: nil, start: nil, stop: nil, line: nil, position: nil) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/antlr4ruby/common_token_factory.rb', line 19

def create(type:, text:, source: nil,
           channel: nil, start: nil, stop: nil, line: nil, position: nil)
  if channel and source and start and stop and line and position
    t = CommonToken.new(type: type, source: source, channel: channel, start: start, stop: stop)
    t.set_line(line)
    t.set_char_position_in_line(position)
    if text
      t.set_text(text)
    elsif copy_text && source.second
      t.set_text(source.second.get_text(start..stop))
    end
    t
  else
    CommonToken.new(type: type, text: text)
  end
end