Class: SGF::SGFStateMachine
- Inherits:
-
StateMachine
- Object
- StateMachine
- SGF::SGFStateMachine
- Defined in:
- lib/sgf/sgf_state_machine.rb
Constant Summary collapse
- STATE_BEGIN =
:begin
- STATE_GAME_BEGIN =
:game_begin
- STATE_GAME_END =
:game_end
- STATE_NODE =
:game_node
- STATE_VAR_BEGIN =
:var_begin
- STATE_VAR_END =
:var_end
- STATE_PROP_NAME_BEGIN =
:prop_name_begin
- STATE_PROP_NAME =
:prop_name
- STATE_VALUE_BEGIN =
:value_begin
- STATE_VALUE =
:value
- STATE_VALUE_ESCAPE =
:value_escape
- STATE_VALUE_END =
:value_end
- STATE_INVALID =
:invalid
Instance Attribute Summary
Attributes inherited from StateMachine
#before_state, #buffer, #context, #input, #start_state, #state, #transitions
Instance Method Summary collapse
-
#initialize ⇒ SGFStateMachine
constructor
A new instance of SGFStateMachine.
Methods inherited from StateMachine
#clear_buffer, #desc, #end, #event, #reset, #transition, #transition_if
Methods included from Debugger
#debug, #disable_debug_mode, #enable_debug_mode
Constructor Details
#initialize ⇒ SGFStateMachine
Returns a new instance of SGFStateMachine.
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 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 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/sgf/sgf_state_machine.rb', line 21 def initialize super(STATE_BEGIN) start_game = lambda{ |stm| return if stm.context.nil?; stm.context.start_game } end_game = lambda{ |stm| return if stm.context.nil?; stm.context.end_game } start_node = lambda{ |stm| return if stm.context.nil?; stm.context.start_node } start_variation = lambda{ |stm| return if stm.context.nil?; stm.context.start_variation } store_input_in_buffer = lambda{ |stm| return if stm.context.nil?; stm.buffer = stm.input } append_input_to_buffer = lambda{ |stm| return if stm.context.nil?; stm.buffer += stm.input } set_property_name = lambda{ |stm| return if stm.context.nil?; stm.context.property_name = stm.buffer; stm.clear_buffer } set_property_value = lambda{ |stm| return if stm.context.nil?; stm.context.property_value = stm.buffer; stm.clear_buffer } end_variation = lambda{ |stm| return if stm.context.nil?; stm.context.end_variation } report_error = lambda{ |stm| raise StateMachineError.new('SGF Error near "' + stm.input + '"') } transition STATE_BEGIN, /\(/, STATE_GAME_BEGIN, start_game transition [STATE_GAME_BEGIN, STATE_VAR_END, STATE_VALUE_END], /;/, STATE_NODE, start_node transition STATE_VAR_BEGIN, /;/, STATE_NODE transition [STATE_NODE, STATE_VAR_END, STATE_VALUE_END], /\(/, STATE_VAR_BEGIN, start_variation transition [STATE_NODE, STATE_VALUE_END], /[a-zA-Z]/, STATE_PROP_NAME_BEGIN, store_input_in_buffer transition [STATE_PROP_NAME_BEGIN, STATE_PROP_NAME], /[a-zA-Z]/, STATE_PROP_NAME, append_input_to_buffer transition [STATE_PROP_NAME_BEGIN, STATE_PROP_NAME], /\[/, STATE_VALUE_BEGIN, set_property_name transition STATE_VALUE_END, /\[/, STATE_VALUE_BEGIN transition STATE_VALUE_BEGIN, /[^\]]/, STATE_VALUE, store_input_in_buffer transition [STATE_VALUE_BEGIN, STATE_VALUE], /\\/, STATE_VALUE_ESCAPE transition STATE_VALUE_ESCAPE, /./, STATE_VALUE, append_input_to_buffer transition STATE_VALUE, /[^\]]/, nil, append_input_to_buffer transition [STATE_VALUE_BEGIN, STATE_VALUE], /\]/, STATE_VALUE_END, set_property_value transition STATE_VAR_END, nil, STATE_GAME_END, end_game transition [STATE_NODE, STATE_VALUE_END, STATE_VAR_END], /\)/, STATE_VAR_END, end_variation transition [STATE_BEGIN, STATE_GAME_BEGIN, STATE_NODE, STATE_VAR_BEGIN, STATE_VAR_END, STATE_PROP_NAME_BEGIN, STATE_PROP_NAME, STATE_VALUE_END], /[^\s]/, STATE_INVALID, report_error end |