From fa975bbf5d40644d987887b4cf273a3f02612f03 Mon Sep 17 00:00:00 2001 From: murphy Date: Sat, 1 May 2010 01:31:56 +0000 Subject: Direct Streaming! See #142 and Changes.textile. --- lib/coderay/scanners/php.rb | 233 ++++++++++++++++++++------------------------ 1 file changed, 104 insertions(+), 129 deletions(-) (limited to 'lib/coderay/scanners/php.rb') diff --git a/lib/coderay/scanners/php.rb b/lib/coderay/scanners/php.rb index 289e795..67bb233 100644 --- a/lib/coderay/scanners/php.rb +++ b/lib/coderay/scanners/php.rb @@ -230,7 +230,7 @@ module Scanners protected - def scan_tokens tokens, options + def scan_tokens encoder, options if check(RE::PHP_START) || # starts with #{RE::IDENTIFIER}/o) - tokens << [:open, :inline] - tokens << [match, :local_variable] - tokens << [scan(/->/), :operator] - tokens << [scan(/#{RE::IDENTIFIER}/o), :ident] - tokens << [:close, :inline] - next + encoder.begin_group :inline + encoder.text_token match, :local_variable + encoder.text_token scan(/->/), :operator + encoder.text_token scan(/#{RE::IDENTIFIER}/o), :ident + encoder.end_group :inline elsif check(/->/) match << scan(/->/) - kind = :error + encoder.text_token match, :error + else + encoder.text_token match, :local_variable end elsif match = scan(/\{/) if check(/\$/) - kind = :delimiter + encoder.begin_group :inline states[-1] = [states.last, delimiter] delimiter = nil states.push :php - tokens << [:open, :inline] + encoder.text_token match, :delimiter else - kind = :string + encoder.text_token match, :string end - elsif scan(/\$\{#{RE::IDENTIFIER}\}/o) - kind = :local_variable - elsif scan(/\$/) - kind = :content + elsif match = scan(/\$\{#{RE::IDENTIFIER}\}/o) + encoder.text_token match, :local_variable + elsif match = scan(/\$/) + encoder.text_token match, :content + else + states.pop end when :class_expected - if scan(/\s+/) - kind = :space + if match = scan(/\s+/) + encoder.text_token match, :space elsif match = scan(/#{RE::IDENTIFIER}/o) - kind = :class + encoder.text_token match, :class states.pop else states.pop - next end when :function_expected - if scan(/\s+/) - kind = :space - elsif scan(/&/) - kind = :operator + if match = scan(/\s+/) + encoder.text_token match, :space + elsif match = scan(/&/) + encoder.text_token match, :operator elsif match = scan(/#{RE::IDENTIFIER}/o) - kind = :function + encoder.text_token match, :function states.pop else states.pop - next end else - raise_inspect 'Unknown state!', tokens, states - end - - match ||= matched - if $CODERAY_DEBUG and not kind - raise_inspect 'Error token %p in line %d' % - [[match, kind], line], tokens, states + raise_inspect 'Unknown state!', encoder, states end - raise_inspect 'Empty token', tokens, states unless match - - tokens << [match, kind] end - tokens + encoder end end -- cgit v1.2.1