coderay 0.7.4.215 → 0.8.260

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. data/LICENSE +421 -257
  2. data/README +24 -13
  3. data/bin/coderay +9 -4
  4. data/lib/coderay.rb +19 -17
  5. data/lib/coderay/duo.rb +67 -9
  6. data/lib/coderay/encoder.rb +18 -9
  7. data/lib/coderay/encoders/_map.rb +2 -1
  8. data/lib/coderay/encoders/debug.rb +14 -11
  9. data/lib/coderay/encoders/html.rb +44 -17
  10. data/lib/coderay/encoders/html/css.rb +13 -8
  11. data/lib/coderay/encoders/html/numerization.rb +8 -6
  12. data/lib/coderay/encoders/html/output.rb +3 -1
  13. data/lib/coderay/encoders/statistic.rb +2 -6
  14. data/lib/coderay/encoders/text.rb +2 -3
  15. data/lib/coderay/encoders/tokens.rb +3 -3
  16. data/lib/coderay/encoders/xml.rb +1 -2
  17. data/lib/coderay/for_redcloth.rb +72 -0
  18. data/lib/coderay/helpers/file_type.rb +38 -9
  19. data/lib/coderay/helpers/gzip_simple.rb +1 -0
  20. data/lib/coderay/helpers/plugin.rb +15 -8
  21. data/lib/coderay/helpers/word_list.rb +4 -0
  22. data/lib/coderay/scanner.rb +30 -13
  23. data/lib/coderay/scanners/_map.rb +1 -1
  24. data/lib/coderay/scanners/c.rb +3 -1
  25. data/lib/coderay/scanners/css.rb +181 -0
  26. data/lib/coderay/scanners/debug.rb +1 -0
  27. data/lib/coderay/scanners/delphi.rb +1 -0
  28. data/lib/coderay/scanners/diff.rb +104 -0
  29. data/lib/coderay/scanners/java.rb +179 -0
  30. data/lib/coderay/scanners/java/builtin_types.rb +419 -0
  31. data/lib/coderay/scanners/java_script.rb +187 -0
  32. data/lib/coderay/scanners/json.rb +106 -0
  33. data/lib/coderay/scanners/nitro_xhtml.rb +5 -4
  34. data/lib/coderay/scanners/plaintext.rb +2 -0
  35. data/lib/coderay/scanners/rhtml.rb +2 -2
  36. data/lib/coderay/scanners/ruby.rb +64 -50
  37. data/lib/coderay/scanners/ruby/patterns.rb +15 -19
  38. data/lib/coderay/scanners/scheme.rb +142 -0
  39. data/lib/coderay/scanners/sql.Keith.rb +143 -0
  40. data/lib/coderay/scanners/sql.rb +154 -0
  41. data/lib/coderay/scanners/xml.rb +1 -0
  42. data/lib/coderay/styles/cycnus.rb +30 -9
  43. data/lib/coderay/styles/murphy.rb +15 -2
  44. data/lib/coderay/{encoders/html/classes.rb → token_classes.rb} +14 -9
  45. data/lib/coderay/tokens.rb +33 -14
  46. data/lib/term/ansicolor.rb +220 -0
  47. metadata +62 -44
@@ -0,0 +1,143 @@
1
+ # by Keith Pitt
2
+ module CodeRay
3
+ module Scanners
4
+
5
+ class SQL < Scanner
6
+
7
+ register_for :sql
8
+
9
+ include Streamable
10
+
11
+ RESERVED_WORDS = %w(
12
+ all alter and any as asc at authid avg begin between
13
+ body bulk by case char check close cluster coalesce
14
+ collect comment commit compress connect constant create
15
+ current currval cursor day declare default delete
16
+ desc distinct do drop else elsif end exception exclusive
17
+ execute exists exit extends extract fetch for forall
18
+ from function goto group having heap hour if immediate in
19
+ index indicator insert interface intersect
20
+ interval into is isolation java level like limited lock
21
+ loop max min minus minute mlslabel mod mode month natural
22
+ naturaln new nextval nocopy not nowait null nullif
23
+ number_base ocirowid of on opaque open operator option or
24
+ order organization others out package partition pctfree
25
+ pls_integer positive positiven pragma prior private procedure
26
+ public raise range raw real record ref release return reverse
27
+ rollback row rowid rownum rowtype savepoint second select
28
+ separate set share space sql sqlcode sqlerrm start
29
+ stddev subtype successful sum synonym sysdate table then
30
+ timezone_region timezone_abbr timezone_minute
31
+ to trigger true type uid union unique update
32
+ use user validate values variance view when
33
+ whenever where while with work write year zone
34
+ )
35
+
36
+ PREDEFINED_TYPES = %w(
37
+ array bigint bit binary blob boolean binary_integer char
38
+ character clob date decimal double float char_base
39
+ int integer nchar nclob smallint timestamp long number
40
+ timestamp_hour timestamp_minute varchar varying smallint
41
+ varchar2 nvarchar money time
42
+ )
43
+
44
+ PREDEFINED_CONSTANTS = %w(
45
+ NULL true false
46
+ )
47
+
48
+ IDENT_KIND = CaseIgnoringWordList.new(:ident).
49
+ add(RESERVED_WORDS, :reserved).
50
+ add(PREDEFINED_TYPES, :pre_type).
51
+ add(PREDEFINED_CONSTANTS, :pre_constant)
52
+
53
+ def scan_tokens tokens, options
54
+
55
+ state = :initial
56
+
57
+ until eos?
58
+
59
+ kind = nil
60
+ match = nil
61
+
62
+ case state
63
+
64
+ when :initial
65
+
66
+ if scan(/ \s+ | \\\n /x)
67
+ kind = :space
68
+
69
+ elsif scan(%r! -- [^\n\\]* (?: \\. [^\n\\]* )* | /\* (?: .*? \*/ | .* ) !mx)
70
+ kind = :comment
71
+
72
+ elsif scan(/ [-+*\/=<>?:;,!&^|()~%]+ | \.(?!\d) /x)
73
+ kind = :operator
74
+
75
+ elsif match = scan(/ [A-Za-z_][A-Za-z_0-9]* /x)
76
+ kind = IDENT_KIND[match]
77
+ if kind == :ident and check(/:(?!:)/)
78
+ match << scan(/:/)
79
+ kind = :label
80
+ end
81
+
82
+ elsif match = scan(/'/)
83
+ tokens << [:open, :string]
84
+ state = :string
85
+ kind = :delimiter
86
+
87
+ elsif scan(/(?:\d+)(?![.eEfF])/)
88
+ kind = :integer
89
+
90
+ elsif scan(/\d[fF]?|\d*\.\d+(?:[eE][+-]?\d+)?[fF]?|\d+[eE][+-]?\d+[fF]?/)
91
+ kind = :float
92
+
93
+ else
94
+ getch
95
+ kind = :error
96
+
97
+ end
98
+
99
+ when :string
100
+ if scan(/[^\\\n']+/)
101
+ kind = :content
102
+ elsif scan(/'/)
103
+ tokens << ["'", :delimiter]
104
+ tokens << [:close, :string]
105
+ state = :initial
106
+ next
107
+ elsif scan(/ \\ (?: #{ESCAPE} | #{UNICODE_ESCAPE} ) /mox)
108
+ kind = :char
109
+ elsif scan(/ \\ | $ /x)
110
+ tokens << [:close, :string]
111
+ kind = :error
112
+ state = :initial
113
+ else
114
+ raise_inspect "else case \" reached; %p not handled." % peek(1), tokens
115
+ end
116
+
117
+ else
118
+ raise_inspect 'Unknown state', tokens
119
+
120
+ end
121
+
122
+ match ||= matched
123
+ if $DEBUG and not kind
124
+ raise_inspect 'Error token %p in line %d' %
125
+ [[match, kind], line], tokens
126
+ end
127
+ raise_inspect 'Empty token', tokens unless match
128
+
129
+ tokens << [match, kind]
130
+
131
+ end
132
+
133
+ if state == :string
134
+ tokens << [:close, :string]
135
+ end
136
+
137
+ tokens
138
+ end
139
+
140
+ end
141
+
142
+ end
143
+ end
@@ -0,0 +1,154 @@
1
+ # by Josh Goebel
2
+ module CodeRay module Scanners
3
+
4
+ class SQL < Scanner
5
+
6
+ register_for :sql
7
+
8
+ RESERVED_WORDS = %w(
9
+ create table index trigger drop primary key set select
10
+ insert update delete replace into
11
+ on from values before and or if exists case when
12
+ then else as group order by avg where
13
+ join inner outer union engine not
14
+ like
15
+ )
16
+
17
+ PREDEFINED_TYPES = %w(
18
+ char varchar enum binary text tinytext mediumtext
19
+ longtext blob tinyblob mediumblob longblob timestamp
20
+ date time datetime year double decimal float int
21
+ integer tinyint mediumint bigint smallint unsigned bit
22
+ bool boolean
23
+ )
24
+
25
+ PREDEFINED_FUNCTIONS = %w( sum cast abs pi count min max avg )
26
+
27
+ DIRECTIVES = %w( auto_increment unique default charset )
28
+
29
+ PREDEFINED_CONSTANTS = %w( null true false )
30
+
31
+ IDENT_KIND = CaseIgnoringWordList.new(:ident).
32
+ add(RESERVED_WORDS, :reserved).
33
+ add(PREDEFINED_TYPES, :pre_type).
34
+ add(PREDEFINED_CONSTANTS, :pre_constant).
35
+ add(PREDEFINED_FUNCTIONS, :predefined).
36
+ add(DIRECTIVES, :directive)
37
+
38
+ ESCAPE = / [rbfnrtv\n\\\/'"] | x[a-fA-F0-9]{1,2} | [0-7]{1,3} /x
39
+ UNICODE_ESCAPE = / u[a-fA-F0-9]{4} | U[a-fA-F0-9]{8} /x
40
+
41
+ def scan_tokens tokens, options
42
+
43
+ state = :initial
44
+ string_type = nil
45
+ string_content = ''
46
+
47
+ until eos?
48
+
49
+ kind = nil
50
+ match = nil
51
+
52
+ if state == :initial
53
+
54
+ if scan(/ \s+ | \\\n /x)
55
+ kind = :space
56
+
57
+ elsif scan(/^(?:--\s|#).*/)
58
+ kind = :comment
59
+
60
+ elsif scan(%r! /\* (?: .*? \*/ | .* ) !mx)
61
+ kind = :comment
62
+
63
+ elsif scan(/ [-+*\/=<>;,!&^|()\[\]{}~%] | \.(?!\d) /x)
64
+ kind = :operator
65
+
66
+ elsif match = scan(/ [A-Za-z_][A-Za-z_0-9]* /x)
67
+ kind = IDENT_KIND[match.downcase]
68
+
69
+ elsif match = scan(/[`"']/)
70
+ tokens << [:open, :string]
71
+ string_type = matched
72
+ state = :string
73
+ kind = :delimiter
74
+
75
+ elsif scan(/0[xX][0-9A-Fa-f]+/)
76
+ kind = :hex
77
+
78
+ elsif scan(/0[0-7]+(?![89.eEfF])/)
79
+ kind = :oct
80
+
81
+ elsif scan(/\d+(?![.eEfF])/)
82
+ kind = :integer
83
+
84
+ elsif scan(/\d[fF]?|\d*\.\d+(?:[eE][+-]?\d+)?[fF]?|\d+[eE][+-]?\d+[fF]?/)
85
+ kind = :float
86
+
87
+ else
88
+ getch
89
+ kind = :error
90
+
91
+ end
92
+
93
+ elsif state == :string
94
+ if match = scan(/[^\\"'`]+/)
95
+ string_content << match
96
+ next
97
+ elsif match = scan(/["'`]/)
98
+ if string_type == match
99
+ if peek(1) == string_type # doubling means escape
100
+ string_content << string_type << getch
101
+ next
102
+ end
103
+ unless string_content.empty?
104
+ tokens << [string_content, :content]
105
+ string_content = ''
106
+ end
107
+ tokens << [matched, :delimiter]
108
+ tokens << [:close, :string]
109
+ state = :initial
110
+ string_type = nil
111
+ next
112
+ else
113
+ string_content << match
114
+ end
115
+ next
116
+ elsif scan(/ \\ (?: #{ESCAPE} | #{UNICODE_ESCAPE} ) /mox)
117
+ unless string_content.empty?
118
+ tokens << [string_content, :content]
119
+ string_content = ''
120
+ end
121
+ kind = :char
122
+ elsif match = scan(/ \\ . /mox)
123
+ string_content << match
124
+ next
125
+ elsif scan(/ \\ | $ /x)
126
+ unless string_content.empty?
127
+ tokens << [string_content, :content]
128
+ string_content = ''
129
+ end
130
+ kind = :error
131
+ state = :initial
132
+ else
133
+ raise "else case \" reached; %p not handled." % peek(1), tokens
134
+ end
135
+
136
+ else
137
+ raise 'else-case reached', tokens
138
+
139
+ end
140
+
141
+ match ||= matched
142
+ # raise [match, kind], tokens if kind == :error
143
+
144
+ tokens << [match, kind]
145
+
146
+ end
147
+ # RAILS_DEFAULT_LOGGER.info tokens.inspect
148
+ tokens
149
+
150
+ end
151
+
152
+ end
153
+
154
+ end end
@@ -11,6 +11,7 @@ module Scanners
11
11
  class XML < HTML
12
12
 
13
13
  register_for :xml
14
+ file_extension 'xml'
14
15
 
15
16
  end
16
17
 
@@ -42,12 +42,15 @@ ol.CodeRay li { white-space: pre }
42
42
  MAIN
43
43
 
44
44
  TOKEN_COLORS = <<-'TOKENS'
45
+ .debug { color:white ! important; background:blue ! important; }
46
+
45
47
  .af { color:#00C }
46
48
  .an { color:#007 }
49
+ .at { color:#f08 }
47
50
  .av { color:#700 }
48
51
  .aw { color:#C00 }
49
52
  .bi { color:#509; font-weight:bold }
50
- .c { color:#888 }
53
+ .c { color:#666; }
51
54
 
52
55
  .ch { color:#04D }
53
56
  .ch .k { color:#04D }
@@ -78,18 +81,25 @@ ol.CodeRay li { white-space: pre }
78
81
  .il .il .il { background: #ccc }
79
82
  .il .idl { font-weight: bold; color: #888 }
80
83
 
84
+ .im { color:#f00; }
81
85
  .in { color:#B2B; font-weight:bold }
82
86
  .iv { color:#33B }
83
87
  .la { color:#970; font-weight:bold }
84
88
  .lv { color:#963 }
85
89
  .oc { color:#40E; font-weight:bold }
86
- .on { color:#000; font-weight:bold }
90
+ .of { color:#000; font-weight:bold }
87
91
  .op { }
88
92
  .pc { color:#038; font-weight:bold }
89
93
  .pd { color:#369; font-weight:bold }
90
- .pp { color:#579 }
94
+ .pp { color:#579; }
95
+ .ps { color:#00C; font-weight: bold; }
91
96
  .pt { color:#339; font-weight:bold }
92
- .r { color:#080; font-weight:bold }
97
+ .r, .kw { color:#080; font-weight:bold }
98
+
99
+ .ke { color: #808; }
100
+ .ke .dl { color: #606; }
101
+ .ke .ch { color: #80f; }
102
+ .vl { color: #088; }
93
103
 
94
104
  .rx { background-color:#fff0ff }
95
105
  .rx .k { color:#808 }
@@ -97,11 +107,12 @@ ol.CodeRay li { white-space: pre }
97
107
  .rx .mod { color:#C2C }
98
108
  .rx .fu { color:#404; font-weight: bold }
99
109
 
100
- .s { background-color:#fff0f0 }
101
- .s .s { background-color:#ffe0e0 }
102
- .s .s .s { background-color:#ffd0d0 }
103
- .s .k { color:#D20 }
104
- .s .dl { color:#710 }
110
+ .s { background-color:#fff0f0 }
111
+ .s .s { background-color:#ffe0e0 }
112
+ .s .s .s { background-color:#ffd0d0 }
113
+ .s .k { color: #D20; }
114
+ .s .ch { color: #b0b; }
115
+ .s .dl { color: #710; }
105
116
 
106
117
  .sh { background-color:#f0fff0 }
107
118
  .sh .k { color:#2B2 }
@@ -117,6 +128,16 @@ ol.CodeRay li { white-space: pre }
117
128
  .ty { color:#339; font-weight:bold }
118
129
  .v { color:#036 }
119
130
  .xt { color:#444 }
131
+
132
+ .ins { background: #afa; }
133
+ .del { background: #faa; }
134
+ .chg { color: #aaf; background: #007; }
135
+ .head { color: #f8f; background: #505 }
136
+
137
+ .ins .ins { color: #080; font-weight:bold }
138
+ .del .del { color: #800; font-weight:bold }
139
+ .chg .chg { color: #66f; }
140
+ .head .head { color: #f4f; }
120
141
  TOKENS
121
142
 
122
143
  end
@@ -47,7 +47,7 @@ ol.CodeRay li { white-space: pre; }
47
47
  .av { color:#700; }
48
48
  .aw { color:#C00; }
49
49
  .bi { color:#509; font-weight:bold; }
50
- .c { color:#666; }
50
+ .c { color:#555; background-color: black; }
51
51
 
52
52
  .ch { color:#88F; }
53
53
  .ch .k { color:#04D; }
@@ -77,13 +77,16 @@ ol.CodeRay li { white-space: pre; }
77
77
  .la { color:#970; font-weight:bold; }
78
78
  .lv { color:#963; }
79
79
  .oc { color:#40E; font-weight:bold; }
80
- .on { color:#000; font-weight:bold; }
80
+ .of { color:#000; font-weight:bold; }
81
81
  .op { }
82
82
  .pc { color:#08f; font-weight:bold; }
83
83
  .pd { color:#369; font-weight:bold; }
84
84
  .pp { color:#579; }
85
85
  .pt { color:#66f; font-weight:bold; }
86
86
  .r { color:#5de; font-weight:bold; }
87
+ .r, .kw { color:#5de; font-weight:bold }
88
+
89
+ .ke { color: #808; }
87
90
 
88
91
  .rx { background-color:#221133; }
89
92
  .rx .k { color:#f8f; }
@@ -111,6 +114,16 @@ ol.CodeRay li { white-space: pre; }
111
114
  .ty { color:#339; font-weight:bold; }
112
115
  .v { color:#036; }
113
116
  .xt { color:#444; }
117
+
118
+ .ins { background: #afa; }
119
+ .del { background: #faa; }
120
+ .chg { color: #aaf; background: #007; }
121
+ .head { color: #f8f; background: #505 }
122
+
123
+ .ins .ins { color: #080; font-weight:bold }
124
+ .del .del { color: #800; font-weight:bold }
125
+ .chg .chg { color: #66f; }
126
+ .head .head { color: #f4f; }
114
127
  TOKENS
115
128
 
116
129
  end
@@ -1,12 +1,10 @@
1
1
  module CodeRay
2
- module Encoders
3
-
4
- class HTML
5
-
2
+ class Tokens
6
3
  ClassOfKind = Hash.new do |h, k|
7
4
  h[k] = k.to_s
8
5
  end
9
6
  ClassOfKind.update with = {
7
+ :annotation => 'at',
10
8
  :attribute_name => 'an',
11
9
  :attribute_name_fat => 'af',
12
10
  :attribute_value => 'av',
@@ -32,21 +30,25 @@ module Encoders
32
30
  :function => 'fu',
33
31
  :global_variable => 'gv',
34
32
  :hex => 'hx',
33
+ :important => 'im',
35
34
  :include => 'ic',
36
35
  :inline => 'il',
37
36
  :inline_delimiter => 'idl',
38
37
  :instance_variable => 'iv',
39
38
  :integer => 'i',
40
39
  :interpreted => 'in',
40
+ :keyword => 'kw',
41
+ :key => 'ke',
41
42
  :label => 'la',
42
43
  :local_variable => 'lv',
43
44
  :modifier => 'mod',
44
45
  :oct => 'oc',
45
- :operator_name => 'on',
46
+ :operator_fat => 'of',
46
47
  :pre_constant => 'pc',
47
48
  :pre_type => 'pt',
48
49
  :predefined => 'pd',
49
50
  :preprocessor => 'pp',
51
+ :pseudo_class => 'ps',
50
52
  :regexp => 'rx',
51
53
  :reserved => 'r',
52
54
  :shell => 'sh',
@@ -57,7 +59,13 @@ module Encoders
57
59
  :tag_special => 'ts',
58
60
  :type => 'ty',
59
61
  :variable => 'v',
62
+ :value => 'vl',
60
63
  :xml_text => 'xt',
64
+
65
+ :insert => 'ins',
66
+ :delete => 'del',
67
+ :change => 'chg',
68
+ :head => 'head',
61
69
 
62
70
  :ident => :NO_HIGHLIGHT, # 'id'
63
71
  #:operator => 'op',
@@ -70,8 +78,5 @@ module Encoders
70
78
  ClassOfKind[:nesting_delimiter] = ClassOfKind[:delimiter]
71
79
  ClassOfKind[:escape] = ClassOfKind[:delimiter]
72
80
  #ClassOfKind.default = ClassOfKind[:error] or raise 'no class found for :error!'
73
-
74
81
  end
75
-
76
- end
77
- end
82
+ end