Skip to content

Commit cc3185f

Browse files
committed
test using skip instead of scan
1 parent 7493dcb commit cc3185f

File tree

1 file changed

+18
-17
lines changed

1 file changed

+18
-17
lines changed

lib/coderay/scanners/ruby.rb

+18-17
Original file line numberDiff line numberDiff line change
@@ -62,30 +62,31 @@ def scan_tokens encoder, options
6262
if match = scan(/[ \t\f\v]+/)
6363
encoder.text_token match, :space
6464

65-
elsif match = scan(/\n/)
65+
elsif skip(/\n/)
6666
if heredocs
6767
unscan # heredoc scanning needs \n at start
6868
state = heredocs.shift
6969
encoder.begin_group state.type
7070
heredocs = nil if heredocs.empty?
7171
else
7272
state = :initial if state == :undef_comma_expected
73-
encoder.text_token match, :space
73+
encoder.text_token "\n", :space
7474
value_expected = true
7575
end
7676

7777
elsif match = scan(bol? ? / \#(!)?.* | #{patterns::RUBYDOC_OR_DATA} /ox : /\#.*/)
7878
encoder.text_token match, self[1] ? :doctype : :comment
7979

80-
elsif match = scan(/\\\n/)
80+
elsif skip(/\\\n/)
8181
if heredocs
8282
unscan # heredoc scanning needs \n at start
83-
encoder.text_token scan(/\\/), :space
83+
skip(/\\/)
84+
encoder.text_token '\\', :space
8485
state = heredocs.shift
8586
encoder.begin_group state.type
8687
heredocs = nil if heredocs.empty?
8788
else
88-
encoder.text_token match, :space
89+
encoder.text_token "\\\n", :space
8990
end
9091

9192
elsif state == :initial
@@ -96,7 +97,7 @@ def scan_tokens encoder, options
9697
/#{patterns::METHOD_NAME}/o)
9798

9899
kind = patterns::IDENT_KIND[match]
99-
if value_expected != :colon_expected && scan(/:(?!:)/)
100+
if value_expected != :colon_expected && skip(/:(?!:)/)
100101
value_expected = true
101102
encoder.text_token match, :key
102103
encoder.text_token ':', :operator
@@ -181,9 +182,9 @@ def scan_tokens encoder, options
181182
value_expected = false
182183
encoder.text_token match, :instance_variable
183184

184-
elsif value_expected && match = scan(/\//)
185+
elsif value_expected && skip(/\//)
185186
encoder.begin_group :regexp
186-
encoder.text_token match, :delimiter
187+
encoder.text_token '/', :delimiter
187188
state = self.class::StringState.new :regexp, true, '/'
188189

189190
elsif match = scan(value_expected ? /[-+]?#{patterns::NUMERIC}/o : /#{patterns::NUMERIC}/o)
@@ -225,10 +226,10 @@ def scan_tokens encoder, options
225226
value_expected = match == '?' ? :colon_expected : true
226227
encoder.text_token match, :operator
227228

228-
elsif match = scan(/`/)
229+
elsif skip(/`/)
229230
encoder.begin_group :shell
230-
encoder.text_token match, :delimiter
231-
state = self.class::StringState.new :shell, true, match
231+
encoder.text_token '`', :delimiter
232+
state = self.class::StringState.new :shell, true, '`'
232233

233234
elsif match = scan(unicode ? /#{patterns::GLOBAL_VARIABLE}/uo :
234235
/#{patterns::GLOBAL_VARIABLE}/o)
@@ -240,8 +241,8 @@ def scan_tokens encoder, options
240241
encoder.text_token match, :class_variable
241242
value_expected = false
242243

243-
elsif match = scan(/\\\z/)
244-
encoder.text_token match, :space
244+
elsif skip(/\\\z/)
245+
encoder.text_token '\\', :space
245246

246247
else
247248
if method_call_expected
@@ -293,8 +294,8 @@ def scan_tokens encoder, options
293294
end
294295

295296
elsif state == :module_expected
296-
if match = scan(/<</)
297-
encoder.text_token match, :operator
297+
if skip(/<</)
298+
encoder.text_token '<<', :operator
298299
else
299300
state = :initial
300301
if match = scan(unicode ? / (?:#{patterns::IDENT}::)* #{patterns::IDENT} /oux :
@@ -325,8 +326,8 @@ def scan_tokens encoder, options
325326
end
326327

327328
elsif state == :undef_comma_expected
328-
if match = scan(/,/)
329-
encoder.text_token match, :operator
329+
if skip(/,/)
330+
encoder.text_token ',', :operator
330331
state = :undef_expected
331332
else
332333
state = :initial

0 commit comments

Comments
 (0)