coderay 0.9.1 → 0.9.2

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile ADDED
@@ -0,0 +1,35 @@
1
+ require 'rake/rdoctask'
2
+
3
+ ROOT = '.'
4
+ LIB_ROOT = File.join ROOT, 'lib'
5
+ EXTRA_RDOC_FILES = %w(lib/README FOLDERS)
6
+
7
+ task :default => :test
8
+
9
+ if File.directory? 'rake_tasks'
10
+
11
+ # load rake tasks from subfolder
12
+ for task_file in Dir['rake_tasks/*.rake'].sort
13
+ load task_file
14
+ end
15
+
16
+ else
17
+
18
+ # fallback tasks when rake_tasks folder is not present
19
+ desc 'Run CodeRay tests (basic)'
20
+ task :test do
21
+ ruby './test/functional/suite.rb'
22
+ ruby './test/functional/for_redcloth.rb'
23
+ end
24
+
25
+ desc 'Generate documentation for CodeRay'
26
+ Rake::RDocTask.new :doc do |rd|
27
+ rd.title = 'CodeRay Documentation'
28
+ rd.main = 'lib/README'
29
+ rd.rdoc_files.add Dir['lib']
30
+ rd.rdoc_files.add 'lib/README'
31
+ rd.rdoc_files.add 'FOLDERS'
32
+ rd.rdoc_dir = 'doc'
33
+ end
34
+
35
+ end
data/lib/README CHANGED
@@ -18,7 +18,7 @@ And with line numbers.
18
18
  * is what everybody should have on their website
19
19
  * solves all your problems and makes the girls run after you
20
20
 
21
- Version: 0.9.1
21
+ Version: 0.9.2
22
22
  Author:: murphy (Kornelius Kalnbach)
23
23
  Contact:: murphy rubychan de
24
24
  Website:: coderay.rubychan.de[http://coderay.rubychan.de]
@@ -82,14 +82,18 @@ Please report errors in this documentation to <murphy rubychan de>.
82
82
  * Andreas Schwarz for finding out that CaseIgnoringWordList was not case
83
83
  ignoring! Such things really make you write tests.
84
84
  * closure for the first version of the Scheme scanner.
85
- * Stefan Walk for the first version of the JavaScript scanner.
86
- * Josh Goebel for another version of the JavaScript scanner and a Diff scanner.
85
+ * Stefan Walk for the first version of the JavaScript and PHP scanners.
86
+ * Josh Goebel for another version of the JavaScript scanner, a SQL and a Diff scanner.
87
87
  * Jonathan Younger for pointing out the licence confusion caused by wrong LICENSE file.
88
88
  * Jeremy Hinegardner for finding the shebang-on-empty-file bug in FileType.
89
89
  * Charles Oliver Nutter and Yehuda Katz for helping me benchmark CodeRay on JRuby.
90
90
  * Andreas Neuhaus for pointing out a markup bug in coderay/for_redcloth.
91
91
  * 0xf30fc7 for the FileType patch concerning Delphi file extensions.
92
92
  * The folks at redmine.org - thank you for using and fixing CodeRay!
93
+ * Keith Pitt for his SQL scanners
94
+ * Rob Aldred for the terminal encoder
95
+ * Trans for pointing out $DEBUG dependencies
96
+ * Flameeyes for finding that Term::ANSIColor was obsolete
93
97
  * matz and all Ruby gods and gurus
94
98
  * The inventors of: the computer, the internet, the true color display, HTML &
95
99
  CSS, VIM, Ruby, pizza, microwaves, guitars, scouting, programming, anime,
data/lib/coderay.rb CHANGED
@@ -14,7 +14,7 @@
14
14
  #
15
15
  # Here's a fancy graphic to light up this gray docu:
16
16
  #
17
- # http://rd.cYcnus.de/coderay/scheme.png
17
+ # http://cycnus.de/raindark/coderay/scheme.png
18
18
  #
19
19
  # == Documentation
20
20
  #
@@ -126,13 +126,15 @@
126
126
  # If you want to re-use scanners and encoders (because that is faster), see
127
127
  # CodeRay::Duo for the most convenient (and recommended) interface.
128
128
  module CodeRay
129
-
129
+
130
+ $CODERAY_DEBUG ||= false
131
+
130
132
  # Version: Major.Minor.Teeny[.Revision]
131
133
  # Major: 0 for pre-stable, 1 for stable
132
134
  # Minor: feature milestone
133
135
  # Teeny: development state, 0 for pre-release
134
136
  # Revision: Subversion Revision number (generated on rake gem:make)
135
- VERSION = '0.9.1'
137
+ VERSION = '0.9.2'
136
138
 
137
139
  require 'coderay/tokens'
138
140
  require 'coderay/token_classes'
@@ -5,6 +5,7 @@ module Encoders
5
5
  :loc => :lines_of_code,
6
6
  :plain => :text,
7
7
  :stats => :statistic,
8
+ :terminal => :term,
8
9
  :tex => :latex
9
10
 
10
11
  end
@@ -264,7 +264,7 @@ module Encoders
264
264
  if @opened.empty?
265
265
  # nothing to close
266
266
  else
267
- if $DEBUG and (@opened.size == 1 or @opened.last != type)
267
+ if $CODERAY_DEBUG and (@opened.size == 1 or @opened.last != type)
268
268
  raise 'Malformed token stream: Trying to close a token (%p) \
269
269
  that is not open. Open are: %p.' % [type, @opened[1..-1]]
270
270
  end
@@ -285,7 +285,7 @@ module Encoders
285
285
  if @opened.empty?
286
286
  # nothing to close
287
287
  else
288
- if $DEBUG and (@opened.size == 1 or @opened.last != type)
288
+ if $CODERAY_DEBUG and (@opened.size == 1 or @opened.last != type)
289
289
  raise 'Malformed token stream: Trying to close a line (%p) \
290
290
  that is not open. Open are: %p.' % [type, @opened[1..-1]]
291
291
  end
@@ -27,7 +27,7 @@ module Encoders
27
27
  1.upto(styles.size) do |offset|
28
28
  break if style = cl[styles[offset .. -1]]
29
29
  end
30
- $stderr.puts 'Style not found: %p' % [styles] if $DEBUG and style.empty?
30
+ # warn 'Style not found: %p' % [styles] if style.empty?
31
31
  return style
32
32
  end
33
33
 
@@ -25,7 +25,7 @@ module Encoders
25
25
  if scanner = tokens.scanner
26
26
  kinds_not_loc = scanner.class::KINDS_NOT_LOC
27
27
  else
28
- warn ArgumentError, 'Tokens have no scanner.' if $DEBUG
28
+ warn ArgumentError, 'Tokens have no scanner.' if $VERBOSE
29
29
  kinds_not_loc = CodeRay::Scanners::Scanner::KINDS_NOT_LOC
30
30
  end
31
31
  code = tokens.token_class_filter :exclude => kinds_not_loc
@@ -12,6 +12,7 @@ module CodeRay
12
12
  register_for :term
13
13
 
14
14
  TOKEN_COLORS = {
15
+ :annotation => '35',
15
16
  :attribute_name => '33',
16
17
  :attribute_name_fat => '33',
17
18
  :attribute_value => '31',
@@ -22,10 +23,13 @@ module CodeRay
22
23
  :class_variable => '36',
23
24
  :color => '32',
24
25
  :comment => '37',
26
+ :complex => '34',
25
27
  :constant => ['34', '4'],
28
+ :decoration => '35',
26
29
  :definition => '1;32',
27
30
  :directive => ['32', '4'],
28
31
  :doc => '46',
32
+ :doctype => '1;30',
29
33
  :doc_string => ['31', '4'],
30
34
  :entity => '33',
31
35
  :error => ['1;33', '41'],
@@ -34,9 +38,11 @@ module CodeRay
34
38
  :function => '1;34',
35
39
  :global_variable => '42',
36
40
  :hex => '1;36',
41
+ :important => '1;31',
37
42
  :include => '33',
38
43
  :integer => '1;34',
39
44
  :interpreted => '1;35',
45
+ :key => '35',
40
46
  :label => '1;4',
41
47
  :local_variable => '33',
42
48
  :oct => '1;35',
@@ -45,6 +51,7 @@ module CodeRay
45
51
  :pre_type => '1;30',
46
52
  :predefined => ['4', '1;34'],
47
53
  :preprocessor => '36',
54
+ :pseudo_class => '34',
48
55
  :regexp => {
49
56
  :content => '31',
50
57
  :delimiter => '1;29',
@@ -52,16 +59,32 @@ module CodeRay
52
59
  :function => '1;29'
53
60
  },
54
61
  :reserved => '1;31',
55
- :shell => {:self => '42', :content => '1;29'},
56
- :string => '32',
62
+ :shell => {
63
+ :self => '42',
64
+ :content => '1;29',
65
+ :delimiter => '37',
66
+ },
67
+ :string => {
68
+ :self => '32',
69
+ :modifier => '1;32',
70
+ :escape => '1;36',
71
+ :delimiter => '1;32',
72
+ },
57
73
  :symbol => '1;32',
58
74
  :tag => '34',
59
75
  :tag_fat => '1;34',
60
76
  :tag_special => ['34', '4'],
61
77
  :type => '1;34',
62
- :variable => '34'
78
+ :value => '36',
79
+ :variable => '34',
80
+ :insert => '42',
81
+ :delete => '41',
82
+ :change => '44',
83
+ :head => '45',
63
84
  }
64
- TOKEN_COLORS[:procedure] = TOKEN_COLORS[:method] = TOKEN_COLORS[:function]
85
+ TOKEN_COLORS[:keyword] = TOKEN_COLORS[:reserved]
86
+ TOKEN_COLORS[:method] = TOKEN_COLORS[:function]
87
+ TOKEN_COLORS[:imaginary] = TOKEN_COLORS[:complex]
65
88
  TOKEN_COLORS[:open] = TOKEN_COLORS[:close] = TOKEN_COLORS[:nesting_delimiter] = TOKEN_COLORS[:escape] = TOKEN_COLORS[:delimiter]
66
89
 
67
90
  protected
@@ -110,9 +133,7 @@ module CodeRay
110
133
  if @opened.empty?
111
134
  # nothing to close
112
135
  else
113
- if (@subcolors || {})[:self]
114
- @out << col(0)
115
- end
136
+ @out << col(0) if (@subcolors || {})[:self]
116
137
  @subcolors = nil
117
138
  @opened.pop
118
139
  end
@@ -13,10 +13,20 @@ module CodeRay
13
13
  module ForRedCloth
14
14
 
15
15
  def self.install
16
- gem 'RedCloth', '>= 4.0.3' rescue nil
16
+ gem 'RedCloth', '>= 4.0.3' if defined? gem
17
17
  require 'redcloth'
18
18
  unless RedCloth::VERSION.to_s >= '4.0.3'
19
- raise 'CodeRay.for_redcloth needs RedCloth version 4.0.3 or later.'
19
+ if defined? gem
20
+ raise 'CodeRay.for_redcloth needs RedCloth version 4.0.3 or later. ' +
21
+ "You have #{RedCloth::VERSION}. Please gem install RedCloth."
22
+ else
23
+ $".delete 'redcloth.rb' # sorry, but it works
24
+ require 'rubygems'
25
+ return install # retry
26
+ end
27
+ end
28
+ unless RedCloth::VERSION.to_s >= '4.2.2'
29
+ warn 'CodeRay.for_redcloth works best with RedCloth version 4.2.2 or later.'
20
30
  end
21
31
  RedCloth::TextileDoc.send :include, ForRedCloth::TextileDoc
22
32
  RedCloth::Formatters::HTML.module_eval do
@@ -214,7 +214,7 @@ protected
214
214
  mapfile = path_to '_map'
215
215
  if File.exist? mapfile
216
216
  require mapfile
217
- elsif $DEBUG
217
+ elsif $VERBOSE
218
218
  warn 'no _map.rb found for %s' % name
219
219
  end
220
220
  end
@@ -69,11 +69,14 @@ module CodeRay
69
69
  def normify code
70
70
  code = code.to_s
71
71
  if code.respond_to? :force_encoding
72
+ debug, $DEBUG = $DEBUG, false
72
73
  begin
73
74
  code.force_encoding 'utf-8'
74
75
  code[/\z/] # raises an ArgumentError when code contains a non-UTF-8 char
75
76
  rescue ArgumentError
76
77
  code.force_encoding 'binary'
78
+ ensure
79
+ $DEBUG = debug
77
80
  end
78
81
  end
79
82
  code.to_unix
@@ -200,7 +203,7 @@ module CodeRay
200
203
  return 0 if pos <= 0
201
204
  string = string()
202
205
  if string.respond_to?(:bytesize) && (defined?(@bin_string) || string.bytesize != string.size)
203
- @bin_string ||= string.dup.force_encoding(:binary)
206
+ @bin_string ||= string.dup.force_encoding('binary')
204
207
  string = @bin_string
205
208
  end
206
209
  pos - (string.rindex(?\n, pos) || 0)
@@ -180,7 +180,7 @@ module Scanners
180
180
  end
181
181
 
182
182
  match ||= matched
183
- if $DEBUG and not kind
183
+ if $CODERAY_DEBUG and not kind
184
184
  raise_inspect 'Error token %p in line %d' %
185
185
  [[match, kind], line], tokens
186
186
  end
@@ -205,7 +205,7 @@ module Scanners
205
205
  end
206
206
 
207
207
  match ||= matched
208
- if $DEBUG and not kind
208
+ if $CODERAY_DEBUG and not kind
209
209
  raise_inspect 'Error token %p in line %d' %
210
210
  [[match, kind], line], tokens
211
211
  end
@@ -191,7 +191,7 @@ module Scanners
191
191
  end
192
192
 
193
193
  match ||= matched
194
- if $DEBUG and not kind
194
+ if $CODERAY_DEBUG and not kind
195
195
  raise_inspect 'Error token %p in line %d' %
196
196
  [[match, kind], line], tokens
197
197
  end
@@ -32,8 +32,8 @@ module Scanners
32
32
  opened_tokens << kind
33
33
  match = :open
34
34
 
35
- elsif scan(/ > /x)
36
- kind = opened_tokens.pop
35
+ elsif !opened_tokens.empty? && scan(/ > /x)
36
+ kind = opened_tokens.pop || :error
37
37
  match = :close
38
38
 
39
39
  else
@@ -43,7 +43,7 @@ module Scanners
43
43
  end
44
44
 
45
45
  match ||= matched
46
- if $DEBUG and not kind
46
+ if $CODERAY_DEBUG and not kind
47
47
  raise_inspect 'Error token %p in line %d' %
48
48
  [[match, kind], line], tokens
49
49
  end
@@ -130,7 +130,7 @@ module Scanners
130
130
  end
131
131
 
132
132
  match ||= matched
133
- if $DEBUG and not kind
133
+ if $CODERAY_DEBUG and not kind
134
134
  raise_inspect 'Error token %p in line %d' %
135
135
  [[match, kind], line], tokens, state
136
136
  end
@@ -86,7 +86,7 @@ module Scanners
86
86
  end
87
87
 
88
88
  match ||= matched
89
- if $DEBUG and not kind
89
+ if $CODERAY_DEBUG and not kind
90
90
  raise_inspect 'Error token %p in line %d' %
91
91
  [[match, kind], line], tokens
92
92
  end
@@ -123,6 +123,7 @@ module Scanners
123
123
  next
124
124
  end
125
125
  end
126
+ kind = :operator
126
127
 
127
128
  elsif check(/[\d.]/)
128
129
  after_def = value_expected = false
@@ -238,7 +239,7 @@ module Scanners
238
239
  end
239
240
 
240
241
  match ||= matched
241
- if $DEBUG and not kind
242
+ if $CODERAY_DEBUG and not kind
242
243
  raise_inspect 'Error token %p in line %d' %
243
244
  [[match, kind], line], tokens
244
245
  end
@@ -159,7 +159,7 @@ module Scanners
159
159
  end
160
160
 
161
161
  match ||= matched
162
- if $DEBUG and not kind
162
+ if $CODERAY_DEBUG and not kind
163
163
  raise_inspect 'Error token %p in line %d' %
164
164
  [[match, kind], line], tokens, state
165
165
  end
@@ -151,7 +151,7 @@ module Scanners
151
151
  end
152
152
 
153
153
  match ||= matched
154
- if $DEBUG and not kind
154
+ if $CODERAY_DEBUG and not kind
155
155
  raise_inspect 'Error token %p in line %d' %
156
156
  [[match, kind], line], tokens
157
157
  end
@@ -190,7 +190,7 @@ module Scanners
190
190
  end
191
191
 
192
192
  match ||= matched
193
- if $DEBUG and not kind
193
+ if $CODERAY_DEBUG and not kind
194
194
  raise_inspect 'Error token %p in line %d' %
195
195
  [[match, kind], line], tokens
196
196
  end
@@ -89,7 +89,7 @@ module Scanners
89
89
  end
90
90
 
91
91
  match ||= matched
92
- if $DEBUG and not kind
92
+ if $CODERAY_DEBUG and not kind
93
93
  raise_inspect 'Error token %p in line %d' %
94
94
  [[match, kind], line], tokens
95
95
  end
@@ -212,6 +212,7 @@ module Scanners
212
212
  \.(?!\d)=? | # dot that is not decimal point, string concatenation
213
213
  && | \|\| | # logic
214
214
  :: | -> | => | # scope, member, dictionary
215
+ \\(?!\n) | # namespace
215
216
  \+\+ | -- | # increment, decrement
216
217
  [,;?:()\[\]{}] | # simple delimiters
217
218
  [-+*\/%&|^]=? | # ordinary math, binary logic, assignment shortcuts
@@ -507,7 +508,7 @@ module Scanners
507
508
  end
508
509
 
509
510
  match ||= matched
510
- if $DEBUG and not kind
511
+ if $CODERAY_DEBUG and not kind
511
512
  raise_inspect 'Error token %p in line %d' %
512
513
  [[match, kind], line], tokens, states
513
514
  end
@@ -260,7 +260,7 @@ module Scanners
260
260
  end
261
261
 
262
262
  match ||= matched
263
- if $DEBUG and not kind
263
+ if $CODERAY_DEBUG and not kind
264
264
  raise_inspect 'Error token %p in line %d' %
265
265
  [[match, kind], line], tokens, state
266
266
  end