diff options
author | murphy <murphy@rubychan.de> | 2010-03-21 09:21:34 +0000 |
---|---|---|
committer | murphy <murphy@rubychan.de> | 2010-03-21 09:21:34 +0000 |
commit | c4ea49e6c7844dc7a1324859a7d331633b4b8bab (patch) | |
tree | fb25f138893d70f8c307597d7518b55d8c04078c /lib/coderay/scanners | |
parent | 67deabc8f18ef1874d2485bc354f74f20c81966e (diff) | |
download | coderay-c4ea49e6c7844dc7a1324859a7d331633b4b8bab.tar.gz |
Improvements to the SQL scanner - more keywords, more colors :)
Diffstat (limited to 'lib/coderay/scanners')
-rw-r--r-- | lib/coderay/scanners/sql.rb | 34 |
1 files changed, 24 insertions, 10 deletions
diff --git a/lib/coderay/scanners/sql.rb b/lib/coderay/scanners/sql.rb index 2b21c79..993afd5 100644 --- a/lib/coderay/scanners/sql.rb +++ b/lib/coderay/scanners/sql.rb @@ -6,12 +6,21 @@ module CodeRay module Scanners register_for :sql RESERVED_WORDS = %w( - create database table index trigger drop primary key set select - insert update delete replace into - on from values before and or if exists case when - then else as group order by avg where - join inner outer union engine not - like end using collate show columns begin + all and as before begin by case collate + constraint create else end engine exists + for foreign from group if inner is join key + like not on or order outer primary references replace + then to trigger union using values when where + left + ) + + OBJECTS = %w( + database databases table tables column columns index + ) + + COMMANDS = %w( + add alter comment create delete drop grant insert into select update set + show ) PREDEFINED_TYPES = %w( @@ -22,14 +31,16 @@ module CodeRay module Scanners bool boolean hex bin oct ) - PREDEFINED_FUNCTIONS = %w( sum cast abs pi count min max avg ) + PREDEFINED_FUNCTIONS = %w( sum cast substring abs pi count min max avg ) DIRECTIVES = %w( auto_increment unique default charset ) - + PREDEFINED_CONSTANTS = %w( null true false ) IDENT_KIND = CaseIgnoringWordList.new(:ident). add(RESERVED_WORDS, :reserved). + add(OBJECTS, :type). + add(COMMANDS, :class). add(PREDEFINED_TYPES, :pre_type). add(PREDEFINED_CONSTANTS, :pre_constant). add(PREDEFINED_FUNCTIONS, :predefined). @@ -59,8 +70,8 @@ module CodeRay module Scanners elsif scan(/^(?:--\s?|#).*/) kind = :comment - elsif scan(%r! /\* (?: .*? \*/ | .* ) !mx) - kind = :comment + elsif scan(%r( /\* (!)? (?: .*? \*/ | .* ) )mx) + kind = self[1] ? :directive : :comment elsif scan(/ [-+*\/=<>;,!&^|()\[\]{}~%] | \.(?!\d) /x) kind = :operator @@ -88,6 +99,9 @@ module CodeRay module Scanners elsif scan(/\d[fF]|\d*\.\d+(?:[eE][+-]?\d+)?|\d+[eE][+-]?\d+/) kind = :float + + elsif scan(/\\N/) + kind = :pre_constant else getch |