8000 fix token nesting in PHP scanner · tricknotes/coderay@c34ad73 · GitHub
[go: up one dir, main page]

Skip to content

Commit c34ad73

Browse files
committed
fix token nesting in PHP scanner
1 parent c8751fb commit c34ad73

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

lib/coderay/scanners/php.rb

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ def scan_tokens encoder, options
265265
@html_scanner.tokenize match unless match.empty?
266266
end
267267

268-
when :php
268+
when :php, :php_inline
269269
if match = scan(/\s+/)
270270
encoder.text_token match, :space
271271

@@ -332,14 +332,15 @@ def scan_tokens encoder, options
332332
if states.size == 1
333333
encoder.text_token match, :error
334334
else
335-
states.pop
335+
state = states.pop
336336
if states.last.is_a?(::Array)
337337
delimiter = states.last[1]
338338
states[-1] = states.last[0]
339339
encoder.text_token match, :delimiter
340340
encoder.end_group :inline
341341
else
342342
encoder.text_token match, :operator
343+
encoder.end_group :inline if state == :php_inline
343344
label_expected = true
344345
end
345346
end
@@ -350,7 +351,14 @@ def scan_tokens encoder, options
350351

351352
elsif match = scan(RE::PHP_END)
352353
encoder.text_token match, :inline_delimiter
353-
states = [:initial]
354+
while state = states.pop
355+
encoder.end_group :string if [:sqstring, :dqstring].include? state
356+
if state.is_a? Array
357+
encoder.end_group :inline
358+
encoder.end_group :string if [:sqstring, :dqstring].include? state.first
359+
end
360+
end
361+
states << :initial
354362

355363
elsif match = scan(/<<<(?:(#{RE::IDENTIFIER})|"(#{RE::IDENTIFIER})"|'(#{RE::IDENTIFIER})')/o)
356364
encoder.begin_group :string
@@ -400,6 +408,7 @@ def scan_tokens encoder, options
400408
elsif match = scan(/\\/)
401409
encoder.text_token match, :error
402410
else
411+
encoder.end_group :string
403412
states.pop
404413
end
405414

@@ -459,7 +468,7 @@ def scan_tokens encoder, options
459468
encoder.begin_group :inline
460469
states[-1] = [states.last, delimiter]
461470
delimiter = nil
462-
states.push :php
471+
states.push :php_inline
463472
encoder.text_token match, :delimiter
464473
else
465474
encoder.text_token match, :content
@@ -469,6 +478,7 @@ def scan_tokens encoder, options
469478
elsif match = scan(/\$/)
470479
encoder.text_token match, :content
471480
else
481+
encoder.end_group :string
472482
states.pop
473483
end
474484

@@ -502,6 +512,10 @@ def scan_tokens encoder, options
502512

503513
while state = states.pop
504514
encoder.end_group :string if [:sqstring, :dqstring].include? state
515+
if state.is_a? Array
516+
encoder.end_group :inline
517+
encoder.end_group :string if [:sqstring, :dqstring].include? state.first
518+
end
505519
end
506520

507521
encoder

0 commit comments

Comments
 (0)
0