@@ -184,14 +184,8 @@ def tokenize source = nil, options = {}
184
184
options = @options . merge ( options )
185
185
@tokens = options [ :tokens ] || @tokens || Tokens . new
186
186
@tokens . scanner = self if @tokens . respond_to? :scanner=
187
- case source
188
- when Array
189
- self . string = self . class . normalize ( source . join )
190
- when nil
191
- reset
192
- else
193
- self . string = self . class . normalize ( source )
194
- end
187
+
188
+ set_string_from_source source
195
189
196
190
begin
197
191
scan_tokens @tokens , options
@@ -261,6 +255,17 @@ def binary_string
261
255
def setup # :doc:
262
256
end
263
257
258
+ def set_string_from_source source
259
+ case source
260
+ when Array
261
+ self . string = self . class . normalize ( source . join )
262
+ when nil
263
+ reset
264
+ else
265
+ self . string = self . class . normalize ( source )
266
+ end
267
+ end
268
+
264
269
# This is the central method, and commonly the only one a
265
270
# subclass implements.
266
271
#
@@ -277,9 +282,7 @@ def reset_instance
277
282
@binary_string = nil if defined? @binary_string
278
283
end
279
284
280
- # Scanner error with additional status information
281
- def raise_inspect msg , tokens , state = self . state || 'No state given!' , ambit = 30 , backtrace = caller
282
- raise ScanError , <<-EOE % [
285
+ SCAN_ERROR_MESSAGE = <<-MESSAGE
283
286
284
287
285
288
***ERROR in %s: %s (after %d tokens)
@@ -297,7 +300,11 @@ def raise_inspect msg, tokens, state = self.state || 'No state given!', ambit =
297
300
298
301
***ERROR***
299
302
300
- EOE
303
+ MESSAGE
304
+
305
+ # Scanner error with additional status information
306
+ def raise_inspect msg , tokens , state = self . state || 'No state given!' , ambit = 30 , backtrace = caller
307
+ raise ScanError , SCAN_ERROR_MESSAGE % [
301
308
File . basename ( caller [ 0 ] ) ,
302
309
msg ,
303
310
tokens . respond_to? ( :size ) ? tokens . size : 0 ,
0 commit comments