diff options
author | murphy <murphy@rubychan.de> | 2009-10-19 17:40:34 +0000 |
---|---|---|
committer | murphy <murphy@rubychan.de> | 2009-10-19 17:40:34 +0000 |
commit | 0201cedb3a449510082a6fc084702d62391f2555 (patch) | |
tree | ce4e99483d9dab92c3a4df33e4ee114edccea468 /lib/coderay/scanners/php.rb | |
parent | 87783c60d93caa75fc8cd117e5d9cb9be0a558f3 (diff) | |
download | coderay-0201cedb3a449510082a6fc084702d62391f2555.tar.gz |
Updated PHP scanner: added a test, improved HTML/PHP detection, cleanup.
Diffstat (limited to 'lib/coderay/scanners/php.rb')
-rw-r--r-- | lib/coderay/scanners/php.rb | 18 |
1 files changed, 8 insertions, 10 deletions
diff --git a/lib/coderay/scanners/php.rb b/lib/coderay/scanners/php.rb index 46f879e..8949eff 100644 --- a/lib/coderay/scanners/php.rb +++ b/lib/coderay/scanners/php.rb @@ -1,11 +1,3 @@ -class XRegexp - def |(other) - Regexp.union(self, other) - end - def +(other) - /#{self}#{other}/ - end -end module CodeRay module Scanners @@ -17,6 +9,8 @@ module Scanners register_for :php file_extension 'php' + KINDS_NOT_LOC = HTML::KINDS_NOT_LOC + def setup @html_scanner = CodeRay.scanner :html, :tokens => @tokens, :keep_tokens => true, :keep_state => true end @@ -188,6 +182,8 @@ module Scanners \?> !xi + HTML_INDICATOR = /<!DOCTYPE html|<(?:html|body|div|p)[> ]/i + IDENTIFIER = /[a-z_\x80-\xFF][a-z0-9_\x80-\xFF]*/i VARIABLE = /\$#{IDENTIFIER}/ @@ -209,11 +205,13 @@ module Scanners states = [:initial] if match?(RE::PHP_START) || # starts with <? - (match?(/\s*<(?i:\w|\?xml)/) && exist?(RE::PHP_START)) # starts with HTML tag and contains <? - # start with HTML + (match?(/\s*<(?i:\w|\?xml)/) && exist?(RE::PHP_START)) || # starts with HTML tag and contains <? + exist?(RE::HTML_INDICATOR) + # is PHP inside HTML, so start with HTML else states << :php end + # heredocdelim = nil delimiter = nil |