diff options
author | murphy <murphy@rubychan.de> | 2009-01-04 14:27:34 +0000 |
---|---|---|
committer | murphy <murphy@rubychan.de> | 2009-01-04 14:27:34 +0000 |
commit | 1ec41b19995acf2adffdf42fb957ab20d5f7b88e (patch) | |
tree | e8044ee72b60779d06c657699a335dbffbdbae3e | |
parent | de0fc10606a67c95c27bcadd2f8daaf6820ef1ea (diff) | |
download | coderay-1ec41b19995acf2adffdf42fb957ab20d5f7b88e.tar.gz |
Added scanner proposals.
-rw-r--r-- | etc/todo/scanners/bash.rb | 124 | ||||
-rw-r--r-- | etc/todo/scanners/coderay_lua_lexar.patch | 193 |
2 files changed, 317 insertions, 0 deletions
diff --git a/etc/todo/scanners/bash.rb b/etc/todo/scanners/bash.rb new file mode 100644 index 0000000..cbc9e25 --- /dev/null +++ b/etc/todo/scanners/bash.rb @@ -0,0 +1,124 @@ +# author: Vincent Landgraf <setcool@gmx.de> +# licence: GPLv2.1 +require "rubygems" +require "coderay" + +module CodeRay + module Scanners + class Bash < Scanner + include CodeRay::Streamable + register_for :bash + + KEYWORDS = Regexp.new("(%s)(?![a-zA-Z0-9_\-])" % %w{ + if fi until while done for do case in esac select + break else then shift function + }.sort.join('|')) + + BUILTIN = Regexp.new("(%s)(?![a-zA-Z0-9_\-])" % %w{ + cd continue eval exec true false suspend unalias + exit export getopts hash pwd readonly return test + times trap umask unset alias bind builtin caller + command declare echo enable help let local logout + printf read shopt source type typeset ulimit + set dirs popd pushd bg fg jobs kill wait disown + }.sort.join('|')) + + GLOBAL_VARIABLES = Regexp.new("(%s)(?![a-zA-Z0-9_\-])" % %w{ + CDPATH HOME IFS MAIL MAILPATH OPTARG LINENO LINES + OPTIND PATH PS1 PS2 BASH BASH_ARGCBASH_ARGV + BASH_COMMAND BASH_ENV BASH_EXECUTION_STRING + BASH_LINENO BASH_REMATCH BASH_SOURCE COLUMNS + BASH_SUBSHELL BASH_VERSINFO BASH_VERSION OSTYPE + COMP_CWORD COMP_LINE COMP_POINT COMP_WORDBREAKS + COMP_WORDS COMPREPLY DIRSTACK EMACS EUID OTPERR + FCEDIT FIGNORE FUNCNAME GLOBIGNORE GROUPS OLDPWD + histchars HISTCMD HISTCONTROL HISTFILE MACHTYPE + HISTFILESIZE HISTIGNORE HISTSIZE HISTTIMEFOMAT + HOSTFILE HOSTNAME HOSTTYPE IGNOREEOF INPUTRC LANG + LC_ALL LC_COLLATE LC_CTYPE LC_MESSAGES LC_NUMERIC + PIPESTATUS POSIXLY_CORRECT MAILCHECK PPID PS3 PS4 + PROMPT_COMMAND PWD RANDOM REPLY SECONDS SHELL + SHELLOPTS SHLVL TIMEFORMAT TMOUT TMPDIR UID + }.sort.join('|')) + + VARIABLE_SIMPLE = /\$[a-zA-Z]\w*/ + + VARIABLE_EXPRESSION = /\$\{[!#]?[a-zA-Z].*?\}/ + + CONSTANT = /\$[@#?\-$!_0-9]/ + + def scan_tokens (tokens, options) + state = :initial + str_delimiter = nil + + until eos? + if state == :initial + if match = scan(CONSTANT) + tokens << [match, :constant] + elsif match = scan(/(#{VARIABLE_SIMPLE}|#{VARIABLE_EXPRESSION})/) + tokens << [match, :instance_variable] + elsif match = scan(/\s+/) + tokens << [match, :space] + elsif match = scan(/-[a-zA-Z]\w*(=\w*)?/) + tokens << [match, :argument] + elsif match = scan(/[;<>~]|[&]{1,2}|[|]{1,2}|\*/) + tokens << [match, :operator] + elsif match = scan(/[1-9][0-9]*/) + tokens << [match, :number] + elsif ((!tokens.empty? and tokens.last[1] != :escape) or tokens.empty? ) and + (str_delimiter = scan(/["'`]/)) + # don't match if last token is backsplash + tokens << [:open, :string] + tokens << [str_delimiter, :delimiter] + state = :string + elsif match = scan(/\\/) + tokens << [match, :escape] + elsif match = scan(KEYWORDS) + tokens << [match, :reserved] + elsif match = scan(BUILTIN) + tokens << [match, :method] + elsif match = scan(GLOBAL_VARIABLES) + tokens << [match, :global_variable] + elsif match = scan(/[a-zA-Z]\w*/) + tokens << [match, :ident] + elsif match = scan(/\#!.*/) # until eof + tokens << [match, :preprocessor] + elsif match = scan(/\#.*/) # until eof + tokens << [match, :comment] + # catch the rest as other + else c = getch + tokens << [c, :other] + end + elsif state == :string + if match = scan(/[\\][abefnrtv\\#{str_delimiter}]/) + tokens << [match, :escape] + elsif match = scan(CONSTANT) + tokens << [:open, :inline] + tokens << [match, :constant] + tokens << [:close, :inline] + elsif match = scan(/(#{VARIABLE_SIMPLE}|#{VARIABLE_EXPRESSION})/) + tokens << [:open, :inline] + tokens << [match, :instance_variable] + tokens << [:close, :inline] + elsif match = scan(/[^\n#{str_delimiter}\\][^\n#{str_delimiter}$\\]*/) + tokens << [match, :content] + elsif match = scan(Regexp.new(str_delimiter)) + tokens << [match, :delimiter] + tokens << [:close, :string] + state = :initial + elsif scan(/\n/) + tokens << [:close, :string] + state = :initial + else + raise 'String: else-case reached', tokens + end + else + raise 'else-case reached', tokens + end + end + + return tokens + end + end + end +end
\ No newline at end of file diff --git a/etc/todo/scanners/coderay_lua_lexar.patch b/etc/todo/scanners/coderay_lua_lexar.patch new file mode 100644 index 0000000..23d2bc6 --- /dev/null +++ b/etc/todo/scanners/coderay_lua_lexar.patch @@ -0,0 +1,193 @@ +by Chris Peterson +http://www.redmine.org/issues/show/1471 +http://www.redmine.org/attachments/642/coderay_lua_lexar.patch +Index: vendor/plugins/coderay-0.7.6.227/lib/coderay/scanners/lua.rb +=================================================================== +--- vendor/plugins/coderay-0.7.6.227/lib/coderay/scanners/lua.rb (revision 0) ++++ vendor/plugins/coderay-0.7.6.227/lib/coderay/scanners/lua.rb (revision 0) +@@ -0,0 +1,185 @@ ++module CodeRay ++module Scanners ++ ++ class Lua < Scanner ++ ++ register_for :lua ++ ++ include Streamable ++ ++ RESERVED_WORDS = [ ++ 'if', 'elseif', 'else', 'then', ++ 'end', 'do', 'while', 'true', ++ 'false', 'in', 'for', 'and', 'or', ++ 'function', 'local', 'not', 'repeat', ++ 'return', 'until', 'break', ++ ] ++ ++ PREDEFINED_TYPES = [ ++ 'nil', 'boolean', 'number', 'string', 'table', ++ ] ++ ++ BUILTIN_LIBS = [ ++ 'package', 'table', 'math', 'string', 'io', 'os', 'debug', ++ ] ++ ++ BUILTIN_METHODS = [ ++ 'loadlib', 'path', 'cpath', ++ 'loaded','preloaded','seeall', ++ 'coroutine', 'create','resume','yield', ++ 'status','running','wrap', ++ 'insert','remove','maxn','sort', ++ 'concat','abs','mod','floor','ceil', ++ 'min','max','sqrt','math.pow','math.log', ++ 'exp','log10','deg','math.pi','math.rad', ++ 'sin','cos','tan','asin','acos', ++ 'atan','atan2','frexp','ldexp','random', ++ 'randomseed', 'len','sub','rep','upper', ++ 'lower','byte','char','dump','format', ++ 'find','gmatch','gsub','match','open', ++ 'input','output','close','read','lines', ++ 'write','flush','stdout','stdin','stderr', ++ 'popen','type','tmpfile','execute','exit', ++ 'getenv','setlocale','remove','rename','tmpname', ++ 'clock','time','date','difftime','debug', ++ 'getinfo','getlocal','getupvalue','traceback', ++ 'setlocal','setupvalue','sethook','gethook', ++ ] ++ ++ BUILTIN_FUNCTIONS = [ ++ 'print', 'pairs','ipairs', 'error', 'load', ++ 'require', 'getfenv', 'setfenv', 'dofile', ++ 'loadfile', 'loadstring', 'pcall', 'xpcall', ++ 'assert', 'type', 'tostring', 'tonumber', ++ 'select', 'upack', 'next', 'collectgarbage', ++ 'module', ++ ] ++ ++ IDENT_KIND = WordList.new(:ident). ++ add(RESERVED_WORDS, :reserved). ++ add(PREDEFINED_TYPES, :pre_type). ++ add(BUILTIN_LIBS, :predefined). ++ add(BUILTIN_METHODS, :pre_type). ++ add(BUILTIN_FUNCTIONS, :preprocessor) ++ ++ ESCAPE = / [rbfnrtv\n\\'"] | x[a-fA-F0-9]{1,2} | [0-7]{1,3} /x ++ UNICODE_ESCAPE = / u[a-fA-F0-9]{4} | U[a-fA-F0-9]{8} /x ++ ++ def scan_tokens tokens, options ++ ++ state = :initial ++ ++ until eos? ++ ++ kind = nil ++ match = nil ++ ++ case state ++ ++ when :initial ++ ++ if scan(/ \s+ | \\\n /x) ++ kind = :space ++ ++ elsif scan(%r! --[^\n\\]* (?: \\. [^\n\\]* )* | --\[\[ (?: .*? \]\] | .* ) !mx) ++ kind = :comment ++ ++ elsif scan(/ [-+*\/=<>?:;,!&^|()\[\]{}~%]+ | \.(?!\d) /x) ++ kind = :operator ++ ++ elsif match = scan(/ [#A-Za-z_][A-Za-z_0-9]* /x) ++ kind = IDENT_KIND[match] ++ if kind == :pre_type and check(/[^\.\:\(\']/) ++ kind = :ident ++ end ++ ++ elsif match = scan(/L?"/) ++ tokens << [:open, :string] ++ if match[0] == ?L ++ tokens << ['L', :modifier] ++ match = '"' ++ end ++ state = :string ++ kind = :string ++ ++ elsif scan(/ L?' (?: [^\'\n\\] | \\ #{ESCAPE} )? '? /ox) ++ kind = :char ++ ++ elsif scan(/0[xX][0-9A-Fa-f]+/) ++ kind = :hex ++ ++ elsif scan(/(?:0[0-7]+)(?![89.eEfF])/) ++ kind = :oct ++ ++ elsif scan(/(?:\d+)(?![.eEfF])/) ++ kind = :integer ++ ++ elsif scan(/\d[fF]?|\d*\.\d+(?:[eE][+-]?\d+)?[fF]?|\d+[eE][+-]?\d+[fF]?/) ++ kind = :float ++ ++ else ++ getch ++ kind = :error ++ ++ end ++ ++ when :string ++ if scan(/[^\\\n"]+/) ++ kind = :content ++ elsif scan(/"/) ++ tokens << ['"', :string] ++ tokens << [:close, :string] ++ state = :initial ++ next ++ elsif scan(/ \\ (?: #{ESCAPE} | #{UNICODE_ESCAPE} ) /mox) ++ kind = :char ++ elsif scan(/ \\ | $ /x) ++ tokens << [:close, :string] ++ kind = :error ++ state = :initial ++ else ++ raise_inspect "else case \" reached; %p not handled." % peek(1), tokens ++ end ++ ++ when :include_expected ++ if scan(/<[^>\n]+>?|"[^"\n\\]*(?:\\.[^"\n\\]*)*"?/) ++ kind = :include ++ state = :initial ++ ++ elsif match = scan(/\s+/) ++ kind = :space ++ state = :initial if match.index ?\n ++ ++ else ++ getch ++ kind = :error ++ ++ end ++ ++ else ++ raise_inspect 'Unknown state', tokens ++ ++ end ++ ++ match ||= matched ++ if $DEBUG and not kind ++ raise_inspect 'Error token %p in line %d' % ++ [[match, kind], line], tokens ++ end ++ raise_inspect 'Empty token', tokens unless match ++ ++ tokens << [match, kind] ++ ++ end ++ ++ if state == :string ++ tokens << [:close, :string] ++ end ++ ++ tokens ++ end ++ ++ end ++ ++end ++end |