Module: Ibex::Runtime::ParserSyncRecovery
- Included in:
- Parser
- Defined in:
- lib/ibex/runtime/parser_sync_recovery.rb,
sig/ibex/runtime/parser_sync_recovery.rbs
Overview
Panic-mode synchronization used only when yacc's explicit error token
cannot be shifted. Included by Parser to share its table and event paths.
Constant Summary collapse
- ERROR_ACTION =
[:error].freeze
Instance Method Summary collapse
- #begin_sync_recovery(context, token_data, observers) ⇒ Object
- #clear_sync_recovery ⇒ void
- #continue_sync_recovery ⇒ Object
- #finish_sync_recovery ⇒ [ :continue ]
- #reject_sync_recovery_eof ⇒ [ :done, nil ]
- #sync_action(state, token_id) ⇒ Object
- #sync_recovery_active? ⇒ Boolean
- #sync_recovery_configured? ⇒ Boolean
- #sync_token?(token_id) ⇒ Boolean
- #synchronize_for_current_token ⇒ Boolean
Instance Method Details
#begin_sync_recovery(context, token_data, observers) ⇒ Object
38 39 40 41 42 43 |
# File 'lib/ibex/runtime/parser_sync_recovery.rb', line 38 def begin_sync_recovery(context, token_data, observers) @sync_recovery_context = context @sync_recovery_token_data = token_data @sync_recovery_observers = observers continue_sync_recovery end |
#clear_sync_recovery ⇒ void
This method returns an undefined value.
101 102 103 104 105 |
# File 'lib/ibex/runtime/parser_sync_recovery.rb', line 101 def clear_sync_recovery @sync_recovery_context = nil @sync_recovery_token_data = nil @sync_recovery_observers = nil end |
#continue_sync_recovery ⇒ Object
46 47 48 49 50 51 |
# File 'lib/ibex/runtime/parser_sync_recovery.rb', line 46 def continue_sync_recovery return reject_sync_recovery_eof if @lookahead == Parser::EOF_TOKEN return finish_sync_recovery if sync_token?(@lookahead) && synchronize_for_current_token continue_recovery end |
#finish_sync_recovery ⇒ [ :continue ]
81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/ibex/runtime/parser_sync_recovery.rb', line 81 def finish_sync_recovery context = @sync_recovery_context || raise(ParseError, "(recovery):1:1: missing synchronization context") token_data = @sync_recovery_token_data observers = @sync_recovery_observers clear_sync_recovery @recovery_shifts = Parser::RECOVERY_SHIFTS trace("recover: synchronized before #{token_to_str(@lookahead)} in state #{@state_stack.last}") if @yydebug finish_recovery( context[:token_id], context[:token_display], context[:value], context[:location], context[:state], context.fetch(:value_stack), token_data, context.fetch(:reason), observers ) end |
#reject_sync_recovery_eof ⇒ [ :done, nil ]
95 96 97 98 |
# File 'lib/ibex/runtime/parser_sync_recovery.rb', line 95 def reject_sync_recovery_eof clear_sync_recovery reject_recovery_eof end |
#sync_action(state, token_id) ⇒ Object
74 75 76 77 78 |
# File 'lib/ibex/runtime/parser_sync_recovery.rb', line 74 def sync_action(state, token_id) return ERROR_ACTION unless parser_tables.fetch(:token_names).key?(token_id) table_lookup(parser_tables.fetch(:actions), state, token_id) || default_action(state) || ERROR_ACTION end |
#sync_recovery_active? ⇒ Boolean
32 33 34 |
# File 'lib/ibex/runtime/parser_sync_recovery.rb', line 32 def sync_recovery_active? !@sync_recovery_context.nil? end |
#sync_recovery_configured? ⇒ Boolean
26 27 28 29 |
# File 'lib/ibex/runtime/parser_sync_recovery.rb', line 26 def sync_recovery_configured? tokens = parser_tables[:recovery_sync_tokens] tokens.is_a?(Array) && !tokens.empty? end |
#sync_token?(token_id) ⇒ Boolean
54 55 56 57 |
# File 'lib/ibex/runtime/parser_sync_recovery.rb', line 54 def sync_token?(token_id) tokens = parser_tables[:recovery_sync_tokens] tokens.is_a?(Array) && tokens.include?(token_id) end |
#synchronize_for_current_token ⇒ Boolean
60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/ibex/runtime/parser_sync_recovery.rb', line 60 def synchronize_for_current_token loop do action = sync_action(@state_stack.last, @lookahead) return true unless action.nil? || action.first == :error return false if @state_stack.length == 1 trace("recover: pop state #{@state_stack.last} for sync token") if @yydebug @state_stack.pop @value_stack.pop @location_stack&.pop end end |