@@ -182,9 +182,8 @@ def file_extension
182
182
# Scan the code and returns all tokens in a Tokens object.
183
183
def tokenize source = nil , options = { }
184
184
options = @options . merge ( options )
185
- @tokens = options [ :tokens ] || @tokens || Tokens . new
186
- @tokens . scanner = self if @tokens . respond_to? :scanner=
187
185
186
+ set_tokens_from_options options
188
187
set_string_from_source source
189
188
190
189
begin
@@ -266,6 +265,11 @@ def set_string_from_source source
266
265
end
267
266
end
268
267
268
+ def set_tokens_from_options options
269
+ @tokens = options [ :tokens ] || @tokens || Tokens . new
270
+ @tokens . scanner = self if @tokens . respond_to? :scanner=
271
+ end
272
+
269
273
# This is the central method, and commonly the only one a
270
274
# subclass implements.
271
275
#
@@ -292,7 +296,7 @@ def reset_instance
292
296
293
297
current line: %d column: %d pos: %d
294
298
matched: %p state: %p
295
- bol? = %p, eos? = %p
299
+ bol?: %p, eos?: %p
296
300
297
301
surrounding code:
298
302
%p ~~ %p
@@ -303,14 +307,15 @@ def reset_instance
303
307
MESSAGE
304
308
305
309
# Scanner error with additional status information
306
- def raise_inspect msg , tokens , state = self . state || 'No state given!' , ambit = 30 , backtrace = caller
310
+ def raise_inspect msg , tokens , state = self . state , ambit = 30 , backtrace = caller
307
311
raise ScanError , SCAN_ERROR_MESSAGE % [
308
312
File . basename ( caller [ 0 ] ) ,
309
313
msg ,
310
- tokens . respond_to? ( :size ) ? tokens . size : 0 ,
311
- tokens . respond_to? ( :last ) ? tokens . last ( 10 ) . map { | t | t . inspect } . join ( "\n " ) : '' ,
314
+ tokens . respond_to? ( :size ) ? tokens . size : '[tokens.size undefined]' ,
315
+ tokens . respond_to? ( :last ) ? tokens . last ( 10 ) . map ( & : inspect) . join ( "\n " ) : '[tokens.last undefined] ' ,
312
316
line , column , pos ,
313
- matched , state , bol? , eos? ,
317
+ matched , state || 'No state given!' ,
318
+ bol? , eos? ,
314
319
binary_string [ pos - ambit , ambit ] ,
315
320
binary_string [ pos , ambit ] ,
316
321
] , backtrace
0 commit comments