Class: Antlr4ruby::LexerActionExecutor
- Inherits:
-
Object
- Object
- Antlr4ruby::LexerActionExecutor
- Defined in:
- lib/antlr4ruby/atn/action/lexer_action_executor.rb
Class Method Summary collapse
Instance Method Summary collapse
- #eql?(other) ⇒ Boolean
- #execute(lexer, input, start_index) ⇒ Object
- #fix_offset_before_match(offset) ⇒ Object
- #get_lexer_actions ⇒ Object
- #hash ⇒ Object
-
#initialize(lexer_actions) ⇒ LexerActionExecutor
constructor
A new instance of LexerActionExecutor.
Constructor Details
#initialize(lexer_actions) ⇒ LexerActionExecutor
Returns a new instance of LexerActionExecutor.
5 6 7 8 9 10 11 12 13 14 |
# File 'lib/antlr4ruby/atn/action/lexer_action_executor.rb', line 5 def initialize(lexer_actions) @lexer_actions = lexer_actions hash = MurmurHash.init lexer_actions.each do |action| hash = MurmurHash.update(hash, action) end @hash_code = MurmurHash.finish(hash, lexer_actions.length) end |
Class Method Details
.append(lexer_executor, lexer_action) ⇒ Object
16 17 18 19 20 21 |
# File 'lib/antlr4ruby/atn/action/lexer_action_executor.rb', line 16 def self.append(lexer_executor, lexer_action) return LexerActionExecutor.new([]) unless lexer_executor lexer_actions = lexer_executor.lexer_actions.clone lexer_actions << lexer_action LexerActionExecutor.new(lexer_actions) end |
Instance Method Details
#eql?(other) ⇒ Boolean
67 68 69 |
# File 'lib/antlr4ruby/atn/action/lexer_action_executor.rb', line 67 def eql?(other) # todo end |
#execute(lexer, input, start_index) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/antlr4ruby/atn/action/lexer_action_executor.rb', line 41 def execute(lexer, input, start_index) requires_seek = false stop_index = input.index begin lexer_actions.each do |lexer_action| if lexer_action.instance_of?(LexerIndexedCustomAction) offset = lexer_action.get_offset input.seek(start_index + offset) lexer_action = lexer_action.get_action requires_seek = (start_index + offset) != stop_index elsif lexer_action.is_position_dependent input.seek(stop_index) requires_seek = false end lexer_action.execute(lexer) end ensure input.seek(stop_index) if requires_seek end end |
#fix_offset_before_match(offset) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/antlr4ruby/atn/action/lexer_action_executor.rb', line 23 def fix_offset_before_match(offset) update_lexer_actions = [] lexer_actions.length.times do |i| if lexer_actions[i].is_position_dependent && !(lexer_actions[i].instance_of?(LexerIndexedCustomAction)) update_lexer_actions = lexer_actions.clone if update_lexer_actions.length <= 0 update_lexer_actions[i] = LexerIndexedCustomAction.new(offset, lexer_actions[i]) end end return self if update_lexer_actions.length <= 0 LexerActionExecutor(update_lexer_actions) end |
#get_lexer_actions ⇒ Object
37 38 39 |
# File 'lib/antlr4ruby/atn/action/lexer_action_executor.rb', line 37 def get_lexer_actions @lexer_actions end |
#hash ⇒ Object
63 64 65 |
# File 'lib/antlr4ruby/atn/action/lexer_action_executor.rb', line 63 def hash # todo end |