From 432aeb74d5a49e6f0efd1063113cef099c93aef6 Mon Sep 17 00:00:00 2001 From: murphy Date: Mon, 28 Dec 2009 07:27:12 +0000 Subject: Copying changes and fixes for 0.9.0rc3 from terminal-encoder branch over to trunk. --- lib/coderay/scanners/php.rb | 197 ++++++++++++++++++++++++++++++++------------ 1 file changed, 143 insertions(+), 54 deletions(-) (limited to 'lib/coderay/scanners/php.rb') diff --git a/lib/coderay/scanners/php.rb b/lib/coderay/scanners/php.rb index bfbc642..af9e16f 100644 --- a/lib/coderay/scanners/php.rb +++ b/lib/coderay/scanners/php.rb @@ -38,7 +38,7 @@ module Scanners require require_once return print unset ] - CLASSES = %w[ Directory stdClass __PHP_Incomplete_Class exception php_user_filter Closure ] + CLASSES = %w[ Directory stdClass __PHP_Incomplete_Class exception php_user_filter Closure ] # according to http://php.net/quickref.php on 2009-04-21; # all functions with _ excluded (module functions) and selected additional functions @@ -117,6 +117,18 @@ module Scanners utf8_decode utf8_encode var_dump var_export version_compare zend_logo_guid zend_thread_id zend_version + create_function call_user_func_array + posix_access posix_ctermid posix_get_last_error posix_getcwd posix_getegid + posix_geteuid posix_getgid posix_getgrgid posix_getgrnam posix_getgroups + posix_getlogin posix_getpgid posix_getpgrp posix_getpid posix_getppid + posix_getpwnam posix_getpwuid posix_getrlimit posix_getsid posix_getuid + posix_initgroups posix_isatty posix_kill posix_mkfifo posix_mknod + posix_setegid posix_seteuid posix_setgid posix_setpgid posix_setsid + posix_setuid posix_strerror posix_times posix_ttyname posix_uname + pcntl_alarm pcntl_exec pcntl_fork pcntl_getpriority pcntl_setpriority + pcntl_signal pcntl_signal_dispatch pcntl_sigprocmask pcntl_sigtimedwait + pcntl_sigwaitinfo pcntl_wait pcntl_waitpid pcntl_wexitstatus pcntl_wifexited + pcntl_wifsignaled pcntl_wifstopped pcntl_wstopsig pcntl_wtermsig ] # TODO: more built-in PHP functions? @@ -158,6 +170,12 @@ module Scanners LOG_NDELAY LOG_NOWAIT LOG_PERROR ] + PREDEFINED = %w[ + $GLOBALS $_SERVER $_GET $_POST $_FILES $_REQUEST $_SESSION $_ENV + $_COOKIE $php_errormsg $HTTP_RAW_POST_DATA $http_response_header + $argc $argv + ] + IDENT_KIND = CaseIgnoringWordList.new(:ident, true). add(KEYWORDS, :reserved). add(TYPES, :pre_type). @@ -166,6 +184,9 @@ module Scanners add(CLASSES, :pre_constant). add(EXCEPTIONS, :exception). add(CONSTANTS, :pre_constant) + + VARIABLE_KIND = WordList.new(:local_variable). + add(PREDEFINED, :predefined) end module RE @@ -194,7 +215,8 @@ module Scanners \+\+ | -- | # increment, decrement [,;?:()\[\]{}] | # simple delimiters [-+*\/%&|^]=? | # ordinary math, binary logic, assignment shortcuts - [~@$] | # whatever + [~$] | # whatever + =& | # reference assignment [=!]=?=? | <> | # comparison and assignment <<=? | >>=? | [<>]=? # comparison and shift /x @@ -203,17 +225,23 @@ module Scanners def scan_tokens tokens, options - states = [:initial] - if match?(RE::PHP_START) || # starts with bar kind of stuff - # TODO: highlight tokens separately! if check(/\[#{RE::IDENTIFIER}\]/o) - match << scan(/\[#{RE::IDENTIFIER}\]/o) + tokens << [:open, :inline] + tokens << [match, :local_variable] + tokens << [scan(/\[/), :operator] + tokens << [scan(/#{RE::IDENTIFIER}/o), :ident] + tokens << [scan(/\]/), :operator] + tokens << [:close, :inline] + next elsif check(/\[/) - match << scan(/\[#{RE::IDENTIFIER}?/o) + match << scan(/\[['"]?#{RE::IDENTIFIER}?['"]?\]?/o) kind = :error elsif check(/->#{RE::IDENTIFIER}/o) - match << scan(/->#{RE::IDENTIFIER}/o) + tokens << [:open, :inline] + tokens << [match, :local_variable] + tokens << [scan(/->/), :operator] + tokens << [scan(/#{RE::IDENTIFIER}/o), :ident] + tokens << [:close, :inline] + next elsif check(/->/) match << scan(/->/) kind = :error -- cgit v1.2.1