Module: Lich::Gemstone::Infomon::Parser::State

Defined in:
documented/gemstone/infomon/parser.rb

Overview

Namespace for parser state tracking during multi-line game output parsing.

Maintains the current parse state (e.g., :ready, :goals, :profile, :enhancive_stats) to handle commands whose output spans multiple server lines (SKILL GOALS, PROFILE, INVENTORY ENHANCIVE TOTALS). State transitions are guarded to catch parser state machine errors.

See Also:

Constant Summary collapse

Goals =
:goals
Profile =
:profile
Ready =
:ready
EnhanciveStats =

Enhancive parsing states

:enhancive_stats
EnhanciveSkills =
:enhancive_skills
EnhanciveResources =
:enhancive_resources
EnhanciveMartial =
:enhancive_martial
EnhanciveSpells =
:enhancive_spells
EnhanciveStatistics =
:enhancive_statistics

Class Method Summary collapse

Class Method Details

.enhancive_state?Boolean

Returns true if the parser is in any of the Enhancive parsing states.

Useful for detecting whether enhancive inventory output is being parsed and for guarding initialization of @enhancive_hold across multiple section handlers.

Returns:

  • (Boolean)

    true if state is EnhanciveStats, EnhanciveSkills, EnhanciveResources, EnhanciveMartial, EnhanciveSpells, or EnhanciveStatistics; false otherwise

See Also:



272
273
274
275
# File 'documented/gemstone/infomon/parser.rb', line 272

def self.enhancive_state?
  [EnhanciveStats, EnhanciveSkills, EnhanciveResources,
   EnhanciveMartial, EnhanciveSpells, EnhanciveStatistics].include?(@state)
end

.getSymbol

Returns the current parser state.

Returns:

  • (Symbol)

    the current state (:ready, :goals, :profile, :enhancive_stats, etc.)

See Also:



260
261
262
# File 'documented/gemstone/infomon/parser.rb', line 260

def self.get
  @state
end

.set(state) ⇒ Symbol

Sets the parser state with transition validation.

Enforces valid state transitions: Goals and Profile states can only be entered from Ready; Enhancive states can transition from Ready or between other Enhancive states. Attempting an invalid transition raises an error with caller context for debugging.

Parameters:

  • state (Symbol)

    the target state (:goals, :profile, :ready, :enhancive_stats, etc.)

Returns:

  • (Symbol)

    the state that was set

Raises:

  • (RuntimeError)

    if the state transition is invalid

See Also:

  • get
  • Parser.State::Goals
  • Parser.State::EnhanciveStats


239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
# File 'documented/gemstone/infomon/parser.rb', line 239

def self.set(state)
  case state
  when Goals, Profile
    unless @state.eql?(Ready)
      Lich.log "error: Infomon::Parser::State is in invalid state(#{@state}) - caller: #{caller[0]}"
      fail "--- Lich: error: Infomon::Parser::State is in invalid state(#{@state}) - caller: #{caller[0]}"
    end
  when EnhanciveStats, EnhanciveSkills, EnhanciveResources, EnhanciveMartial, EnhanciveSpells, EnhanciveStatistics
    # Enhancive states can start from Ready or transition between each other
    unless @state.eql?(Ready) || enhancive_state?
      Lich.log "error: Infomon::Parser::State is in invalid state(#{@state}) - caller: #{caller[0]}"
      fail "--- Lich: error: Infomon::Parser::State is in invalid state(#{@state}) - caller: #{caller[0]}"
    end
  end
  @state = state
end