From dbc30e76d948abfe3cb2fe5a5a001cd065344d6b Mon Sep 17 00:00:00 2001 From: murphy Date: Thu, 11 Sep 2008 23:17:00 +0000 Subject: Some cleanup for the toto folder. --- etc/todo/scanners/sql.Josh Goebel.rb | 138 ++++++++++++++++++++++++++++++++++ etc/todo/scanners/sql.Keith Pitt.rb | 142 +++++++++++++++++++++++++++++++++++ etc/todo/scanners/sql.rb | 138 ---------------------------------- 3 files changed, 280 insertions(+), 138 deletions(-) create mode 100644 etc/todo/scanners/sql.Josh Goebel.rb create mode 100644 etc/todo/scanners/sql.Keith Pitt.rb delete mode 100644 etc/todo/scanners/sql.rb diff --git a/etc/todo/scanners/sql.Josh Goebel.rb b/etc/todo/scanners/sql.Josh Goebel.rb new file mode 100644 index 0000000..57b5e8c --- /dev/null +++ b/etc/todo/scanners/sql.Josh Goebel.rb @@ -0,0 +1,138 @@ +# by Josh Goebel +module CodeRay module Scanners + + class SQL < Scanner + + register_for :sql + + RESERVED_WORDS = [ + 'create','table','index','trigger','drop', + 'primary','key', + 'select','insert','update','vacuum','delete','merge','replace','truncate', + 'into','on','from','values', + 'after','before', + 'and','or', + 'count','min','max','group','order','by','avg', + 'where','join','inner','outer','unique','union', + 'transaction', + 'begin','end', + ] + + PREDEFINED_TYPES = [ + 'char','varchar','enum','set','binary', + 'text','tinytext','mediumtext','longtext', + 'blob','tinyblob','mediumblob','longblob', + 'timestamp','date','time','datetime','year', + 'double','decimal','float', + 'int','integer','tinyint','mediumint','bigint', + 'bit','bool','boolean' + ] + + PREDEFINED_CONSTANTS = [ + 'null', 'true', 'false', 'not' + ] + + SQL_KIND= CaseIgnoringWordList.new(:ident). + add(RESERVED_WORDS, :reserved). + add(PREDEFINED_TYPES, :pre_type). + add(PREDEFINED_CONSTANTS, :pre_constant) + + IDENT_KIND = WordList.new(:ident) + + 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 + string_type = nil + + until eos? + + kind = :error + match = nil + + if state == :initial + + if scan(/ ^ -- .* $ /x) + kind = :comment + elsif scan(/ \s+ | \\\n /x) + kind = :space + + elsif scan(%r! // [^\n\\]* (?: \\. [^\n\\]* )* | /\* (?: .*? \*/ | .* ) !mx) + kind = :comment + + elsif match = scan(/ \# \s* if \s* 0 /x) + match << scan_until(/ ^\# (?:elif|else|endif) .*? $ | \z /xm) unless eos? + kind = :comment + + elsif scan(/ [-+*\/=<>?:;,!&^|()\[\]{}~%] | \.(?!\d) /x) + kind = :operator + + elsif match = scan(/ [A-Za-z_][A-Za-z_0-9]* /x) + kind = SQL_KIND[match.downcase] + kind = IDENT_KIND[match] if kind.nil? + + elsif match = scan(/[`"']/) + tokens << [:open, :string] + string_type = matched + state = :string + kind = :delimiter + + 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 + end + + elsif state == :string + if scan(/[^\\"'`]+/) + kind = :content + elsif scan(/["'`]/) + if string_type==matched + tokens << [matched, :delimiter] + tokens << [:close, :string] + state = :initial + string_type=nil + next + else + kind = :content + end + elsif scan(/ \\ (?: #{ESCAPE} | #{UNICODE_ESCAPE} ) /mox) + kind = :content + elsif scan(/ \\ | $ /x) + kind = :error + state = :initial + else + raise "else case \" reached; %p not handled." % peek(1), tokens + end + + else + raise 'else-case reached', tokens + + end + + match ||= matched +# raise [match, kind], tokens if kind == :error + + tokens << [match, kind] + + end +# RAILS_DEFAULT_LOGGER.info tokens.inspect + tokens + + end + + end + +end end \ No newline at end of file diff --git a/etc/todo/scanners/sql.Keith Pitt.rb b/etc/todo/scanners/sql.Keith Pitt.rb new file mode 100644 index 0000000..8b0f90c --- /dev/null +++ b/etc/todo/scanners/sql.Keith Pitt.rb @@ -0,0 +1,142 @@ +module CodeRay +module Scanners + + class SQL < Scanner + + register_for :sql + + include Streamable + + RESERVED_WORDS = %W( + all alter and any as asc at authid avg begin between + body bulk by case char check close cluster coalesce + collect comment commit compress connect constant create + current currval cursor day declare default delete + desc distinct do drop else elsif end exception exclusive + execute exists exit extends extract fetch for forall + from function goto group having heap hour if immediate in + index indicator insert interface intersect + interval into is isolation java level like limited lock + loop max min minus minute mlslabel mod mode month natural + naturaln new nextval nocopy not nowait null nullif + number_base ocirowid of on opaque open operator option or + order organization others out package partition pctfree + pls_integer positive positiven pragma prior private procedure + public raise range raw real record ref release return reverse + rollback row rowid rownum rowtype savepoint second select + separate set share space sql sqlcode sqlerrm start + stddev subtype successful sum synonym sysdate table then + timezone_region timezone_abbr timezone_minute + to trigger true type uid union unique update + use user validate values variance view when + whenever where while with work write year zone + ) + + PREDEFINED_TYPES = %W( + array bigint bit binary blob boolean binary_integer char + character clob date decimal double float char_base + int integer nchar nclob smallint timestamp long number + timestamp_hour timestamp_minute varchar varying smallint + varchar2 nvarchar money time + ) + + PREDEFINED_CONSTANTS = %W( + NULL true false' + ) + + IDENT_KIND = CaseIgnoringWordList.new(:ident). + add(RESERVED_WORDS, :reserved). + add(PREDEFINED_TYPES, :pre_type). + add(PREDEFINED_CONSTANTS, :pre_constant) + + 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 == :ident and check(/:(?!:)/) + match << scan(/:/) + kind = :label + end + + elsif match = scan(/'/) + tokens << [:open, :string] + state = :string + kind = :delimiter + + 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 << ["'", :delimiter] + 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 + + 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 diff --git a/etc/todo/scanners/sql.rb b/etc/todo/scanners/sql.rb deleted file mode 100644 index 57b5e8c..0000000 --- a/etc/todo/scanners/sql.rb +++ /dev/null @@ -1,138 +0,0 @@ -# by Josh Goebel -module CodeRay module Scanners - - class SQL < Scanner - - register_for :sql - - RESERVED_WORDS = [ - 'create','table','index','trigger','drop', - 'primary','key', - 'select','insert','update','vacuum','delete','merge','replace','truncate', - 'into','on','from','values', - 'after','before', - 'and','or', - 'count','min','max','group','order','by','avg', - 'where','join','inner','outer','unique','union', - 'transaction', - 'begin','end', - ] - - PREDEFINED_TYPES = [ - 'char','varchar','enum','set','binary', - 'text','tinytext','mediumtext','longtext', - 'blob','tinyblob','mediumblob','longblob', - 'timestamp','date','time','datetime','year', - 'double','decimal','float', - 'int','integer','tinyint','mediumint','bigint', - 'bit','bool','boolean' - ] - - PREDEFINED_CONSTANTS = [ - 'null', 'true', 'false', 'not' - ] - - SQL_KIND= CaseIgnoringWordList.new(:ident). - add(RESERVED_WORDS, :reserved). - add(PREDEFINED_TYPES, :pre_type). - add(PREDEFINED_CONSTANTS, :pre_constant) - - IDENT_KIND = WordList.new(:ident) - - 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 - string_type = nil - - until eos? - - kind = :error - match = nil - - if state == :initial - - if scan(/ ^ -- .* $ /x) - kind = :comment - elsif scan(/ \s+ | \\\n /x) - kind = :space - - elsif scan(%r! // [^\n\\]* (?: \\. [^\n\\]* )* | /\* (?: .*? \*/ | .* ) !mx) - kind = :comment - - elsif match = scan(/ \# \s* if \s* 0 /x) - match << scan_until(/ ^\# (?:elif|else|endif) .*? $ | \z /xm) unless eos? - kind = :comment - - elsif scan(/ [-+*\/=<>?:;,!&^|()\[\]{}~%] | \.(?!\d) /x) - kind = :operator - - elsif match = scan(/ [A-Za-z_][A-Za-z_0-9]* /x) - kind = SQL_KIND[match.downcase] - kind = IDENT_KIND[match] if kind.nil? - - elsif match = scan(/[`"']/) - tokens << [:open, :string] - string_type = matched - state = :string - kind = :delimiter - - 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 - end - - elsif state == :string - if scan(/[^\\"'`]+/) - kind = :content - elsif scan(/["'`]/) - if string_type==matched - tokens << [matched, :delimiter] - tokens << [:close, :string] - state = :initial - string_type=nil - next - else - kind = :content - end - elsif scan(/ \\ (?: #{ESCAPE} | #{UNICODE_ESCAPE} ) /mox) - kind = :content - elsif scan(/ \\ | $ /x) - kind = :error - state = :initial - else - raise "else case \" reached; %p not handled." % peek(1), tokens - end - - else - raise 'else-case reached', tokens - - end - - match ||= matched -# raise [match, kind], tokens if kind == :error - - tokens << [match, kind] - - end -# RAILS_DEFAULT_LOGGER.info tokens.inspect - tokens - - end - - end - -end end \ No newline at end of file -- cgit v1.2.1