Class: Antlr4::Runtime::LexerActionExecutor

Inherits:
Object
  • Object
show all
Defined in:
lib/antlr4/runtime/lexer_action_executor.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(lexer_actions) ⇒ LexerActionExecutor

Returns a new instance of LexerActionExecutor



7
8
9
10
# File 'lib/antlr4/runtime/lexer_action_executor.rb', line 7

def initialize(lexer_actions)
  @lexer_actions = lexer_actions
  @hash_code = MurmurHash.hash_objs(lexer_actions)
end

Instance Attribute Details

#hash_codeObject (readonly)

Returns the value of attribute hash_code



5
6
7
# File 'lib/antlr4/runtime/lexer_action_executor.rb', line 5

def hash_code
  @hash_code
end

#lexer_actionsObject (readonly)

Returns the value of attribute lexer_actions



4
5
6
# File 'lib/antlr4/runtime/lexer_action_executor.rb', line 4

def lexer_actions
  @lexer_actions
end

Class Method Details

.append(lexer_action_executor, lexer_action) ⇒ Object



12
13
14
15
16
17
18
# File 'lib/antlr4/runtime/lexer_action_executor.rb', line 12

def self.append(lexer_action_executor, lexer_action)
  return LexerActionExecutor.new([lexer_action]) if lexer_action_executor.nil?

  lexer_actions = lexer_action_executor.lexer_actions.dup
  lexer_actions << lexer_action
  LexerActionExecutor.new(lexer_actions)
end

Instance Method Details

#eql?(obj) ⇒ Boolean

Returns:

  • (Boolean)


63
64
65
66
67
68
69
70
71
# File 'lib/antlr4/runtime/lexer_action_executor.rb', line 63

def eql?(obj)
  if obj == self
    return true
  else
    return false unless obj.is_a? LexerActionExecutor
  end

  @hash_code == obj.hash_code && (@lexer_actions == obj._a)
end

#execute(lexer, input, start_index) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/antlr4/runtime/lexer_action_executor.rb', line 37

def execute(lexer, input, start_index)
  requires_seek = false
  stop_index = input.index
  begin
    i = 0
    while i < @lexer_actions.length
      lexerAction = @lexer_actions[i]
      if lexerAction.is_a? LexerIndexedCustomAction
        offset = lexerAction.getOffset
        input.seek(start_index + offset)
        requires_seek = ((start_index + offset) != stop_index)
      else
        if lexerAction.position_dependent?
          input.seek(stop_index)
          requires_seek = false
        end

        lexerAction.execute(lexer)
      end
      i += 1
    end
  ensure
    input.seek(stop_index) if requires_seek
  end
end

#fix_offset_before_match(offset) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/antlr4/runtime/lexer_action_executor.rb', line 20

def fix_offset_before_match(offset)
  updated_lexer_actions = nil
  i = 0
  while i < @lexer_actions.length
    if @lexer_actions[i].position_dependent? && !(@lexer_actions[i].is_a? LexerIndexedCustomAction)
      updated_lexer_actions = @lexer_actions.dup if updated_lexer_actions.nil?

      updated_lexer_actions[i] = LexerIndexedCustomAction.new(offset, @lexer_actions[i])
    end
    i += 1
  end

  return self if updated_lexer_actions.nil?

  LexerActionExecutor.new(updated_lexer_actions)
end