coderay 0.9.1 → 0.9.2
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.
- data/Rakefile +35 -0
- data/lib/README +7 -3
- data/lib/coderay.rb +5 -3
- data/lib/coderay/encoders/_map.rb +1 -0
- data/lib/coderay/encoders/html.rb +2 -2
- data/lib/coderay/encoders/html/css.rb +1 -1
- data/lib/coderay/encoders/lines_of_code.rb +1 -1
- data/lib/coderay/encoders/term.rb +28 -7
- data/lib/coderay/for_redcloth.rb +12 -2
- data/lib/coderay/helpers/plugin.rb +1 -1
- data/lib/coderay/scanner.rb +4 -1
- data/lib/coderay/scanners/c.rb +1 -1
- data/lib/coderay/scanners/cpp.rb +1 -1
- data/lib/coderay/scanners/css.rb +1 -1
- data/lib/coderay/scanners/debug.rb +3 -3
- data/lib/coderay/scanners/delphi.rb +1 -1
- data/lib/coderay/scanners/diff.rb +1 -1
- data/lib/coderay/scanners/groovy.rb +2 -1
- data/lib/coderay/scanners/html.rb +1 -1
- data/lib/coderay/scanners/java.rb +1 -1
- data/lib/coderay/scanners/java_script.rb +1 -1
- data/lib/coderay/scanners/json.rb +1 -1
- data/lib/coderay/scanners/php.rb +2 -1
- data/lib/coderay/scanners/python.rb +1 -1
- data/lib/coderay/scanners/ruby.rb +17 -8
- data/lib/coderay/scanners/scheme.rb +1 -1
- data/lib/coderay/scanners/yaml.rb +6 -10
- data/lib/coderay/tokens.rb +0 -3
- data/test/functional/basic.rb +118 -0
- data/test/functional/for_redcloth.rb +77 -0
- data/test/functional/load_plugin_scanner.rb +11 -0
- data/test/functional/suite.rb +12 -0
- data/test/functional/vhdl.rb +126 -0
- data/test/functional/word_list.rb +79 -0
- metadata +32 -14
- data/lib/term/ansicolor.rb +0 -220
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.
|
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
|
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://
|
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.
|
137
|
+
VERSION = '0.9.2'
|
136
138
|
|
137
139
|
require 'coderay/tokens'
|
138
140
|
require 'coderay/token_classes'
|
@@ -264,7 +264,7 @@ module Encoders
|
|
264
264
|
if @opened.empty?
|
265
265
|
# nothing to close
|
266
266
|
else
|
267
|
-
if $
|
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 $
|
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
|
-
|
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 $
|
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 => {
|
56
|
-
|
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
|
-
:
|
78
|
+
:value => '36',
|
79
|
+
:variable => '34',
|
80
|
+
:insert => '42',
|
81
|
+
:delete => '41',
|
82
|
+
:change => '44',
|
83
|
+
:head => '45',
|
63
84
|
}
|
64
|
-
TOKEN_COLORS[:
|
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
|
data/lib/coderay/for_redcloth.rb
CHANGED
@@ -13,10 +13,20 @@ module CodeRay
|
|
13
13
|
module ForRedCloth
|
14
14
|
|
15
15
|
def self.install
|
16
|
-
gem 'RedCloth', '>= 4.0.3'
|
16
|
+
gem 'RedCloth', '>= 4.0.3' if defined? gem
|
17
17
|
require 'redcloth'
|
18
18
|
unless RedCloth::VERSION.to_s >= '4.0.3'
|
19
|
-
|
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
|
data/lib/coderay/scanner.rb
CHANGED
@@ -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(
|
206
|
+
@bin_string ||= string.dup.force_encoding('binary')
|
204
207
|
string = @bin_string
|
205
208
|
end
|
206
209
|
pos - (string.rindex(?\n, pos) || 0)
|
data/lib/coderay/scanners/c.rb
CHANGED
data/lib/coderay/scanners/cpp.rb
CHANGED
data/lib/coderay/scanners/css.rb
CHANGED
@@ -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 $
|
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
|
@@ -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 $
|
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
|
data/lib/coderay/scanners/php.rb
CHANGED
@@ -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 $
|
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
|