@@ -12,14 +12,14 @@ def transition_to(state)
12
12
13
13
$states = { }
14
14
15
- $states [ :ANYWHERE ] = {
15
+ $anywhere_transitions = {
16
16
0x18 => [ :execute , transition_to ( :GROUND ) ] ,
17
17
0x1a => [ :execute , transition_to ( :GROUND ) ] ,
18
18
0x80 ..0x8f => [ :execute , transition_to ( :GROUND ) ] ,
19
19
0x91 ..0x97 => [ :execute , transition_to ( :GROUND ) ] ,
20
20
0x99 => [ :execute , transition_to ( :GROUND ) ] ,
21
21
0x9a => [ :execute , transition_to ( :GROUND ) ] ,
22
- 0x9c => [ :execute , transition_to ( :GROUND ) ] ,
22
+ 0x9c => transition_to ( :GROUND ) ,
23
23
0x1b => transition_to ( :ESCAPE ) ,
24
24
0x98 => transition_to ( :SOS_PM_APC_STRING ) ,
25
25
0x9e => transition_to ( :SOS_PM_APC_STRING ) ,
@@ -34,9 +34,6 @@ def transition_to(state)
34
34
0x19 => :execute ,
35
35
0x1c ..0x1f => :execute ,
36
36
0x20 ..0x7f => :print ,
37
- 0x80 ..0x8f => :execute ,
38
- 0x91 ..0x9a => :execute ,
39
- 0x9c => :execute
40
37
}
41
38
42
39
$states[ :ESCAPE ] = {
@@ -144,7 +141,6 @@ def transition_to(state)
144
141
0x19 => :ignore ,
145
142
0x1c ..0x1f => :ignore ,
146
143
0x20 ..0x7f => :ignore ,
147
- 0x9c => transition_to ( :GROUND )
148
144
}
149
145
150
146
$states[ :DCS_PARAM ] = {
@@ -167,7 +163,6 @@ def transition_to(state)
167
163
0x1c ..0x1f => :put ,
168
164
0x20 ..0x7e => :put ,
169
165
0x7f => :ignore ,
170
- 0x9c => transition_to ( :GROUND ) ,
171
166
:on_exit => :unhook
172
167
}
173
168
@@ -176,7 +171,6 @@ def transition_to(state)
176
171
0x19 => :ignore ,
177
172
0x1c ..0x1f => :ignore ,
178
173
0x20 ..0x7f => :ignore ,
179
- 0x9c => transition_to ( :GROUND )
180
174
}
181
175
182
176
$states[ :OSC_STRING ] = {
@@ -185,24 +179,16 @@ def transition_to(state)
185
179
0x19 => :ignore ,
186
180
0x1c ..0x1f => :ignore ,
187
181
0x20 ..0x7f => :osc_put ,
188
- 0x9c => transition_to ( :GROUND ) ,
189
182
:on_exit => :osc_end
190
183
}
191
184
192
- $states. each { |state , transitions |
193
- transitions . each { |keys , actions |
194
- if not actions . kind_of? ( Array )
195
- $states[ state ] [ keys ] = [ actions ]
196
- end
197
- }
198
- }
199
-
200
185
201
186
# get the list of actions implicit in the tables
202
187
203
188
action_names = { }
204
189
$states. each { |state , transitions |
205
190
transitions . each { |keys , actions |
191
+ actions = [ actions ] if !actions . kind_of? ( Array )
206
192
actions . each { |action |
207
193
if action . kind_of? ( Symbol )
208
194
action_names [ action ] = 1
@@ -213,8 +199,10 @@ def transition_to(state)
213
199
214
200
# establish an ordering to the states and actions
215
201
216
- $actions_in_order = action_names . keys . sort { |a1 , a2 | a1 . to_s <=> a2 . to_s } + [ :error ]
217
- $states_in_order = $states. keys . sort { |s1 , s2 | s1 . to_s <=> s2 . to_s }
202
+ $actions_in_order = action_names . keys . sort { |a1 , a2 | a1 . to_s <=> a2 . to_s } + [ :error ]
203
+ $states_in_order = $states. keys . sort { |s1 , s2 | s1 . to_s <=> s2 . to_s }
204
+
205
+
218
206
219
207
#
220
208
# Expand the above range-based data structures (which are convenient
@@ -242,4 +230,22 @@ def expand_ranges(hash_with_ranges_as_keys)
242
230
$state_tables[ state ] = expand_ranges ( transitions )
243
231
}
244
232
233
+ # seed all the states with the anywhere transitions
234
+ $anywhere_transitions = expand_ranges ( $anywhere_transitions)
235
+
236
+ $state_tables. each { |state , transitions |
237
+ $anywhere_transitions. each_with_index { |transition , i |
238
+ next if transition . nil?
239
+ if transitions [ i ]
240
+ raise "State #{ state } already had a transition defined for 0x#{ i . to_s ( 16 ) } , but " + \
241
+ "that transition is also an anywhere transition!"
242
+ end
243
+ transitions [ i ] = transition
244
+ }
245
+ }
246
+
247
+ # for consistency, make all transitions *lists* of actions
248
+ $state_tables. each { |state , transitions |
249
+ transitions . map! { |t | t . kind_of? ( Array ) ? t : [ t ] }
250
+ }
245
251
0 commit comments