##// END OF EJS Templates
Coderay upgraded to 0.9.7 (#5344)....
Jean-Philippe Lang -
r4619:144ca23442a5
parent child
Show More
@@ -0,0 +1,155
1 --- !ruby/object:Gem::Specification
2 name: coderay
3 version: !ruby/object:Gem::Version
4 hash: 53
5 prerelease: false
6 segments:
7 - 0
8 - 9
9 - 7
10 version: 0.9.7
11 platform: ruby
12 authors:
13 - murphy
14 autorequire:
15 bindir: bin
16 cert_chain: []
17
18 date: 2011-01-15 00:00:00 +01:00
19 default_executable:
20 dependencies: []
21
22 description: |
23 Fast and easy syntax highlighting for selected languages, written in Ruby.
24 Comes with RedCloth integration and LOC counter.
25
26 email: murphy@rubychan.de
27 executables:
28 - coderay
29 - coderay_stylesheet
30 extensions: []
31
32 extra_rdoc_files:
33 - lib/README
34 - FOLDERS
35 files:
36 - ./lib/coderay/duo.rb
37 - ./lib/coderay/encoder.rb
38 - ./lib/coderay/encoders/_map.rb
39 - ./lib/coderay/encoders/comment_filter.rb
40 - ./lib/coderay/encoders/count.rb
41 - ./lib/coderay/encoders/debug.rb
42 - ./lib/coderay/encoders/div.rb
43 - ./lib/coderay/encoders/filter.rb
44 - ./lib/coderay/encoders/html/css.rb
45 - ./lib/coderay/encoders/html/numerization.rb
46 - ./lib/coderay/encoders/html/output.rb
47 - ./lib/coderay/encoders/html.rb
48 - ./lib/coderay/encoders/json.rb
49 - ./lib/coderay/encoders/lines_of_code.rb
50 - ./lib/coderay/encoders/null.rb
51 - ./lib/coderay/encoders/page.rb
52 - ./lib/coderay/encoders/span.rb
53 - ./lib/coderay/encoders/statistic.rb
54 - ./lib/coderay/encoders/term.rb
55 - ./lib/coderay/encoders/text.rb
56 - ./lib/coderay/encoders/token_class_filter.rb
57 - ./lib/coderay/encoders/xml.rb
58 - ./lib/coderay/encoders/yaml.rb
59 - ./lib/coderay/for_redcloth.rb
60 - ./lib/coderay/helpers/file_type.rb
61 - ./lib/coderay/helpers/gzip_simple.rb
62 - ./lib/coderay/helpers/plugin.rb
63 - ./lib/coderay/helpers/word_list.rb
64 - ./lib/coderay/scanner.rb
65 - ./lib/coderay/scanners/_map.rb
66 - ./lib/coderay/scanners/c.rb
67 - ./lib/coderay/scanners/cpp.rb
68 - ./lib/coderay/scanners/css.rb
69 - ./lib/coderay/scanners/debug.rb
70 - ./lib/coderay/scanners/delphi.rb
71 - ./lib/coderay/scanners/diff.rb
72 - ./lib/coderay/scanners/groovy.rb
73 - ./lib/coderay/scanners/html.rb
74 - ./lib/coderay/scanners/java/builtin_types.rb
75 - ./lib/coderay/scanners/java.rb
76 - ./lib/coderay/scanners/java_script-0.9.6.rb
77 - ./lib/coderay/scanners/java_script.rb
78 - ./lib/coderay/scanners/json.rb
79 - ./lib/coderay/scanners/nitro_xhtml.rb
80 - ./lib/coderay/scanners/php.rb
81 - ./lib/coderay/scanners/plaintext.rb
82 - ./lib/coderay/scanners/python.rb
83 - ./lib/coderay/scanners/rhtml.rb
84 - ./lib/coderay/scanners/ruby/patterns.rb
85 - ./lib/coderay/scanners/ruby.rb
86 - ./lib/coderay/scanners/scheme.rb
87 - ./lib/coderay/scanners/sql.rb
88 - ./lib/coderay/scanners/xml.rb
89 - ./lib/coderay/scanners/yaml.rb
90 - ./lib/coderay/style.rb
91 - ./lib/coderay/styles/_map.rb
92 - ./lib/coderay/styles/cycnus.rb
93 - ./lib/coderay/styles/murphy.rb
94 - ./lib/coderay/token_classes.rb
95 - ./lib/coderay/tokens.rb
96 - ./lib/coderay.rb
97 - ./Rakefile
98 - ./test/functional/basic.rb
99 - ./test/functional/basic.rbc
100 - ./test/functional/for_redcloth.rb
101 - ./test/functional/for_redcloth.rbc
102 - ./test/functional/load_plugin_scanner.rb
103 - ./test/functional/load_plugin_scanner.rbc
104 - ./test/functional/suite.rb
105 - ./test/functional/suite.rbc
106 - ./test/functional/vhdl.rb
107 - ./test/functional/vhdl.rbc
108 - ./test/functional/word_list.rb
109 - ./test/functional/word_list.rbc
110 - ./lib/README
111 - ./LICENSE
112 - lib/README
113 - FOLDERS
114 - bin/coderay
115 - bin/coderay_stylesheet
116 has_rdoc: true
117 homepage: http://coderay.rubychan.de
118 licenses: []
119
120 post_install_message:
121 rdoc_options:
122 - -SNw2
123 - -mlib/README
124 - -t CodeRay Documentation
125 require_paths:
126 - lib
127 required_ruby_version: !ruby/object:Gem::Requirement
128 none: false
129 requirements:
130 - - ">="
131 - !ruby/object:Gem::Version
132 hash: 51
133 segments:
134 - 1
135 - 8
136 - 2
137 version: 1.8.2
138 required_rubygems_version: !ruby/object:Gem::Requirement
139 none: false
140 requirements:
141 - - ">="
142 - !ruby/object:Gem::Version
143 hash: 3
144 segments:
145 - 0
146 version: "0"
147 requirements: []
148
149 rubyforge_project: coderay
150 rubygems_version: 1.3.7
151 signing_key:
152 specification_version: 3
153 summary: Fast syntax highlighting for selected languages.
154 test_files:
155 - ./test/functional/suite.rb
@@ -0,0 +1,53
1 = CodeRay - Trunk folder structure
2
3 == bench - Benchmarking system
4
5 All benchmarking stuff goes here.
6
7 Test inputs are stored in files named <code>example.<lang></code>.
8 Test outputs go to <code>bench/test.<encoder-default-file-extension></code>.
9
10 Run <code>bench/bench.rb</code> to get a usage description.
11
12 Run <code>rake bench</code> to perform an example benchmark.
13
14
15 == bin - Scripts
16
17 Executional files for CodeRay.
18
19
20 == demo - Demos and functional tests
21
22 Demonstrational scripts to show of CodeRay's features.
23
24 Run them as functional tests with <code>rake test:demos</code>.
25
26
27 == etc - Lots of stuff
28
29 Some addidtional files for CodeRay, mainly graphics and Vim scripts.
30
31
32 == gem_server - Gem output folder
33
34 For <code>rake gem</code>.
35
36
37 == lib - CodeRay library code
38
39 This is the base directory for the CodeRay library.
40
41
42 == rake_helpers - Rake helper libraries
43
44 Some files to enhance Rake, including the Autumnal Rdoc template and some scripts.
45
46
47 == test - Tests
48
49 Tests for the scanners.
50
51 Each language has its own subfolder and sub-suite.
52
53 Run with <code>rake test</code>.
@@ -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 No newline at end of file
@@ -0,0 +1,86
1 #!/usr/bin/env ruby
2 # CodeRay Executable
3 #
4 # Version: 0.2
5 # Author: murphy
6
7 require 'coderay'
8
9 if ARGV.empty?
10 $stderr.puts <<-USAGE
11 CodeRay #{CodeRay::VERSION} (http://coderay.rubychan.de)
12
13 Usage:
14 coderay file [-<format>]
15 coderay -<lang> [-<format>] [< file] [> output]
16
17 Defaults:
18 lang: based on file extension
19 format: ANSI colorized output for terminal, HTML page for files
20
21 Examples:
22 coderay foo.rb # colorized output to terminal, based on file extension
23 coderay foo.rb -loc # print LOC count, based on file extension and format
24 coderay foo.rb > foo.html # HTML page output to file, based on extension
25 coderay -ruby < foo.rb # colorized output to terminal, based on lang
26 coderay -ruby -loc < foo.rb # print LOC count, based on lang
27 coderay -ruby -page foo.rb # HTML page output to terminal, based on lang and format
28 coderay -ruby -page foo.rb > foo.html # HTML page output to file, based on lang and format
29 USAGE
30 end
31
32 first, second = ARGV
33
34 def read
35 file = ARGV.grep(/^(?!-)/).last
36 if file
37 if File.exist?(file)
38 File.read file
39 else
40 $stderr.puts "No such file: #{file}"
41 end
42 else
43 $stdin.read
44 end
45 end
46
47 if first
48 if first[/-(\w+)/] == first
49 lang = $1
50 input = read
51 tokens = :scan
52 else
53 file = first
54 unless File.exist? file
55 $stderr.puts "No such file: #{file}"
56 exit 2
57 end
58 tokens = CodeRay.scan_file file
59 end
60 else
61 $stderr.puts 'No lang/file given.'
62 exit 1
63 end
64
65 if second
66 if second[/-(\w+)/] == second
67 format = $1.to_sym
68 else
69 raise 'invalid format (must be -xxx)'
70 end
71 else
72 if $stdout.tty?
73 format = :term
74 else
75 $stderr.puts 'No format given; setting to default (HTML Page).'
76 format = :page
77 end
78 end
79
80 if tokens == :scan
81 output = CodeRay::Duo[lang => format].highlight input
82 else
83 output = tokens.encode format
84 end
85 out = $stdout
86 out.puts output
@@ -0,0 +1,4
1 #!/usr/bin/env ruby
2 require 'coderay'
3
4 puts CodeRay::Encoders[:html]::CSS.new.stylesheet
@@ -0,0 +1,224
1 module CodeRay
2 module Scanners
3
4 class JavaScript < Scanner
5
6 include Streamable
7
8 register_for :java_script
9 file_extension 'js'
10
11 # The actual JavaScript keywords.
12 KEYWORDS = %w[
13 break case catch continue default delete do else
14 finally for function if in instanceof new
15 return switch throw try typeof var void while with
16 ]
17 PREDEFINED_CONSTANTS = %w[
18 false null true undefined
19 ]
20
21 MAGIC_VARIABLES = %w[ this arguments ] # arguments was introduced in JavaScript 1.4
22
23 KEYWORDS_EXPECTING_VALUE = WordList.new.add %w[
24 case delete in instanceof new return throw typeof with
25 ]
26
27 # Reserved for future use.
28 RESERVED_WORDS = %w[
29 abstract boolean byte char class debugger double enum export extends
30 final float goto implements import int interface long native package
31 private protected public short static super synchronized throws transient
32 volatile
33 ]
34
35 IDENT_KIND = WordList.new(:ident).
36 add(RESERVED_WORDS, :reserved).
37 add(PREDEFINED_CONSTANTS, :pre_constant).
38 add(MAGIC_VARIABLES, :local_variable).
39 add(KEYWORDS, :keyword)
40
41 ESCAPE = / [bfnrtv\n\\'"] | x[a-fA-F0-9]{1,2} | [0-7]{1,3} /x
42 UNICODE_ESCAPE = / u[a-fA-F0-9]{4} | U[a-fA-F0-9]{8} /x
43 REGEXP_ESCAPE = / [bBdDsSwW] /x
44 STRING_CONTENT_PATTERN = {
45 "'" => /[^\\']+/,
46 '"' => /[^\\"]+/,
47 '/' => /[^\\\/]+/,
48 }
49 KEY_CHECK_PATTERN = {
50 "'" => / (?> [^\\']* (?: \\. [^\\']* )* ) ' \s* : /mx,
51 '"' => / (?> [^\\"]* (?: \\. [^\\"]* )* ) " \s* : /mx,
52 }
53
54 def scan_tokens tokens, options
55
56 state = :initial
57 string_delimiter = nil
58 value_expected = true
59 key_expected = false
60 function_expected = false
61
62 until eos?
63
64 kind = nil
65 match = nil
66
67 case state
68
69 when :initial
70
71 if match = scan(/ \s+ | \\\n /x)
72 value_expected = true if !value_expected && match.index(?\n)
73 tokens << [match, :space]
74 next
75
76 elsif scan(%r! // [^\n\\]* (?: \\. [^\n\\]* )* | /\* (?: .*? \*/ | .* ) !mx)
77 value_expected = true
78 kind = :comment
79
80 elsif check(/\.?\d/)
81 key_expected = value_expected = false
82 if scan(/0[xX][0-9A-Fa-f]+/)
83 kind = :hex
84 elsif scan(/(?>0[0-7]+)(?![89.eEfF])/)
85 kind = :oct
86 elsif scan(/\d+[fF]|\d*\.\d+(?:[eE][+-]?\d+)?[fF]?|\d+[eE][+-]?\d+[fF]?/)
87 kind = :float
88 elsif scan(/\d+/)
89 kind = :integer
90 end
91
92 elsif value_expected && match = scan(/<([[:alpha:]]\w*) (?: [^\/>]*\/> | .*?<\/\1>)/xim)
93 # FIXME: scan over nested tags
94 xml_scanner.tokenize match
95 value_expected = false
96 next
97
98 elsif match = scan(/ [-+*=<>?:;,!&^|(\[{~%]+ | \.(?!\d) /x)
99 value_expected = true
100 last_operator = match[-1]
101 key_expected = (last_operator == ?{) || (last_operator == ?,)
102 function_expected = false
103 kind = :operator
104
105 elsif scan(/ [)\]}]+ /x)
106 function_expected = key_expected = value_expected = false
107 kind = :operator
108
109 elsif match = scan(/ [$a-zA-Z_][A-Za-z_0-9$]* /x)
110 kind = IDENT_KIND[match]
111 value_expected = (kind == :keyword) && KEYWORDS_EXPECTING_VALUE[match]
112 # TODO: labels
113 if kind == :ident
114 if match.index(?$) # $ allowed inside an identifier
115 kind = :predefined
116 elsif function_expected
117 kind = :function
118 elsif check(/\s*[=:]\s*function\b/)
119 kind = :function
120 elsif key_expected && check(/\s*:/)
121 kind = :key
122 end
123 end
124 function_expected = (kind == :keyword) && (match == 'function')
125 key_expected = false
126
127 elsif match = scan(/["']/)
128 if key_expected && check(KEY_CHECK_PATTERN[match])
129 state = :key
130 else
131 state = :string
132 end
133 tokens << [:open, state]
134 string_delimiter = match
135 kind = :delimiter
136
137 elsif value_expected && (match = scan(/\/(?=\S)/))
138 tokens << [:open, :regexp]
139 state = :regexp
140 string_delimiter = '/'
141 kind = :delimiter
142
143 elsif scan(/ \/ /x)
144 value_expected = true
145 key_expected = false
146 kind = :operator
147
148 else
149 getch
150 kind = :error
151
152 end
153
154 when :string, :regexp, :key
155 if scan(STRING_CONTENT_PATTERN[string_delimiter])
156 kind = :content
157 elsif match = scan(/["'\/]/)
158 tokens << [match, :delimiter]
159 if state == :regexp
160 modifiers = scan(/[gim]+/)
161 tokens << [modifiers, :modifier] if modifiers && !modifiers.empty?
162 end
163 tokens << [:close, state]
164 string_delimiter = nil
165 key_expected = value_expected = false
166 state = :initial
167 next
168 elsif state != :regexp && (match = scan(/ \\ (?: #{ESCAPE} | #{UNICODE_ESCAPE} ) /mox))
169 if string_delimiter == "'" && !(match == "\\\\" || match == "\\'")
170 kind = :content
171 else
172 kind = :char
173 end
174 elsif state == :regexp && scan(/ \\ (?: #{ESCAPE} | #{REGEXP_ESCAPE} | #{UNICODE_ESCAPE} ) /mox)
175 kind = :char
176 elsif scan(/\\./m)
177 kind = :content
178 elsif scan(/ \\ | $ /x)
179 tokens << [:close, state]
180 kind = :error
181 key_expected = value_expected = false
182 state = :initial
183 else
184 raise_inspect "else case \" reached; %p not handled." % peek(1), tokens
185 end
186
187 else
188 raise_inspect 'Unknown state', tokens
189
190 end
191
192 match ||= matched
193 if $CODERAY_DEBUG and not kind
194 raise_inspect 'Error token %p in line %d' %
195 [[match, kind], line], tokens
196 end
197 raise_inspect 'Empty token', tokens unless match
198
199 tokens << [match, kind]
200
201 end
202
203 if [:string, :regexp].include? state
204 tokens << [:close, state]
205 end
206
207 tokens
208 end
209
210 protected
211
212 def reset_instance
213 super
214 @xml_scanner.reset if defined? @xml_scanner
215 end
216
217 def xml_scanner
218 @xml_scanner ||= CodeRay.scanner :xml, :tokens => @tokens, :keep_tokens => true, :keep_state => false
219 end
220
221 end
222
223 end
224 end
@@ -0,0 +1,122
1 require 'test/unit'
2 require 'coderay'
3
4 class BasicTest < Test::Unit::TestCase
5
6 def test_version
7 assert_nothing_raised do
8 assert_match(/\A\d\.\d\.\d\z/, CodeRay::VERSION)
9 end
10 end
11
12 RUBY_TEST_CODE = 'puts "Hello, World!"'
13
14 RUBY_TEST_TOKENS = [
15 ['puts', :ident],
16 [' ', :space],
17 [:open, :string],
18 ['"', :delimiter],
19 ['Hello, World!', :content],
20 ['"', :delimiter],
21 [:close, :string]
22 ]
23 def test_simple_scan
24 assert_nothing_raised do
25 assert_equal RUBY_TEST_TOKENS, CodeRay.scan(RUBY_TEST_CODE, :ruby).to_ary
26 end
27 end
28
29 RUBY_TEST_HTML = 'puts <span class="s"><span class="dl">&quot;</span>' +
30 '<span class="k">Hello, World!</span><span class="dl">&quot;</span></span>'
31 def test_simple_highlight
32 assert_nothing_raised do
33 assert_equal RUBY_TEST_HTML, CodeRay.scan(RUBY_TEST_CODE, :ruby).html
34 end
35 end
36
37 def test_duo
38 assert_equal(RUBY_TEST_CODE,
39 CodeRay::Duo[:plain, :plain].highlight(RUBY_TEST_CODE))
40 assert_equal(RUBY_TEST_CODE,
41 CodeRay::Duo[:plain => :plain].highlight(RUBY_TEST_CODE))
42 end
43
44 def test_duo_stream
45 assert_equal(RUBY_TEST_CODE,
46 CodeRay::Duo[:plain, :plain].highlight(RUBY_TEST_CODE, :stream => true))
47 end
48
49 def test_comment_filter
50 assert_equal <<-EXPECTED, CodeRay.scan(<<-INPUT, :ruby).comment_filter.text
51 #!/usr/bin/env ruby
52
53 code
54
55 more code
56 EXPECTED
57 #!/usr/bin/env ruby
58 =begin
59 A multi-line comment.
60 =end
61 code
62 # A single-line comment.
63 more code # and another comment, in-line.
64 INPUT
65 end
66
67 def test_lines_of_code
68 assert_equal 2, CodeRay.scan(<<-INPUT, :ruby).lines_of_code
69 #!/usr/bin/env ruby
70 =begin
71 A multi-line comment.
72 =end
73 code
74 # A single-line comment.
75 more code # and another comment, in-line.
76 INPUT
77 rHTML = <<-RHTML
78 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
79 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
80
81 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
82 <head>
83 <meta http-equiv="content-type" content="text/html;charset=UTF-8" />
84 <title><%= controller.controller_name.titleize %>: <%= controller.action_name %></title>
85 <%= stylesheet_link_tag 'scaffold' %>
86 </head>
87 <body>
88
89 <p style="color: green"><%= flash[:notice] %></p>
90
91 <div id="main">
92 <%= yield %>
93 </div>
94
95 </body>
96 </html>
97 RHTML
98 assert_equal 0, CodeRay.scan(rHTML, :html).lines_of_code
99 assert_equal 0, CodeRay.scan(rHTML, :php).lines_of_code
100 assert_equal 0, CodeRay.scan(rHTML, :yaml).lines_of_code
101 assert_equal 4, CodeRay.scan(rHTML, :rhtml).lines_of_code
102 end
103
104 def test_rubygems_not_loaded
105 assert_equal nil, defined? Gem
106 end if ENV['check_rubygems'] && RUBY_VERSION < '1.9'
107
108 def test_list_of_encoders
109 assert_kind_of(Array, CodeRay::Encoders.list)
110 assert CodeRay::Encoders.list.include?('count')
111 end
112
113 def test_list_of_scanners
114 assert_kind_of(Array, CodeRay::Scanners.list)
115 assert CodeRay::Scanners.list.include?('plaintext')
116 end
117
118 def test_scan_a_frozen_string
119 CodeRay.scan RUBY_VERSION, :ruby
120 end
121
122 end
This diff has been collapsed as it changes many lines, (2022 lines changed) Show them Hide them
@@ -0,0 +1,2022
1 !RBIX
2 0
3 x
4 M
5 1
6 n
7 n
8 x
9 10
10 __script__
11 i
12 53
13 5
14 7
15 0
16 64
17 47
18 49
19 1
20 1
21 15
22 5
23 7
24 2
25 64
26 47
27 49
28 1
29 1
30 15
31 99
32 7
33 3
34 45
35 4
36 5
37 43
38 6
39 43
40 7
41 65
42 49
43 8
44 3
45 13
46 99
47 12
48 7
49 9
50 12
51 7
52 10
53 12
54 65
55 12
56 49
57 11
58 4
59 15
60 49
61 9
62 0
63 15
64 2
65 11
66 I
67 6
68 I
69 0
70 I
71 0
72 I
73 0
74 n
75 p
76 12
77 s
78 9
79 test/unit
80 x
81 7
82 require
83 s
84 7
85 coderay
86 x
87 9
88 BasicTest
89 x
90 4
91 Test
92 n
93 x
94 4
95 Unit
96 x
97 8
98 TestCase
99 x
100 10
101 open_class
102 x
103 14
104 __class_init__
105 M
106 1
107 n
108 n
109 x
110 9
111 BasicTest
112 i
113 263
114 5
115 66
116 99
117 7
118 0
119 7
120 1
121 65
122 67
123 49
124 2
125 0
126 49
127 3
128 4
129 15
130 65
131 7
132 4
133 7
134 5
135 64
136 49
137 6
138 2
139 15
140 65
141 7
142 7
143 7
144 8
145 64
146 7
147 9
148 35
149 2
150 7
151 10
152 64
153 7
154 11
155 35
156 2
157 7
158 12
159 7
160 13
161 35
162 2
163 7
164 14
165 64
166 7
167 15
168 35
169 2
170 7
171 16
172 64
173 7
174 17
175 35
176 2
177 7
178 14
179 64
180 7
181 15
182 35
183 2
184 7
185 18
186 7
187 13
188 35
189 2
190 35
191 7
192 49
193 6
194 2
195 15
196 99
197 7
198 19
199 7
200 20
201 65
202 67
203 49
204 2
205 0
206 49
207 3
208 4
209 15
210 65
211 7
212 21
213 7
214 22
215 64
216 7
217 23
218 64
219 81
220 24
221 49
222 6
223 2
224 15
225 99
226 7
227 25
228 7
229 26
230 65
231 67
232 49
233 2
234 0
235 49
236 3
237 4
238 15
239 99
240 7
241 27
242 7
243 28
244 65
245 67
246 49
247 2
248 0
249 49
250 3
251 4
252 15
253 99
254 7
255 29
256 7
257 30
258 65
259 67
260 49
261 2
262 0
263 49
264 3
265 4
266 15
267 99
268 7
269 31
270 7
271 32
272 65
273 67
274 49
275 2
276 0
277 49
278 3
279 4
280 15
281 99
282 7
283 33
284 7
285 34
286 65
287 67
288 49
289 2
290 0
291 49
292 3
293 4
294 15
295 45
296 35
297 36
298 7
299 37
300 64
301 49
302 38
303 1
304 13
305 9
306 202
307 15
308 45
309 39
310 40
311 7
312 41
313 64
314 84
315 42
316 9
317 219
318 99
319 7
320 43
321 7
322 44
323 65
324 67
325 49
326 2
327 0
328 49
329 3
330 4
331 8
332 220
333 1
334 15
335 99
336 7
337 45
338 7
339 46
340 65
341 67
342 49
343 2
344 0
345 49
346 3
347 4
348 15
349 99
350 7
351 47
352 7
353 48
354 65
355 67
356 49
357 2
358 0
359 49
360 3
361 4
362 15
363 99
364 7
365 49
366 7
367 50
368 65
369 67
370 49
371 2
372 0
373 49
374 3
375 4
376 11
377 I
378 a
379 I
380 0
381 I
382 0
383 I
384 0
385 n
386 p
387 51
388 x
389 12
390 test_version
391 M
392 1
393 n
394 n
395 x
396 12
397 test_version
398 i
399 8
400 5
401 56
402 0
403 47
404 50
405 1
406 0
407 11
408 I
409 2
410 I
411 0
412 I
413 0
414 I
415 0
416 n
417 p
418 2
419 M
420 1
421 p
422 2
423 x
424 9
425 for_block
426 t
427 n
428 x
429 12
430 test_version
431 i
432 29
433 5
434 7
435 0
436 13
437 70
438 9
439 19
440 15
441 44
442 43
443 1
444 7
445 2
446 78
447 49
448 3
449 2
450 6
451 0
452 45
453 4
454 5
455 43
456 6
457 47
458 49
459 7
460 2
461 11
462 I
463 5
464 I
465 0
466 I
467 0
468 I
469 0
470 I
471 -2
472 p
473 8
474 n
475 x
476 6
477 Regexp
478 s
479 14
480 \A\d\.\d\.\d\z
481 x
482 3
483 new
484 x
485 7
486 CodeRay
487 n
488 x
489 7
490 VERSION
491 x
492 12
493 assert_match
494 p
495 5
496 I
497 0
498 I
499 7
500 I
501 0
502 I
503 8
504 I
505 1d
506 x
507 55
508 /Users/murphy/ruby/coderay-0.9/test/functional/basic.rb
509 p
510 0
511 x
512 21
513 assert_nothing_raised
514 p
515 5
516 I
517 0
518 I
519 6
520 I
521 0
522 I
523 7
524 I
525 8
526 x
527 55
528 /Users/murphy/ruby/coderay-0.9/test/functional/basic.rb
529 p
530 0
531 x
532 17
533 method_visibility
534 x
535 15
536 add_defn_method
537 x
538 14
539 RUBY_TEST_CODE
540 s
541 20
542 puts "Hello, World!"
543 x
544 9
545 const_set
546 x
547 16
548 RUBY_TEST_TOKENS
549 s
550 4
551 puts
552 x
553 5
554 ident
555 s
556 1
557
558 x
559 5
560 space
561 x
562 4
563 open
564 x
565 6
566 string
567 s
568 1
569 "
570 x
571 9
572 delimiter
573 s
574 13
575 Hello, World!
576 x
577 7
578 content
579 x
580 5
581 close
582 x
583 16
584 test_simple_scan
585 M
586 1
587 n
588 n
589 x
590 16
591 test_simple_scan
592 i
593 8
594 5
595 56
596 0
597 47
598 50
599 1
600 0
601 11
602 I
603 2
604 I
605 0
606 I
607 0
608 I
609 0
610 n
611 p
612 2
613 M
614 1
615 p
616 2
617 x
618 9
619 for_block
620 t
621 n
622 x
623 16
624 test_simple_scan
625 i
626 23
627 5
628 45
629 0
630 1
631 45
632 2
633 3
634 45
635 4
636 5
637 7
638 6
639 49
640 7
641 2
642 49
643 8
644 0
645 47
646 49
647 9
648 2
649 11
650 I
651 6
652 I
653 0
654 I
655 0
656 I
657 0
658 I
659 -2
660 p
661 10
662 x
663 16
664 RUBY_TEST_TOKENS
665 n
666 x
667 7
668 CodeRay
669 n
670 x
671 14
672 RUBY_TEST_CODE
673 n
674 x
675 4
676 ruby
677 x
678 4
679 scan
680 x
681 6
682 to_ary
683 x
684 12
685 assert_equal
686 p
687 5
688 I
689 0
690 I
691 18
692 I
693 0
694 I
695 19
696 I
697 17
698 x
699 55
700 /Users/murphy/ruby/coderay-0.9/test/functional/basic.rb
701 p
702 0
703 x
704 21
705 assert_nothing_raised
706 p
707 5
708 I
709 0
710 I
711 17
712 I
713 0
714 I
715 18
716 I
717 8
718 x
719 55
720 /Users/murphy/ruby/coderay-0.9/test/functional/basic.rb
721 p
722 0
723 x
724 14
725 RUBY_TEST_HTML
726 s
727 51
728 puts <span class="s"><span class="dl">&quot;</span>
729 s
730 73
731 <span class="k">Hello, World!</span><span class="dl">&quot;</span></span>
732 x
733 1
734 +
735 x
736 21
737 test_simple_highlight
738 M
739 1
740 n
741 n
742 x
743 21
744 test_simple_highlight
745 i
746 8
747 5
748 56
749 0
750 47
751 50
752 1
753 0
754 11
755 I
756 2
757 I
758 0
759 I
760 0
761 I
762 0
763 n
764 p
765 2
766 M
767 1
768 p
769 2
770 x
771 9
772 for_block
773 t
774 n
775 x
776 21
777 test_simple_highlight
778 i
779 23
780 5
781 45
782 0
783 1
784 45
785 2
786 3
787 45
788 4
789 5
790 7
791 6
792 49
793 7
794 2
795 49
796 8
797 0
798 47
799 49
800 9
801 2
802 11
803 I
804 6
805 I
806 0
807 I
808 0
809 I
810 0
811 I
812 -2
813 p
814 10
815 x
816 14
817 RUBY_TEST_HTML
818 n
819 x
820 7
821 CodeRay
822 n
823 x
824 14
825 RUBY_TEST_CODE
826 n
827 x
828 4
829 ruby
830 x
831 4
832 scan
833 x
834 4
835 html
836 x
837 12
838 assert_equal
839 p
840 5
841 I
842 0
843 I
844 20
845 I
846 0
847 I
848 21
849 I
850 17
851 x
852 55
853 /Users/murphy/ruby/coderay-0.9/test/functional/basic.rb
854 p
855 0
856 x
857 21
858 assert_nothing_raised
859 p
860 5
861 I
862 0
863 I
864 1f
865 I
866 0
867 I
868 20
869 I
870 8
871 x
872 55
873 /Users/murphy/ruby/coderay-0.9/test/functional/basic.rb
874 p
875 0
876 x
877 8
878 test_duo
879 M
880 1
881 n
882 n
883 x
884 8
885 test_duo
886 i
887 66
888 5
889 45
890 0
891 1
892 45
893 2
894 3
895 43
896 4
897 7
898 5
899 7
900 5
901 49
902 6
903 2
904 45
905 0
906 7
907 49
908 8
909 1
910 47
911 49
912 9
913 2
914 15
915 5
916 45
917 0
918 10
919 45
920 2
921 11
922 43
923 4
924 44
925 43
926 12
927 79
928 49
929 13
930 1
931 13
932 7
933 5
934 7
935 5
936 49
937 14
938 2
939 15
940 49
941 6
942 1
943 45
944 0
945 15
946 49
947 8
948 1
949 47
950 49
951 9
952 2
953 11
954 I
955 7
956 I
957 0
958 I
959 0
960 I
961 0
962 n
963 p
964 16
965 x
966 14
967 RUBY_TEST_CODE
968 n
969 x
970 7
971 CodeRay
972 n
973 x
974 3
975 Duo
976 x
977 5
978 plain
979 x
980 2
981 []
982 n
983 x
984 9
985 highlight
986 x
987 12
988 assert_equal
989 n
990 n
991 x
992 4
993 Hash
994 x
995 16
996 new_from_literal
997 x
998 3
999 []=
1000 n
1001 p
1002 15
1003 I
1004 0
1005 I
1006 25
1007 I
1008 0
1009 I
1010 26
1011 I
1012 4
1013 I
1014 27
1015 I
1016 16
1017 I
1018 26
1019 I
1020 1b
1021 I
1022 28
1023 I
1024 1f
1025 I
1026 29
1027 I
1028 3d
1029 I
1030 28
1031 I
1032 42
1033 x
1034 55
1035 /Users/murphy/ruby/coderay-0.9/test/functional/basic.rb
1036 p
1037 0
1038 x
1039 15
1040 test_duo_stream
1041 M
1042 1
1043 n
1044 n
1045 x
1046 15
1047 test_duo_stream
1048 i
1049 42
1050 5
1051 45
1052 0
1053 1
1054 45
1055 2
1056 3
1057 43
1058 4
1059 7
1060 5
1061 7
1062 5
1063 49
1064 6
1065 2
1066 45
1067 0
1068 7
1069 44
1070 43
1071 8
1072 79
1073 49
1074 9
1075 1
1076 13
1077 7
1078 10
1079 2
1080 49
1081 11
1082 2
1083 15
1084 49
1085 12
1086 2
1087 47
1088 49
1089 13
1090 2
1091 11
1092 I
1093 8
1094 I
1095 0
1096 I
1097 0
1098 I
1099 0
1100 n
1101 p
1102 14
1103 x
1104 14
1105 RUBY_TEST_CODE
1106 n
1107 x
1108 7
1109 CodeRay
1110 n
1111 x
1112 3
1113 Duo
1114 x
1115 5
1116 plain
1117 x
1118 2
1119 []
1120 n
1121 x
1122 4
1123 Hash
1124 x
1125 16
1126 new_from_literal
1127 x
1128 6
1129 stream
1130 x
1131 3
1132 []=
1133 x
1134 9
1135 highlight
1136 x
1137 12
1138 assert_equal
1139 p
1140 9
1141 I
1142 0
1143 I
1144 2c
1145 I
1146 0
1147 I
1148 2d
1149 I
1150 4
1151 I
1152 2e
1153 I
1154 25
1155 I
1156 2d
1157 I
1158 2a
1159 x
1160 55
1161 /Users/murphy/ruby/coderay-0.9/test/functional/basic.rb
1162 p
1163 0
1164 x
1165 19
1166 test_comment_filter
1167 M
1168 1
1169 n
1170 n
1171 x
1172 19
1173 test_comment_filter
1174 i
1175 26
1176 5
1177 7
1178 0
1179 64
1180 45
1181 1
1182 2
1183 7
1184 3
1185 64
1186 7
1187 4
1188 49
1189 5
1190 2
1191 49
1192 6
1193 0
1194 49
1195 7
1196 0
1197 47
1198 49
1199 8
1200 2
1201 11
1202 I
1203 5
1204 I
1205 0
1206 I
1207 0
1208 I
1209 0
1210 n
1211 p
1212 9
1213 s
1214 39
1215 #!/usr/bin/env ruby
1216
1217 code
1218
1219 more code
1220
1221 x
1222 7
1223 CodeRay
1224 n
1225 s
1226 127
1227 #!/usr/bin/env ruby
1228 =begin
1229 A multi-line comment.
1230 =end
1231 code
1232 # A single-line comment.
1233 more code # and another comment, in-line.
1234
1235 x
1236 4
1237 ruby
1238 x
1239 4
1240 scan
1241 x
1242 14
1243 comment_filter
1244 x
1245 4
1246 text
1247 x
1248 12
1249 assert_equal
1250 p
1251 5
1252 I
1253 0
1254 I
1255 31
1256 I
1257 0
1258 I
1259 32
1260 I
1261 1a
1262 x
1263 55
1264 /Users/murphy/ruby/coderay-0.9/test/functional/basic.rb
1265 p
1266 0
1267 x
1268 18
1269 test_lines_of_code
1270 M
1271 1
1272 n
1273 n
1274 x
1275 18
1276 test_lines_of_code
1277 i
1278 108
1279 5
1280 80
1281 45
1282 0
1283 1
1284 7
1285 2
1286 64
1287 7
1288 3
1289 49
1290 4
1291 2
1292 49
1293 5
1294 0
1295 47
1296 49
1297 6
1298 2
1299 15
1300 7
1301 7
1302 64
1303 19
1304 0
1305 15
1306 5
1307 78
1308 45
1309 0
1310 8
1311 20
1312 0
1313 7
1314 9
1315 49
1316 4
1317 2
1318 49
1319 5
1320 0
1321 47
1322 49
1323 6
1324 2
1325 15
1326 5
1327 78
1328 45
1329 0
1330 10
1331 20
1332 0
1333 7
1334 11
1335 49
1336 4
1337 2
1338 49
1339 5
1340 0
1341 47
1342 49
1343 6
1344 2
1345 15
1346 5
1347 78
1348 45
1349 0
1350 12
1351 20
1352 0
1353 7
1354 13
1355 49
1356 4
1357 2
1358 49
1359 5
1360 0
1361 47
1362 49
1363 6
1364 2
1365 15
1366 5
1367 4
1368 4
1369 45
1370 0
1371 14
1372 20
1373 0
1374 7
1375 15
1376 49
1377 4
1378 2
1379 49
1380 5
1381 0
1382 47
1383 49
1384 6
1385 2
1386 11
1387 I
1388 6
1389 I
1390 1
1391 I
1392 0
1393 I
1394 0
1395 n
1396 p
1397 16
1398 x
1399 7
1400 CodeRay
1401 n
1402 s
1403 127
1404 #!/usr/bin/env ruby
1405 =begin
1406 A multi-line comment.
1407 =end
1408 code
1409 # A single-line comment.
1410 more code # and another comment, in-line.
1411
1412 x
1413 4
1414 ruby
1415 x
1416 4
1417 scan
1418 x
1419 13
1420 lines_of_code
1421 x
1422 12
1423 assert_equal
1424 s
1425 514
1426 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
1427 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
1428
1429 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
1430 <head>
1431 <meta http-equiv="content-type" content="text/html;charset=UTF-8" />
1432 <title><%= controller.controller_name.titleize %>: <%= controller.action_name %></title>
1433 <%= stylesheet_link_tag 'scaffold' %>
1434 </head>
1435 <body>
1436
1437 <p style="color: green"><%= flash[:notice] %></p>
1438
1439 <div id="main">
1440 <%= yield %>
1441 </div>
1442
1443 </body>
1444 </html>
1445
1446 n
1447 x
1448 4
1449 html
1450 n
1451 x
1452 3
1453 php
1454 n
1455 x
1456 4
1457 yaml
1458 n
1459 x
1460 5
1461 rhtml
1462 p
1463 15
1464 I
1465 0
1466 I
1467 43
1468 I
1469 0
1470 I
1471 44
1472 I
1473 15
1474 I
1475 4d
1476 I
1477 1b
1478 I
1479 62
1480 I
1481 2f
1482 I
1483 63
1484 I
1485 43
1486 I
1487 64
1488 I
1489 57
1490 I
1491 65
1492 I
1493 6c
1494 x
1495 55
1496 /Users/murphy/ruby/coderay-0.9/test/functional/basic.rb
1497 p
1498 1
1499 x
1500 5
1501 rHTML
1502 x
1503 3
1504 ENV
1505 n
1506 s
1507 14
1508 check_rubygems
1509 x
1510 2
1511 []
1512 x
1513 12
1514 RUBY_VERSION
1515 n
1516 s
1517 3
1518 1.9
1519 x
1520 1
1521 <
1522 x
1523 24
1524 test_rubygems_not_loaded
1525 M
1526 1
1527 n
1528 n
1529 x
1530 24
1531 test_rubygems_not_loaded
1532 i
1533 34
1534 5
1535 1
1536 26
1537 93
1538 0
1539 15
1540 29
1541 17
1542 0
1543 7
1544 0
1545 98
1546 1
1547 1
1548 30
1549 8
1550 23
1551 25
1552 92
1553 0
1554 27
1555 8
1556 28
1557 15
1558 7
1559 2
1560 8
1561 29
1562 1
1563 47
1564 49
1565 3
1566 2
1567 11
1568 I
1569 4
1570 I
1571 0
1572 I
1573 0
1574 I
1575 0
1576 n
1577 p
1578 4
1579 x
1580 3
1581 Gem
1582 x
1583 16
1584 vm_const_defined
1585 s
1586 8
1587 constant
1588 x
1589 12
1590 assert_equal
1591 p
1592 5
1593 I
1594 0
1595 I
1596 68
1597 I
1598 0
1599 I
1600 69
1601 I
1602 22
1603 x
1604 55
1605 /Users/murphy/ruby/coderay-0.9/test/functional/basic.rb
1606 p
1607 0
1608 x
1609 21
1610 test_list_of_encoders
1611 M
1612 1
1613 n
1614 n
1615 x
1616 21
1617 test_list_of_encoders
1618 i
1619 37
1620 5
1621 45
1622 0
1623 1
1624 45
1625 2
1626 3
1627 43
1628 4
1629 49
1630 5
1631 0
1632 47
1633 49
1634 6
1635 2
1636 15
1637 5
1638 45
1639 2
1640 7
1641 43
1642 4
1643 49
1644 5
1645 0
1646 7
1647 8
1648 64
1649 49
1650 9
1651 1
1652 47
1653 49
1654 10
1655 1
1656 11
1657 I
1658 3
1659 I
1660 0
1661 I
1662 0
1663 I
1664 0
1665 n
1666 p
1667 11
1668 x
1669 5
1670 Array
1671 n
1672 x
1673 7
1674 CodeRay
1675 n
1676 x
1677 8
1678 Encoders
1679 x
1680 4
1681 list
1682 x
1683 14
1684 assert_kind_of
1685 n
1686 s
1687 5
1688 count
1689 x
1690 8
1691 include?
1692 x
1693 6
1694 assert
1695 p
1696 7
1697 I
1698 0
1699 I
1700 6c
1701 I
1702 0
1703 I
1704 6d
1705 I
1706 11
1707 I
1708 6e
1709 I
1710 25
1711 x
1712 55
1713 /Users/murphy/ruby/coderay-0.9/test/functional/basic.rb
1714 p
1715 0
1716 x
1717 21
1718 test_list_of_scanners
1719 M
1720 1
1721 n
1722 n
1723 x
1724 21
1725 test_list_of_scanners
1726 i
1727 37
1728 5
1729 45
1730 0
1731 1
1732 45
1733 2
1734 3
1735 43
1736 4
1737 49
1738 5
1739 0
1740 47
1741 49
1742 6
1743 2
1744 15
1745 5
1746 45
1747 2
1748 7
1749 43
1750 4
1751 49
1752 5
1753 0
1754 7
1755 8
1756 64
1757 49
1758 9
1759 1
1760 47
1761 49
1762 10
1763 1
1764 11
1765 I
1766 3
1767 I
1768 0
1769 I
1770 0
1771 I
1772 0
1773 n
1774 p
1775 11
1776 x
1777 5
1778 Array
1779 n
1780 x
1781 7
1782 CodeRay
1783 n
1784 x
1785 8
1786 Scanners
1787 x
1788 4
1789 list
1790 x
1791 14
1792 assert_kind_of
1793 n
1794 s
1795 9
1796 plaintext
1797 x
1798 8
1799 include?
1800 x
1801 6
1802 assert
1803 p
1804 7
1805 I
1806 0
1807 I
1808 71
1809 I
1810 0
1811 I
1812 72
1813 I
1814 11
1815 I
1816 73
1817 I
1818 25
1819 x
1820 55
1821 /Users/murphy/ruby/coderay-0.9/test/functional/basic.rb
1822 p
1823 0
1824 x
1825 25
1826 test_scan_a_frozen_string
1827 M
1828 1
1829 n
1830 n
1831 x
1832 25
1833 test_scan_a_frozen_string
1834 i
1835 12
1836 45
1837 0
1838 1
1839 45
1840 2
1841 3
1842 7
1843 4
1844 49
1845 5
1846 2
1847 11
1848 I
1849 3
1850 I
1851 0
1852 I
1853 0
1854 I
1855 0
1856 n
1857 p
1858 6
1859 x
1860 7
1861 CodeRay
1862 n
1863 x
1864 12
1865 RUBY_VERSION
1866 n
1867 x
1868 4
1869 ruby
1870 x
1871 4
1872 scan
1873 p
1874 5
1875 I
1876 0
1877 I
1878 76
1879 I
1880 0
1881 I
1882 77
1883 I
1884 c
1885 x
1886 55
1887 /Users/murphy/ruby/coderay-0.9/test/functional/basic.rb
1888 p
1889 0
1890 p
1891 51
1892 I
1893 2
1894 I
1895 6
1896 I
1897 10
1898 I
1899 c
1900 I
1901 1a
1902 I
1903 e
1904 I
1905 1d
1906 I
1907 f
1908 I
1909 24
1910 I
1911 10
1912 I
1913 2b
1914 I
1915 11
1916 I
1917 31
1918 I
1919 12
1920 I
1921 38
1922 I
1923 13
1924 I
1925 3f
1926 I
1927 14
1928 I
1929 46
1930 I
1931 15
1932 I
1933 52
1934 I
1935 17
1936 I
1937 60
1938 I
1939 1d
1940 I
1941 63
1942 I
1943 1d
1944 I
1945 66
1946 I
1947 1e
1948 I
1949 6f
1950 I
1951 1f
1952 I
1953 7d
1954 I
1955 25
1956 I
1957 8b
1958 I
1959 2c
1960 I
1961 99
1962 I
1963 31
1964 I
1965 a7
1966 I
1967 43
1968 I
1969 b5
1970 I
1971 6a
1972 I
1973 cc
1974 I
1975 68
1976 I
1977 db
1978 I
1979 6a
1980 I
1981 dd
1982 I
1983 6c
1984 I
1985 eb
1986 I
1987 71
1988 I
1989 f9
1990 I
1991 76
1992 I
1993 107
1994 x
1995 55
1996 /Users/murphy/ruby/coderay-0.9/test/functional/basic.rb
1997 p
1998 0
1999 x
2000 13
2001 attach_method
2002 p
2003 7
2004 I
2005 0
2006 I
2007 1
2008 I
2009 9
2010 I
2011 2
2012 I
2013 12
2014 I
2015 4
2016 I
2017 35
2018 x
2019 55
2020 /Users/murphy/ruby/coderay-0.9/test/functional/basic.rb
2021 p
2022 0
@@ -0,0 +1,77
1 require 'test/unit'
2 $:.unshift 'lib'
3 require 'coderay'
4
5 begin
6 require 'rubygems' unless defined? Gem
7 gem 'RedCloth', '>= 4.0.3' rescue nil
8 require 'redcloth'
9 rescue LoadError
10 warn 'RedCloth not found - skipping for_redcloth tests.'
11 end
12
13 class BasicTest < Test::Unit::TestCase
14
15 def test_for_redcloth
16 require 'coderay/for_redcloth'
17 assert_equal "<p><span lang=\"ruby\" class=\"CodeRay\">puts <span style=\"background-color:#fff0f0;color:#D20\"><span style=\"color:#710\">&quot;</span><span style=\"\">Hello, World!</span><span style=\"color:#710\">&quot;</span></span></span></p>",
18 RedCloth.new('@[ruby]puts "Hello, World!"@').to_html
19 assert_equal <<-BLOCKCODE.chomp,
20 <div lang="ruby" class="CodeRay">
21 <div class="code"><pre>puts <span style="background-color:#fff0f0;color:#D20"><span style="color:#710">&quot;</span><span style="">Hello, World!</span><span style="color:#710">&quot;</span></span></pre></div>
22 </div>
23 BLOCKCODE
24 RedCloth.new('bc[ruby]. puts "Hello, World!"').to_html
25 end
26
27 def test_for_redcloth_no_lang
28 require 'coderay/for_redcloth'
29 assert_equal "<p><code>puts \"Hello, World!\"</code></p>",
30 RedCloth.new('@puts "Hello, World!"@').to_html
31 assert_equal <<-BLOCKCODE.chomp,
32 <pre><code>puts \"Hello, World!\"</code></pre>
33 BLOCKCODE
34 RedCloth.new('bc. puts "Hello, World!"').to_html
35 end
36
37 def test_for_redcloth_style
38 require 'coderay/for_redcloth'
39 assert_equal <<-BLOCKCODE.chomp,
40 <pre style=\"color: red;\"><code style=\"color: red;\">puts \"Hello, World!\"</code></pre>
41 BLOCKCODE
42 RedCloth.new('bc{color: red}. puts "Hello, World!"').to_html
43 end
44
45 def test_for_redcloth_escapes
46 require 'coderay/for_redcloth'
47 assert_equal '<p><span lang="ruby" class="CodeRay">&gt;</span></p>',
48 RedCloth.new('@[ruby]>@').to_html
49 assert_equal <<-BLOCKCODE.chomp,
50 <div lang="ruby" class="CodeRay">
51 <div class="code"><pre>&amp;</pre></div>
52 </div>
53 BLOCKCODE
54 RedCloth.new('bc[ruby]. &').to_html
55 end
56
57 def test_for_redcloth_escapes2
58 require 'coderay/for_redcloth'
59 assert_equal "<p><span lang=\"c\" class=\"CodeRay\"><span style=\"color:#579\">#include</span> <span style=\"color:#B44;font-weight:bold\">&lt;test.h&gt;</span></span></p>",
60 RedCloth.new('@[c]#include <test.h>@').to_html
61 end
62
63 # See http://jgarber.lighthouseapp.com/projects/13054/tickets/124-code-markup-does-not-allow-brackets.
64 def test_for_redcloth_false_positive
65 require 'coderay/for_redcloth'
66 assert_equal '<p><code>[project]_dff.skjd</code></p>',
67 RedCloth.new('@[project]_dff.skjd@').to_html
68 # false positive, but expected behavior / known issue
69 assert_equal "<p><span lang=\"ruby\" class=\"CodeRay\">_dff.skjd</span></p>",
70 RedCloth.new('@[ruby]_dff.skjd@').to_html
71 assert_equal <<-BLOCKCODE.chomp,
72 <pre><code>[project]_dff.skjd</code></pre>
73 BLOCKCODE
74 RedCloth.new('bc. [project]_dff.skjd').to_html
75 end
76
77 end if defined? RedCloth No newline at end of file
This diff has been collapsed as it changes many lines, (1708 lines changed) Show them Hide them
@@ -0,0 +1,1708
1 !RBIX
2 0
3 x
4 M
5 1
6 n
7 n
8 x
9 10
10 __script__
11 i
12 249
13 5
14 7
15 0
16 64
17 47
18 49
19 1
20 1
21 15
22 99
23 43
24 2
25 7
26 3
27 49
28 4
29 1
30 7
31 5
32 64
33 49
34 6
35 1
36 15
37 5
38 7
39 7
40 64
41 47
42 49
43 1
44 1
45 15
46 26
47 93
48 0
49 15
50 29
51 144
52 0
53 26
54 93
55 1
56 15
57 29
58 55
59 0
60 7
61 8
62 98
63 9
64 1
65 30
66 8
67 61
68 25
69 92
70 1
71 27
72 8
73 66
74 15
75 7
76 10
77 8
78 67
79 1
80 9
81 72
82 1
83 8
84 80
85 5
86 7
87 11
88 64
89 47
90 49
91 1
92 1
93 15
94 26
95 93
96 2
97 15
98 29
99 102
100 0
101 5
102 7
103 12
104 64
105 7
106 13
107 64
108 47
109 49
110 14
111 2
112 30
113 8
114 129
115 26
116 93
117 3
118 15
119 24
120 13
121 45
122 15
123 16
124 12
125 49
126 17
127 1
128 10
129 119
130 8
131 124
132 15
133 1
134 25
135 8
136 129
137 15
138 92
139 3
140 27
141 34
142 92
143 2
144 27
145 15
146 5
147 7
148 18
149 64
150 47
151 49
152 1
153 1
154 30
155 8
156 178
157 26
158 93
159 4
160 15
161 24
162 13
163 45
164 19
165 20
166 12
167 49
168 17
169 1
170 10
171 161
172 8
173 173
174 15
175 5
176 7
177 21
178 64
179 47
180 49
181 22
182 1
183 25
184 8
185 178
186 15
187 92
188 4
189 27
190 34
191 92
192 0
193 27
194 15
195 26
196 93
197 5
198 15
199 29
200 197
201 0
202 7
203 23
204 98
205 9
206 1
207 30
208 8
209 203
210 25
211 92
212 5
213 27
214 8
215 208
216 15
217 7
218 10
219 8
220 209
221 1
222 9
223 245
224 99
225 7
226 24
227 45
228 25
229 26
230 43
231 27
232 43
233 28
234 65
235 49
236 29
237 3
238 13
239 99
240 12
241 7
242 30
243 12
244 7
245 31
246 12
247 65
248 12
249 49
250 32
251 4
252 15
253 49
254 30
255 0
256 8
257 246
258 1
259 15
260 2
261 11
262 I
263 c
264 I
265 0
266 I
267 0
268 I
269 0
270 n
271 p
272 33
273 s
274 9
275 test/unit
276 x
277 7
278 require
279 x
280 7
281 Globals
282 x
283 2
284 $:
285 x
286 2
287 []
288 s
289 3
290 lib
291 x
292 2
293 <<
294 s
295 7
296 coderay
297 x
298 3
299 Gem
300 x
301 16
302 vm_const_defined
303 s
304 8
305 constant
306 s
307 8
308 rubygems
309 s
310 8
311 RedCloth
312 s
313 8
314 >= 4.0.3
315 x
316 3
317 gem
318 x
319 13
320 StandardError
321 n
322 x
323 3
324 ===
325 s
326 8
327 redcloth
328 x
329 9
330 LoadError
331 n
332 s
333 49
334 RedCloth not found - skipping for_redcloth tests.
335 x
336 4
337 warn
338 x
339 8
340 RedCloth
341 x
342 9
343 BasicTest
344 x
345 4
346 Test
347 n
348 x
349 4
350 Unit
351 x
352 8
353 TestCase
354 x
355 10
356 open_class
357 x
358 14
359 __class_init__
360 M
361 1
362 n
363 n
364 x
365 9
366 BasicTest
367 i
368 86
369 5
370 66
371 99
372 7
373 0
374 7
375 1
376 65
377 67
378 49
379 2
380 0
381 49
382 3
383 4
384 15
385 99
386 7
387 4
388 7
389 5
390 65
391 67
392 49
393 2
394 0
395 49
396 3
397 4
398 15
399 99
400 7
401 6
402 7
403 7
404 65
405 67
406 49
407 2
408 0
409 49
410 3
411 4
412 15
413 99
414 7
415 8
416 7
417 9
418 65
419 67
420 49
421 2
422 0
423 49
424 3
425 4
426 15
427 99
428 7
429 10
430 7
431 11
432 65
433 67
434 49
435 2
436 0
437 49
438 3
439 4
440 15
441 99
442 7
443 12
444 7
445 13
446 65
447 67
448 49
449 2
450 0
451 49
452 3
453 4
454 11
455 I
456 5
457 I
458 0
459 I
460 0
461 I
462 0
463 n
464 p
465 14
466 x
467 17
468 test_for_redcloth
469 M
470 1
471 n
472 n
473 x
474 17
475 test_for_redcloth
476 i
477 96
478 5
479 7
480 0
481 64
482 47
483 49
484 1
485 1
486 15
487 5
488 7
489 2
490 64
491 45
492 3
493 4
494 13
495 71
496 5
497 47
498 9
499 37
500 47
501 49
502 6
503 0
504 13
505 7
506 7
507 64
508 47
509 49
510 8
511 1
512 15
513 8
514 43
515 7
516 7
517 64
518 49
519 5
520 1
521 49
522 9
523 0
524 47
525 49
526 10
527 2
528 15
529 5
530 7
531 11
532 64
533 49
534 12
535 0
536 45
537 3
538 13
539 13
540 71
541 5
542 47
543 9
544 82
545 47
546 49
547 6
548 0
549 13
550 7
551 14
552 64
553 47
554 49
555 8
556 1
557 15
558 8
559 88
560 7
561 14
562 64
563 49
564 5
565 1
566 49
567 9
568 0
569 47
570 49
571 10
572 2
573 11
574 I
575 5
576 I
577 0
578 I
579 0
580 I
581 0
582 n
583 p
584 15
585 s
586 20
587 coderay/for_redcloth
588 x
589 7
590 require
591 s
592 221
593 <p><span lang="ruby" class="CodeRay">puts <span style="background-color:#fff0f0;color:#D20"><span style="color:#710">&quot;</span><span style="">Hello, World!</span><span style="color:#710">&quot;</span></span></span></p>
594 x
595 8
596 RedCloth
597 n
598 x
599 3
600 new
601 x
602 8
603 allocate
604 s
605 28
606 @[ruby]puts "Hello, World!"@
607 x
608 10
609 initialize
610 x
611 7
612 to_html
613 x
614 12
615 assert_equal
616 s
617 252
618 <div lang="ruby" class="CodeRay">
619 <div class="code"><pre>puts <span style="background-color:#fff0f0;color:#D20"><span style="color:#710">&quot;</span><span style="">Hello, World!</span><span style="color:#710">&quot;</span></span></pre></div>
620 </div>
621
622 x
623 5
624 chomp
625 n
626 s
627 30
628 bc[ruby]. puts "Hello, World!"
629 p
630 17
631 I
632 0
633 I
634 f
635 I
636 0
637 I
638 10
639 I
640 9
641 I
642 11
643 I
644 d
645 I
646 12
647 I
648 2e
649 I
650 11
651 I
652 33
653 I
654 13
655 I
656 3a
657 I
658 18
659 I
660 5b
661 I
662 13
663 I
664 60
665 x
666 62
667 /Users/murphy/ruby/coderay-0.9/test/functional/for_redcloth.rb
668 p
669 0
670 x
671 17
672 method_visibility
673 x
674 15
675 add_defn_method
676 x
677 25
678 test_for_redcloth_no_lang
679 M
680 1
681 n
682 n
683 x
684 25
685 test_for_redcloth_no_lang
686 i
687 96
688 5
689 7
690 0
691 64
692 47
693 49
694 1
695 1
696 15
697 5
698 7
699 2
700 64
701 45
702 3
703 4
704 13
705 71
706 5
707 47
708 9
709 37
710 47
711 49
712 6
713 0
714 13
715 7
716 7
717 64
718 47
719 49
720 8
721 1
722 15
723 8
724 43
725 7
726 7
727 64
728 49
729 5
730 1
731 49
732 9
733 0
734 47
735 49
736 10
737 2
738 15
739 5
740 7
741 11
742 64
743 49
744 12
745 0
746 45
747 3
748 13
749 13
750 71
751 5
752 47
753 9
754 82
755 47
756 49
757 6
758 0
759 13
760 7
761 14
762 64
763 47
764 49
765 8
766 1
767 15
768 8
769 88
770 7
771 14
772 64
773 49
774 5
775 1
776 49
777 9
778 0
779 47
780 49
781 10
782 2
783 11
784 I
785 5
786 I
787 0
788 I
789 0
790 I
791 0
792 n
793 p
794 15
795 s
796 20
797 coderay/for_redcloth
798 x
799 7
800 require
801 s
802 40
803 <p><code>puts "Hello, World!"</code></p>
804 x
805 8
806 RedCloth
807 n
808 x
809 3
810 new
811 x
812 8
813 allocate
814 s
815 22
816 @puts "Hello, World!"@
817 x
818 10
819 initialize
820 x
821 7
822 to_html
823 x
824 12
825 assert_equal
826 s
827 45
828 <pre><code>puts "Hello, World!"</code></pre>
829
830 x
831 5
832 chomp
833 n
834 s
835 24
836 bc. puts "Hello, World!"
837 p
838 17
839 I
840 0
841 I
842 1b
843 I
844 0
845 I
846 1c
847 I
848 9
849 I
850 1d
851 I
852 d
853 I
854 1e
855 I
856 2e
857 I
858 1d
859 I
860 33
861 I
862 1f
863 I
864 3a
865 I
866 22
867 I
868 5b
869 I
870 1f
871 I
872 60
873 x
874 62
875 /Users/murphy/ruby/coderay-0.9/test/functional/for_redcloth.rb
876 p
877 0
878 x
879 23
880 test_for_redcloth_style
881 M
882 1
883 n
884 n
885 x
886 23
887 test_for_redcloth_style
888 i
889 54
890 5
891 7
892 0
893 64
894 47
895 49
896 1
897 1
898 15
899 5
900 7
901 2
902 64
903 49
904 3
905 0
906 45
907 4
908 5
909 13
910 71
911 6
912 47
913 9
914 40
915 47
916 49
917 7
918 0
919 13
920 7
921 8
922 64
923 47
924 49
925 9
926 1
927 15
928 8
929 46
930 7
931 8
932 64
933 49
934 6
935 1
936 49
937 10
938 0
939 47
940 49
941 11
942 2
943 11
944 I
945 5
946 I
947 0
948 I
949 0
950 I
951 0
952 n
953 p
954 12
955 s
956 20
957 coderay/for_redcloth
958 x
959 7
960 require
961 s
962 85
963 <pre style="color: red;"><code style="color: red;">puts "Hello, World!"</code></pre>
964
965 x
966 5
967 chomp
968 x
969 8
970 RedCloth
971 n
972 x
973 3
974 new
975 x
976 8
977 allocate
978 s
979 36
980 bc{color: red}. puts "Hello, World!"
981 x
982 10
983 initialize
984 x
985 7
986 to_html
987 x
988 12
989 assert_equal
990 p
991 11
992 I
993 0
994 I
995 25
996 I
997 0
998 I
999 26
1000 I
1001 9
1002 I
1003 27
1004 I
1005 10
1006 I
1007 2a
1008 I
1009 31
1010 I
1011 27
1012 I
1013 36
1014 x
1015 62
1016 /Users/murphy/ruby/coderay-0.9/test/functional/for_redcloth.rb
1017 p
1018 0
1019 x
1020 25
1021 test_for_redcloth_escapes
1022 M
1023 1
1024 n
1025 n
1026 x
1027 25
1028 test_for_redcloth_escapes
1029 i
1030 96
1031 5
1032 7
1033 0
1034 64
1035 47
1036 49
1037 1
1038 1
1039 15
1040 5
1041 7
1042 2
1043 64
1044 45
1045 3
1046 4
1047 13
1048 71
1049 5
1050 47
1051 9
1052 37
1053 47
1054 49
1055 6
1056 0
1057 13
1058 7
1059 7
1060 64
1061 47
1062 49
1063 8
1064 1
1065 15
1066 8
1067 43
1068 7
1069 7
1070 64
1071 49
1072 5
1073 1
1074 49
1075 9
1076 0
1077 47
1078 49
1079 10
1080 2
1081 15
1082 5
1083 7
1084 11
1085 64
1086 49
1087 12
1088 0
1089 45
1090 3
1091 13
1092 13
1093 71
1094 5
1095 47
1096 9
1097 82
1098 47
1099 49
1100 6
1101 0
1102 13
1103 7
1104 14
1105 64
1106 47
1107 49
1108 8
1109 1
1110 15
1111 8
1112 88
1113 7
1114 14
1115 64
1116 49
1117 5
1118 1
1119 49
1120 9
1121 0
1122 47
1123 49
1124 10
1125 2
1126 11
1127 I
1128 5
1129 I
1130 0
1131 I
1132 0
1133 I
1134 0
1135 n
1136 p
1137 15
1138 s
1139 20
1140 coderay/for_redcloth
1141 x
1142 7
1143 require
1144 s
1145 52
1146 <p><span lang="ruby" class="CodeRay">&gt;</span></p>
1147 x
1148 8
1149 RedCloth
1150 n
1151 x
1152 3
1153 new
1154 x
1155 8
1156 allocate
1157 s
1158 9
1159 @[ruby]>@
1160 x
1161 10
1162 initialize
1163 x
1164 7
1165 to_html
1166 x
1167 12
1168 assert_equal
1169 s
1170 84
1171 <div lang="ruby" class="CodeRay">
1172 <div class="code"><pre>&amp;</pre></div>
1173 </div>
1174
1175 x
1176 5
1177 chomp
1178 n
1179 s
1180 11
1181 bc[ruby]. &
1182 p
1183 17
1184 I
1185 0
1186 I
1187 2d
1188 I
1189 0
1190 I
1191 2e
1192 I
1193 9
1194 I
1195 2f
1196 I
1197 d
1198 I
1199 30
1200 I
1201 2e
1202 I
1203 2f
1204 I
1205 33
1206 I
1207 31
1208 I
1209 3a
1210 I
1211 36
1212 I
1213 5b
1214 I
1215 31
1216 I
1217 60
1218 x
1219 62
1220 /Users/murphy/ruby/coderay-0.9/test/functional/for_redcloth.rb
1221 p
1222 0
1223 x
1224 26
1225 test_for_redcloth_escapes2
1226 M
1227 1
1228 n
1229 n
1230 x
1231 26
1232 test_for_redcloth_escapes2
1233 i
1234 51
1235 5
1236 7
1237 0
1238 64
1239 47
1240 49
1241 1
1242 1
1243 15
1244 5
1245 7
1246 2
1247 64
1248 45
1249 3
1250 4
1251 13
1252 71
1253 5
1254 47
1255 9
1256 37
1257 47
1258 49
1259 6
1260 0
1261 13
1262 7
1263 7
1264 64
1265 47
1266 49
1267 8
1268 1
1269 15
1270 8
1271 43
1272 7
1273 7
1274 64
1275 49
1276 5
1277 1
1278 49
1279 9
1280 0
1281 47
1282 49
1283 10
1284 2
1285 11
1286 I
1287 5
1288 I
1289 0
1290 I
1291 0
1292 I
1293 0
1294 n
1295 p
1296 11
1297 s
1298 20
1299 coderay/for_redcloth
1300 x
1301 7
1302 require
1303 s
1304 149
1305 <p><span lang="c" class="CodeRay"><span style="color:#579">#include</span> <span style="color:#B44;font-weight:bold">&lt;test.h&gt;</span></span></p>
1306 x
1307 8
1308 RedCloth
1309 n
1310 x
1311 3
1312 new
1313 x
1314 8
1315 allocate
1316 s
1317 22
1318 @[c]#include <test.h>@
1319 x
1320 10
1321 initialize
1322 x
1323 7
1324 to_html
1325 x
1326 12
1327 assert_equal
1328 p
1329 11
1330 I
1331 0
1332 I
1333 39
1334 I
1335 0
1336 I
1337 3a
1338 I
1339 9
1340 I
1341 3b
1342 I
1343 d
1344 I
1345 3c
1346 I
1347 2e
1348 I
1349 3b
1350 I
1351 33
1352 x
1353 62
1354 /Users/murphy/ruby/coderay-0.9/test/functional/for_redcloth.rb
1355 p
1356 0
1357 x
1358 32
1359 test_for_redcloth_false_positive
1360 M
1361 1
1362 n
1363 n
1364 x
1365 32
1366 test_for_redcloth_false_positive
1367 i
1368 138
1369 5
1370 7
1371 0
1372 64
1373 47
1374 49
1375 1
1376 1
1377 15
1378 5
1379 7
1380 2
1381 64
1382 45
1383 3
1384 4
1385 13
1386 71
1387 5
1388 47
1389 9
1390 37
1391 47
1392 49
1393 6
1394 0
1395 13
1396 7
1397 7
1398 64
1399 47
1400 49
1401 8
1402 1
1403 15
1404 8
1405 43
1406 7
1407 7
1408 64
1409 49
1410 5
1411 1
1412 49
1413 9
1414 0
1415 47
1416 49
1417 10
1418 2
1419 15
1420 5
1421 7
1422 11
1423 64
1424 45
1425 3
1426 12
1427 13
1428 71
1429 5
1430 47
1431 9
1432 79
1433 47
1434 49
1435 6
1436 0
1437 13
1438 7
1439 13
1440 64
1441 47
1442 49
1443 8
1444 1
1445 15
1446 8
1447 85
1448 7
1449 13
1450 64
1451 49
1452 5
1453 1
1454 49
1455 9
1456 0
1457 47
1458 49
1459 10
1460 2
1461 15
1462 5
1463 7
1464 14
1465 64
1466 49
1467 15
1468 0
1469 45
1470 3
1471 16
1472 13
1473 71
1474 5
1475 47
1476 9
1477 124
1478 47
1479 49
1480 6
1481 0
1482 13
1483 7
1484 17
1485 64
1486 47
1487 49
1488 8
1489 1
1490 15
1491 8
1492 130
1493 7
1494 17
1495 64
1496 49
1497 5
1498 1
1499 49
1500 9
1501 0
1502 47
1503 49
1504 10
1505 2
1506 11
1507 I
1508 5
1509 I
1510 0
1511 I
1512 0
1513 I
1514 0
1515 n
1516 p
1517 18
1518 s
1519 20
1520 coderay/for_redcloth
1521 x
1522 7
1523 require
1524 s
1525 38
1526 <p><code>[project]_dff.skjd</code></p>
1527 x
1528 8
1529 RedCloth
1530 n
1531 x
1532 3
1533 new
1534 x
1535 8
1536 allocate
1537 s
1538 20
1539 @[project]_dff.skjd@
1540 x
1541 10
1542 initialize
1543 x
1544 7
1545 to_html
1546 x
1547 12
1548 assert_equal
1549 s
1550 57
1551 <p><span lang="ruby" class="CodeRay">_dff.skjd</span></p>
1552 n
1553 s
1554 17
1555 @[ruby]_dff.skjd@
1556 s
1557 43
1558 <pre><code>[project]_dff.skjd</code></pre>
1559
1560 x
1561 5
1562 chomp
1563 n
1564 s
1565 22
1566 bc. [project]_dff.skjd
1567 p
1568 23
1569 I
1570 0
1571 I
1572 40
1573 I
1574 0
1575 I
1576 41
1577 I
1578 9
1579 I
1580 42
1581 I
1582 d
1583 I
1584 43
1585 I
1586 2e
1587 I
1588 42
1589 I
1590 33
1591 I
1592 45
1593 I
1594 37
1595 I
1596 46
1597 I
1598 58
1599 I
1600 45
1601 I
1602 5d
1603 I
1604 47
1605 I
1606 64
1607 I
1608 4a
1609 I
1610 85
1611 I
1612 47
1613 I
1614 8a
1615 x
1616 62
1617 /Users/murphy/ruby/coderay-0.9/test/functional/for_redcloth.rb
1618 p
1619 0
1620 p
1621 13
1622 I
1623 2
1624 I
1625 f
1626 I
1627 10
1628 I
1629 1b
1630 I
1631 1e
1632 I
1633 25
1634 I
1635 2c
1636 I
1637 2d
1638 I
1639 3a
1640 I
1641 39
1642 I
1643 48
1644 I
1645 40
1646 I
1647 56
1648 x
1649 62
1650 /Users/murphy/ruby/coderay-0.9/test/functional/for_redcloth.rb
1651 p
1652 0
1653 x
1654 13
1655 attach_method
1656 p
1657 23
1658 I
1659 0
1660 I
1661 1
1662 I
1663 9
1664 I
1665 2
1666 I
1667 18
1668 I
1669 3
1670 I
1671 21
1672 I
1673 6
1674 I
1675 51
1676 I
1677 7
1678 I
1679 85
1680 I
1681 8
1682 I
1683 95
1684 I
1685 9
1686 I
1687 a2
1688 I
1689 a
1690 I
1691 b6
1692 I
1693 4d
1694 I
1695 d3
1696 I
1697 d
1698 I
1699 f5
1700 I
1701 4d
1702 I
1703 f9
1704 x
1705 62
1706 /Users/murphy/ruby/coderay-0.9/test/functional/for_redcloth.rb
1707 p
1708 0
@@ -0,0 +1,11
1 require 'test/unit'
2 require 'coderay'
3
4 class PluginScannerTest < Test::Unit::TestCase
5
6 def test_load
7 require File.join(File.dirname(__FILE__), 'vhdl')
8 assert_equal 'VHDL', CodeRay.scanner(:vhdl).class.name
9 end
10
11 end
@@ -0,0 +1,317
1 !RBIX
2 0
3 x
4 M
5 1
6 n
7 n
8 x
9 10
10 __script__
11 i
12 53
13 5
14 7
15 0
16 64
17 47
18 49
19 1
20 1
21 15
22 5
23 7
24 2
25 64
26 47
27 49
28 1
29 1
30 15
31 99
32 7
33 3
34 45
35 4
36 5
37 43
38 6
39 43
40 7
41 65
42 49
43 8
44 3
45 13
46 99
47 12
48 7
49 9
50 12
51 7
52 10
53 12
54 65
55 12
56 49
57 11
58 4
59 15
60 49
61 9
62 0
63 15
64 2
65 11
66 I
67 6
68 I
69 0
70 I
71 0
72 I
73 0
74 n
75 p
76 12
77 s
78 9
79 test/unit
80 x
81 7
82 require
83 s
84 7
85 coderay
86 x
87 17
88 PluginScannerTest
89 x
90 4
91 Test
92 n
93 x
94 4
95 Unit
96 x
97 8
98 TestCase
99 x
100 10
101 open_class
102 x
103 14
104 __class_init__
105 M
106 1
107 n
108 n
109 x
110 17
111 PluginScannerTest
112 i
113 16
114 5
115 66
116 99
117 7
118 0
119 7
120 1
121 65
122 67
123 49
124 2
125 0
126 49
127 3
128 4
129 11
130 I
131 5
132 I
133 0
134 I
135 0
136 I
137 0
138 n
139 p
140 4
141 x
142 9
143 test_load
144 M
145 1
146 n
147 n
148 x
149 9
150 test_load
151 i
152 48
153 5
154 45
155 0
156 1
157 45
158 0
159 2
160 65
161 49
162 3
163 0
164 49
165 4
166 1
167 7
168 5
169 64
170 49
171 6
172 2
173 47
174 49
175 7
176 1
177 15
178 5
179 7
180 8
181 64
182 45
183 9
184 10
185 7
186 11
187 49
188 12
189 1
190 49
191 13
192 0
193 49
194 14
195 0
196 47
197 49
198 15
199 2
200 11
201 I
202 4
203 I
204 0
205 I
206 0
207 I
208 0
209 n
210 p
211 16
212 x
213 4
214 File
215 n
216 n
217 x
218 11
219 active_path
220 x
221 7
222 dirname
223 s
224 4
225 vhdl
226 x
227 4
228 join
229 x
230 7
231 require
232 s
233 4
234 VHDL
235 x
236 7
237 CodeRay
238 n
239 x
240 4
241 vhdl
242 x
243 7
244 scanner
245 x
246 5
247 class
248 x
249 4
250 name
251 x
252 12
253 assert_equal
254 p
255 7
256 I
257 0
258 I
259 6
260 I
261 0
262 I
263 7
264 I
265 19
266 I
267 8
268 I
269 30
270 x
271 69
272 /Users/murphy/ruby/coderay-0.9/test/functional/load_plugin_scanner.rb
273 p
274 0
275 x
276 17
277 method_visibility
278 x
279 15
280 add_defn_method
281 p
282 3
283 I
284 2
285 I
286 6
287 I
288 10
289 x
290 69
291 /Users/murphy/ruby/coderay-0.9/test/functional/load_plugin_scanner.rb
292 p
293 0
294 x
295 13
296 attach_method
297 p
298 7
299 I
300 0
301 I
302 1
303 I
304 9
305 I
306 2
307 I
308 12
309 I
310 4
311 I
312 35
313 x
314 69
315 /Users/murphy/ruby/coderay-0.9/test/functional/load_plugin_scanner.rb
316 p
317 0
@@ -0,0 +1,12
1 require 'test/unit'
2
3 MYDIR = File.dirname(__FILE__)
4
5 $:.unshift 'lib'
6 require 'coderay'
7 puts "Running basic CodeRay #{CodeRay::VERSION} tests..."
8
9 suite = %w(basic load_plugin_scanner word_list)
10 for test_case in suite
11 load File.join(MYDIR, test_case + '.rb')
12 end
@@ -0,0 +1,322
1 !RBIX
2 0
3 x
4 M
5 1
6 n
7 n
8 x
9 10
10 __script__
11 i
12 95
13 5
14 7
15 0
16 64
17 47
18 49
19 1
20 1
21 15
22 65
23 7
24 2
25 45
26 3
27 4
28 65
29 49
30 5
31 0
32 49
33 6
34 1
35 49
36 7
37 2
38 15
39 99
40 43
41 8
42 7
43 9
44 49
45 10
46 1
47 7
48 11
49 64
50 49
51 12
52 1
53 15
54 5
55 7
56 13
57 64
58 47
59 49
60 1
61 1
62 15
63 5
64 7
65 14
66 45
67 15
68 16
69 43
70 17
71 47
72 49
73 18
74 0
75 7
76 19
77 63
78 3
79 47
80 49
81 20
82 1
83 15
84 7
85 21
86 64
87 7
88 22
89 64
90 7
91 23
92 64
93 35
94 3
95 19
96 0
97 15
98 20
99 0
100 56
101 24
102 50
103 25
104 0
105 15
106 2
107 11
108 I
109 6
110 I
111 2
112 I
113 0
114 I
115 0
116 n
117 p
118 26
119 s
120 9
121 test/unit
122 x
123 7
124 require
125 x
126 5
127 MYDIR
128 x
129 4
130 File
131 n
132 x
133 11
134 active_path
135 x
136 7
137 dirname
138 x
139 9
140 const_set
141 x
142 7
143 Globals
144 x
145 2
146 $:
147 x
148 2
149 []
150 s
151 3
152 lib
153 x
154 2
155 <<
156 s
157 7
158 coderay
159 s
160 22
161 Running basic CodeRay
162 x
163 7
164 CodeRay
165 n
166 x
167 7
168 VERSION
169 x
170 4
171 to_s
172 s
173 9
174 tests...
175 x
176 4
177 puts
178 s
179 5
180 basic
181 s
182 19
183 load_plugin_scanner
184 s
185 9
186 word_list
187 M
188 1
189 p
190 2
191 x
192 9
193 for_block
194 t
195 n
196 x
197 9
198 __block__
199 i
200 28
201 57
202 22
203 1
204 1
205 15
206 5
207 45
208 0
209 1
210 45
211 2
212 3
213 21
214 1
215 1
216 7
217 4
218 64
219 81
220 5
221 49
222 6
223 2
224 47
225 49
226 7
227 1
228 11
229 I
230 6
231 I
232 0
233 I
234 1
235 I
236 1
237 n
238 p
239 8
240 x
241 4
242 File
243 n
244 x
245 5
246 MYDIR
247 n
248 s
249 3
250 .rb
251 x
252 1
253 +
254 x
255 4
256 join
257 x
258 4
259 load
260 p
261 5
262 I
263 0
264 I
265 a
266 I
267 5
268 I
269 b
270 I
271 1c
272 x
273 55
274 /Users/murphy/ruby/coderay-0.9/test/functional/suite.rb
275 p
276 0
277 x
278 4
279 each
280 p
281 15
282 I
283 0
284 I
285 1
286 I
287 9
288 I
289 3
290 I
291 1a
292 I
293 5
294 I
295 29
296 I
297 6
298 I
299 32
300 I
301 7
302 I
303 47
304 I
305 9
306 I
307 55
308 I
309 a
310 I
311 5f
312 x
313 55
314 /Users/murphy/ruby/coderay-0.9/test/functional/suite.rb
315 p
316 2
317 x
318 5
319 suite
320 x
321 9
322 test_case
@@ -0,0 +1,126
1 class VHDL < CodeRay::Scanners::Scanner
2
3 register_for :vhdl
4
5 RESERVED_WORDS = [
6 'access','after','alias','all','assert','architecture','begin',
7 'block','body','buffer','bus','case','component','configuration','constant',
8 'disconnect','downto','else','elsif','end','entity','exit','file','for',
9 'function','generate','generic','group','guarded','if','impure','in',
10 'inertial','inout','is','label','library','linkage','literal','loop',
11 'map','new','next','null','of','on','open','others','out','package',
12 'port','postponed','procedure','process','pure','range','record','register',
13 'reject','report','return','select','severity','signal','shared','subtype',
14 'then','to','transport','type','unaffected','units','until','use','variable',
15 'wait','when','while','with','note','warning','error','failure','and',
16 'or','xor','not','nor',
17 'array'
18 ]
19
20 PREDEFINED_TYPES = [
21 'bit','bit_vector','character','boolean','integer','real','time','string',
22 'severity_level','positive','natural','signed','unsigned','line','text',
23 'std_logic','std_logic_vector','std_ulogic','std_ulogic_vector','qsim_state',
24 'qsim_state_vector','qsim_12state','qsim_12state_vector','qsim_strength',
25 'mux_bit','mux_vector','reg_bit','reg_vector','wor_bit','wor_vector'
26 ]
27
28 PREDEFINED_CONSTANTS = [
29
30 ]
31
32 IDENT_KIND = CodeRay::CaseIgnoringWordList.new(:ident).
33 add(RESERVED_WORDS, :reserved).
34 add(PREDEFINED_TYPES, :pre_type).
35 add(PREDEFINED_CONSTANTS, :pre_constant)
36
37 ESCAPE = / [rbfntv\n\\'"] | x[a-fA-F0-9]{1,2} | [0-7]{1,3} /x
38 UNICODE_ESCAPE = / u[a-fA-F0-9]{4} | U[a-fA-F0-9]{8} /x
39
40 def scan_tokens tokens, options
41
42 state = :initial
43
44 until eos?
45
46 kind = nil
47 match = nil
48
49 case state
50
51 when :initial
52
53 if scan(/ \s+ | \\\n /x)
54 kind = :space
55
56 elsif scan(/-- .*/x)
57 kind = :comment
58
59 elsif scan(/ [-+*\/=<>?:;,!&^|()\[\]{}~%]+ | \.(?!\d) /x)
60 kind = :operator
61
62 elsif match = scan(/ [A-Za-z_][A-Za-z_0-9]* /x)
63 kind = IDENT_KIND[match.downcase]
64
65 elsif match = scan(/[a-z]?"/i)
66 tokens << [:open, :string]
67 state = :string
68 kind = :delimiter
69
70 elsif scan(/ L?' (?: [^\'\n\\] | \\ #{ESCAPE} )? '? /ox)
71 kind = :char
72
73 elsif scan(/(?:\d+)(?![.eEfF])/)
74 kind = :integer
75
76 elsif scan(/\d[fF]?|\d*\.\d+(?:[eE][+-]?\d+)?[fF]?|\d+[eE][+-]?\d+[fF]?/)
77 kind = :float
78
79 else
80 getch
81 kind = :error
82
83 end
84
85 when :string
86 if scan(/[^\\\n"]+/)
87 kind = :content
88 elsif scan(/"/)
89 tokens << ['"', :delimiter]
90 tokens << [:close, :string]
91 state = :initial
92 next
93 elsif scan(/ \\ (?: #{ESCAPE} | #{UNICODE_ESCAPE} ) /mox)
94 kind = :char
95 elsif scan(/ \\ | $ /x)
96 tokens << [:close, :string]
97 kind = :error
98 state = :initial
99 else
100 raise_inspect "else case \" reached; %p not handled." % peek(1), tokens
101 end
102
103 else
104 raise_inspect 'Unknown state', tokens
105
106 end
107
108 match ||= matched
109 if $DEBUG and not kind
110 raise_inspect 'Error token %p in line %d' %
111 [[match, kind], line], tokens
112 end
113 raise_inspect 'Empty token', tokens unless match
114
115 tokens << [match, kind]
116
117 end
118
119 if state == :string
120 tokens << [:close, :string]
121 end
122
123 tokens
124 end
125
126 end
This diff has been collapsed as it changes many lines, (2334 lines changed) Show them Hide them
@@ -0,0 +1,2334
1 !RBIX
2 0
3 x
4 M
5 1
6 n
7 n
8 x
9 10
10 __script__
11 i
12 35
13 99
14 7
15 0
16 45
17 1
18 2
19 43
20 3
21 43
22 4
23 65
24 49
25 5
26 3
27 13
28 99
29 12
30 7
31 6
32 12
33 7
34 7
35 12
36 65
37 12
38 49
39 8
40 4
41 15
42 49
43 6
44 0
45 15
46 2
47 11
48 I
49 6
50 I
51 0
52 I
53 0
54 I
55 0
56 n
57 p
58 9
59 x
60 4
61 VHDL
62 x
63 7
64 CodeRay
65 n
66 x
67 8
68 Scanners
69 x
70 7
71 Scanner
72 x
73 10
74 open_class
75 x
76 14
77 __class_init__
78 M
79 1
80 n
81 n
82 x
83 4
84 VHDL
85 i
86 519
87 5
88 66
89 5
90 7
91 0
92 47
93 49
94 1
95 1
96 15
97 65
98 7
99 2
100 7
101 3
102 64
103 7
104 4
105 64
106 7
107 5
108 64
109 7
110 6
111 64
112 7
113 7
114 64
115 7
116 8
117 64
118 7
119 9
120 64
121 7
122 10
123 64
124 7
125 11
126 64
127 7
128 12
129 64
130 7
131 13
132 64
133 7
134 14
135 64
136 7
137 15
138 64
139 7
140 16
141 64
142 7
143 17
144 64
145 7
146 18
147 64
148 7
149 19
150 64
151 7
152 20
153 64
154 7
155 21
156 64
157 7
158 22
159 64
160 7
161 23
162 64
163 7
164 24
165 64
166 7
167 25
168 64
169 7
170 26
171 64
172 7
173 27
174 64
175 7
176 28
177 64
178 7
179 29
180 64
181 7
182 30
183 64
184 7
185 31
186 64
187 7
188 32
189 64
190 7
191 33
192 64
193 7
194 34
195 64
196 7
197 35
198 64
199 7
200 36
201 64
202 7
203 37
204 64
205 7
206 38
207 64
208 7
209 39
210 64
211 7
212 40
213 64
214 7
215 41
216 64
217 7
218 42
219 64
220 7
221 43
222 64
223 7
224 44
225 64
226 7
227 45
228 64
229 7
230 46
231 64
232 7
233 47
234 64
235 7
236 48
237 64
238 7
239 49
240 64
241 7
242 50
243 64
244 7
245 51
246 64
247 7
248 52
249 64
250 7
251 53
252 64
253 7
254 54
255 64
256 7
257 55
258 64
259 7
260 56
261 64
262 7
263 57
264 64
265 7
266 58
267 64
268 7
269 59
270 64
271 7
272 60
273 64
274 7
275 61
276 64
277 7
278 62
279 64
280 7
281 63
282 64
283 7
284 64
285 64
286 7
287 65
288 64
289 7
290 66
291 64
292 7
293 67
294 64
295 7
296 68
297 64
298 7
299 69
300 64
301 7
302 70
303 64
304 7
305 71
306 64
307 7
308 72
309 64
310 7
311 73
312 64
313 7
314 74
315 64
316 7
317 75
318 64
319 7
320 76
321 64
322 7
323 77
324 64
325 7
326 78
327 64
328 7
329 79
330 64
331 7
332 80
333 64
334 7
335 81
336 64
337 7
338 82
339 64
340 7
341 83
342 64
343 7
344 84
345 64
346 7
347 85
348 64
349 7
350 86
351 64
352 7
353 87
354 64
355 7
356 88
357 64
358 7
359 89
360 64
361 7
362 90
363 64
364 7
365 91
366 64
367 35
368 89
369 49
370 92
371 2
372 15
373 65
374 7
375 93
376 7
377 94
378 64
379 7
380 95
381 64
382 7
383 96
384 64
385 7
386 97
387 64
388 7
389 98
390 64
391 7
392 99
393 64
394 7
395 100
396 64
397 7
398 101
399 64
400 7
401 102
402 64
403 7
404 103
405 64
406 7
407 104
408 64
409 7
410 105
411 64
412 7
413 106
414 64
415 7
416 107
417 64
418 7
419 108
420 64
421 7
422 109
423 64
424 7
425 110
426 64
427 7
428 111
429 64
430 7
431 112
432 64
433 7
434 113
435 64
436 7
437 114
438 64
439 7
440 115
441 64
442 7
443 116
444 64
445 7
446 117
447 64
448 7
449 118
450 64
451 7
452 119
453 64
454 7
455 120
456 64
457 7
458 121
459 64
460 7
461 122
462 64
463 7
464 123
465 64
466 35
467 30
468 49
469 92
470 2
471 15
472 65
473 7
474 124
475 35
476 0
477 49
478 92
479 2
480 15
481 65
482 7
483 125
484 45
485 126
486 127
487 43
488 128
489 13
490 71
491 129
492 47
493 9
494 422
495 47
496 49
497 130
498 0
499 13
500 7
501 131
502 47
503 49
504 132
505 1
506 15
507 8
508 427
509 7
510 131
511 49
512 129
513 1
514 45
515 2
516 133
517 7
518 134
519 49
520 135
521 2
522 45
523 93
524 136
525 7
526 137
527 49
528 135
529 2
530 45
531 124
532 138
533 7
534 139
535 49
536 135
537 2
538 49
539 92
540 2
541 15
542 65
543 7
544 140
545 7
546 141
547 13
548 70
549 9
550 476
551 15
552 44
553 43
554 142
555 7
556 143
557 80
558 49
559 129
560 2
561 6
562 141
563 49
564 92
565 2
566 15
567 65
568 7
569 144
570 7
571 145
572 13
573 70
574 9
575 501
576 15
577 44
578 43
579 142
580 7
581 146
582 80
583 49
584 129
585 2
586 6
587 145
588 49
589 92
590 2
591 15
592 99
593 7
594 147
595 7
596 148
597 65
598 67
599 49
600 149
601 0
602 49
603 150
604 4
605 11
606 I
607 5b
608 I
609 0
610 I
611 0
612 I
613 0
614 n
615 p
616 151
617 x
618 4
619 vhdl
620 x
621 12
622 register_for
623 x
624 14
625 RESERVED_WORDS
626 s
627 6
628 access
629 s
630 5
631 after
632 s
633 5
634 alias
635 s
636 3
637 all
638 s
639 6
640 assert
641 s
642 12
643 architecture
644 s
645 5
646 begin
647 s
648 5
649 block
650 s
651 4
652 body
653 s
654 6
655 buffer
656 s
657 3
658 bus
659 s
660 4
661 case
662 s
663 9
664 component
665 s
666 13
667 configuration
668 s
669 8
670 constant
671 s
672 10
673 disconnect
674 s
675 6
676 downto
677 s
678 4
679 else
680 s
681 5
682 elsif
683 s
684 3
685 end
686 s
687 6
688 entity
689 s
690 4
691 exit
692 s
693 4
694 file
695 s
696 3
697 for
698 s
699 8
700 function
701 s
702 8
703 generate
704 s
705 7
706 generic
707 s
708 5
709 group
710 s
711 7
712 guarded
713 s
714 2
715 if
716 s
717 6
718 impure
719 s
720 2
721 in
722 s
723 8
724 inertial
725 s
726 5
727 inout
728 s
729 2
730 is
731 s
732 5
733 label
734 s
735 7
736 library
737 s
738 7
739 linkage
740 s
741 7
742 literal
743 s
744 4
745 loop
746 s
747 3
748 map
749 s
750 3
751 new
752 s
753 4
754 next
755 s
756 4
757 null
758 s
759 2
760 of
761 s
762 2
763 on
764 s
765 4
766 open
767 s
768 6
769 others
770 s
771 3
772 out
773 s
774 7
775 package
776 s
777 4
778 port
779 s
780 9
781 postponed
782 s
783 9
784 procedure
785 s
786 7
787 process
788 s
789 4
790 pure
791 s
792 5
793 range
794 s
795 6
796 record
797 s
798 8
799 register
800 s
801 6
802 reject
803 s
804 6
805 report
806 s
807 6
808 return
809 s
810 6
811 select
812 s
813 8
814 severity
815 s
816 6
817 signal
818 s
819 6
820 shared
821 s
822 7
823 subtype
824 s
825 4
826 then
827 s
828 2
829 to
830 s
831 9
832 transport
833 s
834 4
835 type
836 s
837 10
838 unaffected
839 s
840 5
841 units
842 s
843 5
844 until
845 s
846 3
847 use
848 s
849 8
850 variable
851 s
852 4
853 wait
854 s
855 4
856 when
857 s
858 5
859 while
860 s
861 4
862 with
863 s
864 4
865 note
866 s
867 7
868 warning
869 s
870 5
871 error
872 s
873 7
874 failure
875 s
876 3
877 and
878 s
879 2
880 or
881 s
882 3
883 xor
884 s
885 3
886 not
887 s
888 3
889 nor
890 s
891 5
892 array
893 x
894 9
895 const_set
896 x
897 16
898 PREDEFINED_TYPES
899 s
900 3
901 bit
902 s
903 10
904 bit_vector
905 s
906 9
907 character
908 s
909 7
910 boolean
911 s
912 7
913 integer
914 s
915 4
916 real
917 s
918 4
919 time
920 s
921 6
922 string
923 s
924 14
925 severity_level
926 s
927 8
928 positive
929 s
930 7
931 natural
932 s
933 6
934 signed
935 s
936 8
937 unsigned
938 s
939 4
940 line
941 s
942 4
943 text
944 s
945 9
946 std_logic
947 s
948 16
949 std_logic_vector
950 s
951 10
952 std_ulogic
953 s
954 17
955 std_ulogic_vector
956 s
957 10
958 qsim_state
959 s
960 17
961 qsim_state_vector
962 s
963 12
964 qsim_12state
965 s
966 19
967 qsim_12state_vector
968 s
969 13
970 qsim_strength
971 s
972 7
973 mux_bit
974 s
975 10
976 mux_vector
977 s
978 7
979 reg_bit
980 s
981 10
982 reg_vector
983 s
984 7
985 wor_bit
986 s
987 10
988 wor_vector
989 x
990 20
991 PREDEFINED_CONSTANTS
992 x
993 10
994 IDENT_KIND
995 x
996 7
997 CodeRay
998 n
999 x
1000 20
1001 CaseIgnoringWordList
1002 x
1003 3
1004 new
1005 x
1006 8
1007 allocate
1008 x
1009 5
1010 ident
1011 x
1012 10
1013 initialize
1014 n
1015 x
1016 8
1017 reserved
1018 x
1019 3
1020 add
1021 n
1022 x
1023 8
1024 pre_type
1025 n
1026 x
1027 12
1028 pre_constant
1029 x
1030 6
1031 ESCAPE
1032 n
1033 x
1034 6
1035 Regexp
1036 s
1037 49
1038 [rbfntv\n\\'"] | x[a-fA-F0-9]{1,2} | [0-7]{1,3}
1039 x
1040 14
1041 UNICODE_ESCAPE
1042 n
1043 s
1044 35
1045 u[a-fA-F0-9]{4} | U[a-fA-F0-9]{8}
1046 x
1047 11
1048 scan_tokens
1049 M
1050 1
1051 n
1052 n
1053 x
1054 11
1055 scan_tokens
1056 i
1057 688
1058 7
1059 0
1060 19
1061 2
1062 15
1063 5
1064 47
1065 49
1066 1
1067 0
1068 10
1069 660
1070 1
1071 19
1072 3
1073 15
1074 1
1075 19
1076 4
1077 15
1078 20
1079 2
1080 13
1081 7
1082 0
1083 12
1084 49
1085 2
1086 1
1087 9
1088 331
1089 15
1090 5
1091 7
1092 3
1093 13
1094 70
1095 9
1096 51
1097 15
1098 44
1099 43
1100 4
1101 7
1102 5
1103 80
1104 49
1105 6
1106 2
1107 6
1108 3
1109 47
1110 49
1111 7
1112 1
1113 9
1114 63
1115 7
1116 8
1117 19
1118 3
1119 8
1120 329
1121 5
1122 7
1123 9
1124 13
1125 70
1126 9
1127 82
1128 15
1129 44
1130 43
1131 4
1132 7
1133 10
1134 80
1135 49
1136 6
1137 2
1138 6
1139 9
1140 47
1141 49
1142 7
1143 1
1144 9
1145 94
1146 7
1147 11
1148 19
1149 3
1150 8
1151 329
1152 5
1153 7
1154 12
1155 13
1156 70
1157 9
1158 113
1159 15
1160 44
1161 43
1162 4
1163 7
1164 13
1165 80
1166 49
1167 6
1168 2
1169 6
1170 12
1171 47
1172 49
1173 7
1174 1
1175 9
1176 125
1177 7
1178 14
1179 19
1180 3
1181 8
1182 329
1183 5
1184 7
1185 15
1186 13
1187 70
1188 9
1189 144
1190 15
1191 44
1192 43
1193 4
1194 7
1195 16
1196 80
1197 49
1198 6
1199 2
1200 6
1201 15
1202 47
1203 49
1204 7
1205 1
1206 19
1207 4
1208 9
1209 167
1210 45
1211 17
1212 18
1213 20
1214 4
1215 49
1216 19
1217 0
1218 49
1219 20
1220 1
1221 19
1222 3
1223 8
1224 329
1225 5
1226 7
1227 21
1228 13
1229 70
1230 9
1231 186
1232 15
1233 44
1234 43
1235 4
1236 7
1237 22
1238 79
1239 49
1240 6
1241 2
1242 6
1243 21
1244 47
1245 49
1246 7
1247 1
1248 19
1249 4
1250 9
1251 217
1252 20
1253 0
1254 7
1255 23
1256 7
1257 24
1258 35
1259 2
1260 49
1261 25
1262 1
1263 15
1264 7
1265 24
1266 19
1267 2
1268 15
1269 7
1270 26
1271 19
1272 3
1273 8
1274 329
1275 5
1276 7
1277 27
1278 13
1279 70
1280 9
1281 247
1282 15
1283 44
1284 43
1285 4
1286 7
1287 28
1288 45
1289 29
1290 30
1291 47
1292 49
1293 31
1294 0
1295 7
1296 32
1297 63
1298 3
1299 80
1300 49
1301 6
1302 2
1303 6
1304 27
1305 47
1306 49
1307 7
1308 1
1309 9
1310 259
1311 7
1312 33
1313 19
1314 3
1315 8
1316 329
1317 5
1318 7
1319 34
1320 13
1321 70
1322 9
1323 278
1324 15
1325 44
1326 43
1327 4
1328 7
1329 35
1330 78
1331 49
1332 6
1333 2
1334 6
1335 34
1336 47
1337 49
1338 7
1339 1
1340 9
1341 290
1342 7
1343 36
1344 19
1345 3
1346 8
1347 329
1348 5
1349 7
1350 37
1351 13
1352 70
1353 9
1354 309
1355 15
1356 44
1357 43
1358 4
1359 7
1360 38
1361 78
1362 49
1363 6
1364 2
1365 6
1366 37
1367 47
1368 49
1369 7
1370 1
1371 9
1372 321
1373 7
1374 39
1375 19
1376 3
1377 8
1378 329
1379 5
1380 48
1381 40
1382 15
1383 7
1384 41
1385 19
1386 3
1387 8
1388 564
1389 13
1390 7
1391 24
1392 12
1393 49
1394 2
1395 1
1396 9
1397 553
1398 15
1399 5
1400 7
1401 42
1402 13
1403 70
1404 9
1405 360
1406 15
1407 44
1408 43
1409 4
1410 7
1411 43
1412 78
1413 49
1414 6
1415 2
1416 6
1417 42
1418 47
1419 49
1420 7
1421 1
1422 9
1423 372
1424 7
1425 44
1426 19
1427 3
1428 8
1429 551
1430 5
1431 7
1432 45
1433 13
1434 70
1435 9
1436 391
1437 15
1438 44
1439 43
1440 4
1441 7
1442 46
1443 78
1444 49
1445 6
1446 2
1447 6
1448 45
1449 47
1450 49
1451 7
1452 1
1453 9
1454 432
1455 20
1456 0
1457 7
1458 46
1459 64
1460 7
1461 26
1462 35
1463 2
1464 49
1465 25
1466 1
1467 15
1468 20
1469 0
1470 7
1471 47
1472 7
1473 24
1474 35
1475 2
1476 49
1477 25
1478 1
1479 15
1480 7
1481 0
1482 19
1483 2
1484 15
1485 1
1486 8
1487 656
1488 8
1489 551
1490 5
1491 7
1492 48
1493 13
1494 70
1495 9
1496 472
1497 15
1498 44
1499 43
1500 4
1501 7
1502 49
1503 45
1504 29
1505 50
1506 47
1507 49
1508 31
1509 0
1510 7
1511 51
1512 45
1513 52
1514 53
1515 47
1516 49
1517 31
1518 0
1519 7
1520 54
1521 63
1522 5
1523 4
1524 6
1525 49
1526 6
1527 2
1528 6
1529 48
1530 47
1531 49
1532 7
1533 1
1534 9
1535 484
1536 7
1537 33
1538 19
1539 3
1540 8
1541 551
1542 5
1543 7
1544 55
1545 13
1546 70
1547 9
1548 503
1549 15
1550 44
1551 43
1552 4
1553 7
1554 56
1555 80
1556 49
1557 6
1558 2
1559 6
1560 55
1561 47
1562 49
1563 7
1564 1
1565 9
1566 532
1567 20
1568 0
1569 7
1570 47
1571 7
1572 24
1573 35
1574 2
1575 49
1576 25
1577 1
1578 15
1579 7
1580 41
1581 19
1582 3
1583 15
1584 7
1585 0
1586 19
1587 2
1588 8
1589 551
1590 5
1591 7
1592 57
1593 64
1594 5
1595 79
1596 47
1597 49
1598 58
1599 1
1600 49
1601 59
1602 1
1603 20
1604 0
1605 47
1606 49
1607 60
1608 2
1609 8
1610 564
1611 15
1612 5
1613 7
1614 61
1615 64
1616 20
1617 0
1618 47
1619 49
1620 60
1621 2
1622 15
1623 20
1624 4
1625 13
1626 10
1627 576
1628 15
1629 5
1630 48
1631 62
1632 19
1633 4
1634 15
1635 99
1636 43
1637 63
1638 7
1639 64
1640 49
1641 20
1642 1
1643 13
1644 9
1645 597
1646 15
1647 20
1648 3
1649 10
1650 596
1651 2
1652 8
1653 597
1654 3
1655 9
1656 625
1657 5
1658 7
1659 65
1660 64
1661 20
1662 4
1663 20
1664 3
1665 35
1666 2
1667 5
1668 48
1669 66
1670 35
1671 2
1672 49
1673 59
1674 1
1675 20
1676 0
1677 47
1678 49
1679 60
1680 2
1681 8
1682 626
1683 1
1684 15
1685 20
1686 4
1687 9
1688 634
1689 1
1690 8
1691 644
1692 5
1693 7
1694 67
1695 64
1696 20
1697 0
1698 47
1699 49
1700 60
1701 2
1702 15
1703 20
1704 0
1705 20
1706 4
1707 20
1708 3
1709 35
1710 2
1711 49
1712 25
1713 1
1714 15
1715 68
1716 8
1717 5
1718 1
1719 15
1720 20
1721 2
1722 7
1723 24
1724 83
1725 68
1726 9
1727 683
1728 20
1729 0
1730 7
1731 47
1732 7
1733 24
1734 35
1735 2
1736 49
1737 25
1738 1
1739 8
1740 684
1741 1
1742 15
1743 20
1744 0
1745 11
1746 I
1747 c
1748 I
1749 5
1750 I
1751 2
1752 I
1753 2
1754 n
1755 p
1756 69
1757 x
1758 7
1759 initial
1760 x
1761 4
1762 eos?
1763 x
1764 3
1765 ===
1766 n
1767 x
1768 6
1769 Regexp
1770 s
1771 12
1772 \s+ | \\\n
1773 x
1774 3
1775 new
1776 x
1777 4
1778 scan
1779 x
1780 5
1781 space
1782 n
1783 s
1784 5
1785 -- .*
1786 x
1787 7
1788 comment
1789 n
1790 s
1791 42
1792 [-+*\/=<>?:;,!&^|()\[\]{}~%]+ | \.(?!\d)
1793 x
1794 8
1795 operator
1796 n
1797 s
1798 24
1799 [A-Za-z_][A-Za-z_0-9]*
1800 x
1801 10
1802 IDENT_KIND
1803 n
1804 x
1805 8
1806 downcase
1807 x
1808 2
1809 []
1810 n
1811 s
1812 7
1813 [a-z]?"
1814 x
1815 4
1816 open
1817 x
1818 6
1819 string
1820 x
1821 2
1822 <<
1823 x
1824 9
1825 delimiter
1826 n
1827 s
1828 24
1829 L?' (?: [^\'\n\\] | \\
1830 x
1831 6
1832 ESCAPE
1833 n
1834 x
1835 4
1836 to_s
1837 s
1838 7
1839 )? '?
1840 x
1841 4
1842 char
1843 n
1844 s
1845 18
1846 (?:\d+)(?![.eEfF])
1847 x
1848 7
1849 integer
1850 n
1851 s
1852 59
1853 \d[fF]?|\d*\.\d+(?:[eE][+-]?\d+)?[fF]?|\d+[eE][+-]?\d+[fF]?
1854 x
1855 5
1856 float
1857 x
1858 5
1859 getch
1860 x
1861 5
1862 error
1863 n
1864 s
1865 9
1866 [^\\\n"]+
1867 x
1868 7
1869 content
1870 n
1871 s
1872 1
1873 "
1874 x
1875 5
1876 close
1877 n
1878 s
1879 8
1880 \\ (?:
1881 n
1882 s
1883 3
1884 |
1885 x
1886 14
1887 UNICODE_ESCAPE
1888 n
1889 s
1890 3
1891 )
1892 n
1893 s
1894 8
1895 \\ | $
1896 s
1897 36
1898 else case " reached; %p not handled.
1899 x
1900 4
1901 peek
1902 x
1903 1
1904 %
1905 x
1906 13
1907 raise_inspect
1908 s
1909 13
1910 Unknown state
1911 x
1912 7
1913 matched
1914 x
1915 7
1916 Globals
1917 x
1918 6
1919 $DEBUG
1920 s
1921 25
1922 Error token %p in line %d
1923 x
1924 4
1925 line
1926 s
1927 11
1928 Empty token
1929 x
1930 2
1931 ==
1932 p
1933 111
1934 I
1935 0
1936 I
1937 28
1938 I
1939 0
1940 I
1941 2a
1942 I
1943 5
1944 I
1945 2c
1946 I
1947 c
1948 I
1949 2e
1950 I
1951 10
1952 I
1953 2f
1954 I
1955 14
1956 I
1957 31
1958 I
1959 17
1960 I
1961 33
1962 I
1963 20
1964 I
1965 35
1966 I
1967 39
1968 I
1969 36
1970 I
1971 3f
1972 I
1973 38
1974 I
1975 58
1976 I
1977 39
1978 I
1979 5e
1980 I
1981 3b
1982 I
1983 77
1984 I
1985 3c
1986 I
1987 7d
1988 I
1989 3e
1990 I
1991 98
1992 I
1993 3f
1994 I
1995 a7
1996 I
1997 41
1998 I
1999 c2
2000 I
2001 42
2002 I
2003 ce
2004 I
2005 43
2006 I
2007 d3
2008 I
2009 44
2010 I
2011 d9
2012 I
2013 46
2014 I
2015 fd
2016 I
2017 47
2018 I
2019 103
2020 I
2021 49
2022 I
2023 11c
2024 I
2025 4a
2026 I
2027 122
2028 I
2029 4c
2030 I
2031 13b
2032 I
2033 4d
2034 I
2035 141
2036 I
2037 50
2038 I
2039 145
2040 I
2041 51
2042 I
2043 14c
2044 I
2045 55
2046 I
2047 155
2048 I
2049 56
2050 I
2051 16e
2052 I
2053 57
2054 I
2055 174
2056 I
2057 58
2058 I
2059 18d
2060 I
2061 59
2062 I
2063 19a
2064 I
2065 5a
2066 I
2067 1a6
2068 I
2069 5b
2070 I
2071 1ab
2072 I
2073 5c
2074 I
2075 1b0
2076 I
2077 5d
2078 I
2079 1de
2080 I
2081 5e
2082 I
2083 1e4
2084 I
2085 5f
2086 I
2087 1fd
2088 I
2089 60
2090 I
2091 209
2092 I
2093 61
2094 I
2095 20e
2096 I
2097 62
2098 I
2099 214
2100 I
2101 64
2102 I
2103 22a
2104 I
2105 68
2106 I
2107 235
2108 I
2109 6c
2110 I
2111 241
2112 I
2113 6d
2114 I
2115 257
2116 I
2117 6f
2118 I
2119 258
2120 I
2121 6e
2122 I
2123 25b
2124 I
2125 6f
2126 I
2127 271
2128 I
2129 6d
2130 I
2131 273
2132 I
2133 71
2134 I
2135 285
2136 I
2137 73
2138 I
2139 296
2140 I
2141 77
2142 I
2143 29e
2144 I
2145 78
2146 I
2147 2ab
2148 I
2149 77
2150 I
2151 2ad
2152 I
2153 7b
2154 I
2155 2b0
2156 x
2157 54
2158 /Users/murphy/ruby/coderay-0.9/test/functional/vhdl.rb
2159 p
2160 5
2161 x
2162 6
2163 tokens
2164 x
2165 7
2166 options
2167 x
2168 5
2169 state
2170 x
2171 4
2172 kind
2173 x
2174 5
2175 match
2176 x
2177 17
2178 method_visibility
2179 x
2180 15
2181 add_defn_method
2182 p
2183 65
2184 I
2185 2
2186 I
2187 3
2188 I
2189 a
2190 I
2191 5
2192 I
2193 d
2194 I
2195 6
2196 I
2197 22
2198 I
2199 7
2200 I
2201 3a
2202 I
2203 8
2204 I
2205 55
2206 I
2207 9
2208 I
2209 6d
2210 I
2211 a
2212 I
2213 85
2214 I
2215 b
2216 I
2217 a3
2218 I
2219 c
2220 I
2221 bb
2222 I
2223 d
2224 I
2225 d3
2226 I
2227 e
2228 I
2229 ee
2230 I
2231 f
2232 I
2233 109
2234 I
2235 10
2236 I
2237 115
2238 I
2239 11
2240 I
2241 11e
2242 I
2243 14
2244 I
2245 121
2246 I
2247 15
2248 I
2249 139
2250 I
2251 16
2252 I
2253 14e
2254 I
2255 17
2256 I
2257 15d
2258 I
2259 18
2260 I
2261 169
2262 I
2263 19
2264 I
2265 181
2266 I
2267 1c
2268 I
2269 184
2270 I
2271 1e
2272 I
2273 18a
2274 I
2275 20
2276 I
2277 1ab
2278 I
2279 21
2280 I
2281 1b0
2282 I
2283 20
2284 I
2285 1b3
2286 I
2287 22
2288 I
2289 1b8
2290 I
2291 20
2292 I
2293 1bb
2294 I
2295 23
2296 I
2297 1c0
2298 I
2299 20
2300 I
2301 1c7
2302 I
2303 25
2304 I
2305 1e0
2306 I
2307 26
2308 I
2309 1f9
2310 I
2311 28
2312 I
2313 207
2314 x
2315 54
2316 /Users/murphy/ruby/coderay-0.9/test/functional/vhdl.rb
2317 p
2318 0
2319 x
2320 13
2321 attach_method
2322 p
2323 3
2324 I
2325 0
2326 I
2327 1
2328 I
2329 23
2330 x
2331 54
2332 /Users/murphy/ruby/coderay-0.9/test/functional/vhdl.rb
2333 p
2334 0
@@ -0,0 +1,79
1 require 'test/unit'
2 require 'coderay'
3
4 class WordListTest < Test::Unit::TestCase
5
6 include CodeRay
7
8 # define word arrays
9 RESERVED_WORDS = %w[
10 asm break case continue default do else
11 ...
12 ]
13
14 PREDEFINED_TYPES = %w[
15 int long short char void
16 ...
17 ]
18
19 PREDEFINED_CONSTANTS = %w[
20 EOF NULL ...
21 ]
22
23 # make a WordList
24 IDENT_KIND = WordList.new(:ident).
25 add(RESERVED_WORDS, :reserved).
26 add(PREDEFINED_TYPES, :pre_type).
27 add(PREDEFINED_CONSTANTS, :pre_constant)
28
29 def test_word_list_example
30 assert_equal :pre_type, IDENT_KIND['void']
31 # assert_equal :pre_constant, IDENT_KIND['...'] # not specified
32 end
33
34 def test_word_list
35 list = WordList.new(:ident).add(['foobar'], :reserved)
36 assert_equal :reserved, list['foobar']
37 assert_equal :ident, list['FooBar']
38 end
39
40 def test_word_list_cached
41 list = WordList.new(:ident, true).add(['foobar'], :reserved)
42 assert_equal :reserved, list['foobar']
43 assert_equal :ident, list['FooBar']
44 end
45
46 def test_case_ignoring_word_list
47 list = CaseIgnoringWordList.new(:ident).add(['foobar'], :reserved)
48 assert_equal :ident, list['foo']
49 assert_equal :reserved, list['foobar']
50 assert_equal :reserved, list['FooBar']
51
52 list = CaseIgnoringWordList.new(:ident).add(['FooBar'], :reserved)
53 assert_equal :ident, list['foo']
54 assert_equal :reserved, list['foobar']
55 assert_equal :reserved, list['FooBar']
56 end
57
58 def test_case_ignoring_word_list_cached
59 list = CaseIgnoringWordList.new(:ident, true).add(['foobar'], :reserved)
60 assert_equal :ident, list['foo']
61 assert_equal :reserved, list['foobar']
62 assert_equal :reserved, list['FooBar']
63
64 list = CaseIgnoringWordList.new(:ident, true).add(['FooBar'], :reserved)
65 assert_equal :ident, list['foo']
66 assert_equal :reserved, list['foobar']
67 assert_equal :reserved, list['FooBar']
68 end
69
70 def test_dup
71 list = WordList.new(:ident).add(['foobar'], :reserved)
72 assert_equal :reserved, list['foobar']
73 list2 = list.dup
74 list2.add(%w[foobar], :keyword)
75 assert_equal :keyword, list2['foobar']
76 assert_equal :reserved, list['foobar']
77 end
78
79 end No newline at end of file
This diff has been collapsed as it changes many lines, (1763 lines changed) Show them Hide them
@@ -0,0 +1,1763
1 !RBIX
2 0
3 x
4 M
5 1
6 n
7 n
8 x
9 10
10 __script__
11 i
12 53
13 5
14 7
15 0
16 64
17 47
18 49
19 1
20 1
21 15
22 5
23 7
24 2
25 64
26 47
27 49
28 1
29 1
30 15
31 99
32 7
33 3
34 45
35 4
36 5
37 43
38 6
39 43
40 7
41 65
42 49
43 8
44 3
45 13
46 99
47 12
48 7
49 9
50 12
51 7
52 10
53 12
54 65
55 12
56 49
57 11
58 4
59 15
60 49
61 9
62 0
63 15
64 2
65 11
66 I
67 6
68 I
69 0
70 I
71 0
72 I
73 0
74 n
75 p
76 12
77 s
78 9
79 test/unit
80 x
81 7
82 require
83 s
84 7
85 coderay
86 x
87 12
88 WordListTest
89 x
90 4
91 Test
92 n
93 x
94 4
95 Unit
96 x
97 8
98 TestCase
99 x
100 10
101 open_class
102 x
103 14
104 __class_init__
105 M
106 1
107 n
108 n
109 x
110 12
111 WordListTest
112 i
113 232
114 5
115 66
116 5
117 45
118 0
119 1
120 47
121 49
122 2
123 1
124 15
125 65
126 7
127 3
128 7
129 4
130 64
131 7
132 5
133 64
134 7
135 6
136 64
137 7
138 7
139 64
140 7
141 8
142 64
143 7
144 9
145 64
146 7
147 10
148 64
149 7
150 11
151 64
152 35
153 8
154 49
155 12
156 2
157 15
158 65
159 7
160 13
161 7
162 14
163 64
164 7
165 15
166 64
167 7
168 16
169 64
170 7
171 17
172 64
173 7
174 18
175 64
176 7
177 11
178 64
179 35
180 6
181 49
182 12
183 2
184 15
185 65
186 7
187 19
188 7
189 20
190 64
191 7
192 21
193 64
194 7
195 11
196 64
197 35
198 3
199 49
200 12
201 2
202 15
203 65
204 7
205 22
206 45
207 23
208 24
209 13
210 71
211 25
212 47
213 9
214 115
215 47
216 49
217 26
218 0
219 13
220 7
221 27
222 47
223 49
224 28
225 1
226 15
227 8
228 120
229 7
230 27
231 49
232 25
233 1
234 45
235 3
236 29
237 7
238 30
239 49
240 31
241 2
242 45
243 13
244 32
245 7
246 33
247 49
248 31
249 2
250 45
251 19
252 34
253 7
254 35
255 49
256 31
257 2
258 49
259 12
260 2
261 15
262 99
263 7
264 36
265 7
266 37
267 65
268 67
269 49
270 38
271 0
272 49
273 39
274 4
275 15
276 99
277 7
278 40
279 7
280 41
281 65
282 67
283 49
284 38
285 0
286 49
287 39
288 4
289 15
290 99
291 7
292 42
293 7
294 43
295 65
296 67
297 49
298 38
299 0
300 49
301 39
302 4
303 15
304 99
305 7
306 44
307 7
308 45
309 65
310 67
311 49
312 38
313 0
314 49
315 39
316 4
317 15
318 99
319 7
320 46
321 7
322 47
323 65
324 67
325 49
326 38
327 0
328 49
329 39
330 4
331 15
332 99
333 7
334 48
335 7
336 49
337 65
338 67
339 49
340 38
341 0
342 49
343 39
344 4
345 11
346 I
347 a
348 I
349 0
350 I
351 0
352 I
353 0
354 n
355 p
356 50
357 x
358 7
359 CodeRay
360 n
361 x
362 7
363 include
364 x
365 14
366 RESERVED_WORDS
367 s
368 3
369 asm
370 s
371 5
372 break
373 s
374 4
375 case
376 s
377 8
378 continue
379 s
380 7
381 default
382 s
383 2
384 do
385 s
386 4
387 else
388 s
389 3
390 ...
391 x
392 9
393 const_set
394 x
395 16
396 PREDEFINED_TYPES
397 s
398 3
399 int
400 s
401 4
402 long
403 s
404 5
405 short
406 s
407 4
408 char
409 s
410 4
411 void
412 x
413 20
414 PREDEFINED_CONSTANTS
415 s
416 3
417 EOF
418 s
419 4
420 NULL
421 x
422 10
423 IDENT_KIND
424 x
425 8
426 WordList
427 n
428 x
429 3
430 new
431 x
432 8
433 allocate
434 x
435 5
436 ident
437 x
438 10
439 initialize
440 n
441 x
442 8
443 reserved
444 x
445 3
446 add
447 n
448 x
449 8
450 pre_type
451 n
452 x
453 12
454 pre_constant
455 x
456 22
457 test_word_list_example
458 M
459 1
460 n
461 n
462 x
463 22
464 test_word_list_example
465 i
466 17
467 5
468 7
469 0
470 45
471 1
472 2
473 7
474 3
475 64
476 49
477 4
478 1
479 47
480 49
481 5
482 2
483 11
484 I
485 4
486 I
487 0
488 I
489 0
490 I
491 0
492 n
493 p
494 6
495 x
496 8
497 pre_type
498 x
499 10
500 IDENT_KIND
501 n
502 s
503 4
504 void
505 x
506 2
507 []
508 x
509 12
510 assert_equal
511 p
512 5
513 I
514 0
515 I
516 1d
517 I
518 0
519 I
520 1e
521 I
522 11
523 x
524 59
525 /Users/murphy/ruby/coderay-0.9/test/functional/word_list.rb
526 p
527 0
528 x
529 17
530 method_visibility
531 x
532 15
533 add_defn_method
534 x
535 14
536 test_word_list
537 M
538 1
539 n
540 n
541 x
542 14
543 test_word_list
544 i
545 73
546 45
547 0
548 1
549 13
550 71
551 2
552 47
553 9
554 23
555 47
556 49
557 3
558 0
559 13
560 7
561 4
562 47
563 49
564 5
565 1
566 15
567 8
568 28
569 7
570 4
571 49
572 2
573 1
574 7
575 6
576 64
577 35
578 1
579 7
580 7
581 49
582 8
583 2
584 19
585 0
586 15
587 5
588 7
589 7
590 20
591 0
592 7
593 6
594 64
595 49
596 9
597 1
598 47
599 49
600 10
601 2
602 15
603 5
604 7
605 4
606 20
607 0
608 7
609 11
610 64
611 49
612 9
613 1
614 47
615 49
616 10
617 2
618 11
619 I
620 5
621 I
622 1
623 I
624 0
625 I
626 0
627 n
628 p
629 12
630 x
631 8
632 WordList
633 n
634 x
635 3
636 new
637 x
638 8
639 allocate
640 x
641 5
642 ident
643 x
644 10
645 initialize
646 s
647 6
648 foobar
649 x
650 8
651 reserved
652 x
653 3
654 add
655 x
656 2
657 []
658 x
659 12
660 assert_equal
661 s
662 6
663 FooBar
664 p
665 9
666 I
667 0
668 I
669 22
670 I
671 0
672 I
673 23
674 I
675 29
676 I
677 24
678 I
679 39
680 I
681 25
682 I
683 49
684 x
685 59
686 /Users/murphy/ruby/coderay-0.9/test/functional/word_list.rb
687 p
688 1
689 x
690 4
691 list
692 x
693 21
694 test_word_list_cached
695 M
696 1
697 n
698 n
699 x
700 21
701 test_word_list_cached
702 i
703 75
704 45
705 0
706 1
707 13
708 71
709 2
710 47
711 9
712 24
713 47
714 49
715 3
716 0
717 13
718 7
719 4
720 2
721 47
722 49
723 5
724 2
725 15
726 8
727 30
728 7
729 4
730 2
731 49
732 2
733 2
734 7
735 6
736 64
737 35
738 1
739 7
740 7
741 49
742 8
743 2
744 19
745 0
746 15
747 5
748 7
749 7
750 20
751 0
752 7
753 6
754 64
755 49
756 9
757 1
758 47
759 49
760 10
761 2
762 15
763 5
764 7
765 4
766 20
767 0
768 7
769 11
770 64
771 49
772 9
773 1
774 47
775 49
776 10
777 2
778 11
779 I
780 5
781 I
782 1
783 I
784 0
785 I
786 0
787 n
788 p
789 12
790 x
791 8
792 WordList
793 n
794 x
795 3
796 new
797 x
798 8
799 allocate
800 x
801 5
802 ident
803 x
804 10
805 initialize
806 s
807 6
808 foobar
809 x
810 8
811 reserved
812 x
813 3
814 add
815 x
816 2
817 []
818 x
819 12
820 assert_equal
821 s
822 6
823 FooBar
824 p
825 9
826 I
827 0
828 I
829 28
830 I
831 0
832 I
833 29
834 I
835 2b
836 I
837 2a
838 I
839 3b
840 I
841 2b
842 I
843 4b
844 x
845 59
846 /Users/murphy/ruby/coderay-0.9/test/functional/word_list.rb
847 p
848 1
849 x
850 4
851 list
852 x
853 28
854 test_case_ignoring_word_list
855 M
856 1
857 n
858 n
859 x
860 28
861 test_case_ignoring_word_list
862 i
863 178
864 45
865 0
866 1
867 13
868 71
869 2
870 47
871 9
872 23
873 47
874 49
875 3
876 0
877 13
878 7
879 4
880 47
881 49
882 5
883 1
884 15
885 8
886 28
887 7
888 4
889 49
890 2
891 1
892 7
893 6
894 64
895 35
896 1
897 7
898 7
899 49
900 8
901 2
902 19
903 0
904 15
905 5
906 7
907 4
908 20
909 0
910 7
911 9
912 64
913 49
914 10
915 1
916 47
917 49
918 11
919 2
920 15
921 5
922 7
923 7
924 20
925 0
926 7
927 6
928 64
929 49
930 10
931 1
932 47
933 49
934 11
935 2
936 15
937 5
938 7
939 7
940 20
941 0
942 7
943 12
944 64
945 49
946 10
947 1
948 47
949 49
950 11
951 2
952 15
953 45
954 0
955 13
956 13
957 71
958 2
959 47
960 9
961 112
962 47
963 49
964 3
965 0
966 13
967 7
968 4
969 47
970 49
971 5
972 1
973 15
974 8
975 117
976 7
977 4
978 49
979 2
980 1
981 7
982 12
983 64
984 35
985 1
986 7
987 7
988 49
989 8
990 2
991 19
992 0
993 15
994 5
995 7
996 4
997 20
998 0
999 7
1000 9
1001 64
1002 49
1003 10
1004 1
1005 47
1006 49
1007 11
1008 2
1009 15
1010 5
1011 7
1012 7
1013 20
1014 0
1015 7
1016 6
1017 64
1018 49
1019 10
1020 1
1021 47
1022 49
1023 11
1024 2
1025 15
1026 5
1027 7
1028 7
1029 20
1030 0
1031 7
1032 12
1033 64
1034 49
1035 10
1036 1
1037 47
1038 49
1039 11
1040 2
1041 11
1042 I
1043 5
1044 I
1045 1
1046 I
1047 0
1048 I
1049 0
1050 n
1051 p
1052 14
1053 x
1054 20
1055 CaseIgnoringWordList
1056 n
1057 x
1058 3
1059 new
1060 x
1061 8
1062 allocate
1063 x
1064 5
1065 ident
1066 x
1067 10
1068 initialize
1069 s
1070 6
1071 foobar
1072 x
1073 8
1074 reserved
1075 x
1076 3
1077 add
1078 s
1079 3
1080 foo
1081 x
1082 2
1083 []
1084 x
1085 12
1086 assert_equal
1087 s
1088 6
1089 FooBar
1090 n
1091 p
1092 19
1093 I
1094 0
1095 I
1096 2e
1097 I
1098 0
1099 I
1100 2f
1101 I
1102 29
1103 I
1104 30
1105 I
1106 39
1107 I
1108 31
1109 I
1110 49
1111 I
1112 32
1113 I
1114 59
1115 I
1116 34
1117 I
1118 82
1119 I
1120 35
1121 I
1122 92
1123 I
1124 36
1125 I
1126 a2
1127 I
1128 37
1129 I
1130 b2
1131 x
1132 59
1133 /Users/murphy/ruby/coderay-0.9/test/functional/word_list.rb
1134 p
1135 1
1136 x
1137 4
1138 list
1139 x
1140 35
1141 test_case_ignoring_word_list_cached
1142 M
1143 1
1144 n
1145 n
1146 x
1147 35
1148 test_case_ignoring_word_list_cached
1149 i
1150 182
1151 45
1152 0
1153 1
1154 13
1155 71
1156 2
1157 47
1158 9
1159 24
1160 47
1161 49
1162 3
1163 0
1164 13
1165 7
1166 4
1167 2
1168 47
1169 49
1170 5
1171 2
1172 15
1173 8
1174 30
1175 7
1176 4
1177 2
1178 49
1179 2
1180 2
1181 7
1182 6
1183 64
1184 35
1185 1
1186 7
1187 7
1188 49
1189 8
1190 2
1191 19
1192 0
1193 15
1194 5
1195 7
1196 4
1197 20
1198 0
1199 7
1200 9
1201 64
1202 49
1203 10
1204 1
1205 47
1206 49
1207 11
1208 2
1209 15
1210 5
1211 7
1212 7
1213 20
1214 0
1215 7
1216 6
1217 64
1218 49
1219 10
1220 1
1221 47
1222 49
1223 11
1224 2
1225 15
1226 5
1227 7
1228 7
1229 20
1230 0
1231 7
1232 12
1233 64
1234 49
1235 10
1236 1
1237 47
1238 49
1239 11
1240 2
1241 15
1242 45
1243 0
1244 13
1245 13
1246 71
1247 2
1248 47
1249 9
1250 115
1251 47
1252 49
1253 3
1254 0
1255 13
1256 7
1257 4
1258 2
1259 47
1260 49
1261 5
1262 2
1263 15
1264 8
1265 121
1266 7
1267 4
1268 2
1269 49
1270 2
1271 2
1272 7
1273 12
1274 64
1275 35
1276 1
1277 7
1278 7
1279 49
1280 8
1281 2
1282 19
1283 0
1284 15
1285 5
1286 7
1287 4
1288 20
1289 0
1290 7
1291 9
1292 64
1293 49
1294 10
1295 1
1296 47
1297 49
1298 11
1299 2
1300 15
1301 5
1302 7
1303 7
1304 20
1305 0
1306 7
1307 6
1308 64
1309 49
1310 10
1311 1
1312 47
1313 49
1314 11
1315 2
1316 15
1317 5
1318 7
1319 7
1320 20
1321 0
1322 7
1323 12
1324 64
1325 49
1326 10
1327 1
1328 47
1329 49
1330 11
1331 2
1332 11
1333 I
1334 5
1335 I
1336 1
1337 I
1338 0
1339 I
1340 0
1341 n
1342 p
1343 14
1344 x
1345 20
1346 CaseIgnoringWordList
1347 n
1348 x
1349 3
1350 new
1351 x
1352 8
1353 allocate
1354 x
1355 5
1356 ident
1357 x
1358 10
1359 initialize
1360 s
1361 6
1362 foobar
1363 x
1364 8
1365 reserved
1366 x
1367 3
1368 add
1369 s
1370 3
1371 foo
1372 x
1373 2
1374 []
1375 x
1376 12
1377 assert_equal
1378 s
1379 6
1380 FooBar
1381 n
1382 p
1383 19
1384 I
1385 0
1386 I
1387 3a
1388 I
1389 0
1390 I
1391 3b
1392 I
1393 2b
1394 I
1395 3c
1396 I
1397 3b
1398 I
1399 3d
1400 I
1401 4b
1402 I
1403 3e
1404 I
1405 5b
1406 I
1407 40
1408 I
1409 86
1410 I
1411 41
1412 I
1413 96
1414 I
1415 42
1416 I
1417 a6
1418 I
1419 43
1420 I
1421 b6
1422 x
1423 59
1424 /Users/murphy/ruby/coderay-0.9/test/functional/word_list.rb
1425 p
1426 1
1427 x
1428 4
1429 list
1430 x
1431 8
1432 test_dup
1433 M
1434 1
1435 n
1436 n
1437 x
1438 8
1439 test_dup
1440 i
1441 110
1442 45
1443 0
1444 1
1445 13
1446 71
1447 2
1448 47
1449 9
1450 23
1451 47
1452 49
1453 3
1454 0
1455 13
1456 7
1457 4
1458 47
1459 49
1460 5
1461 1
1462 15
1463 8
1464 28
1465 7
1466 4
1467 49
1468 2
1469 1
1470 7
1471 6
1472 64
1473 35
1474 1
1475 7
1476 7
1477 49
1478 8
1479 2
1480 19
1481 0
1482 15
1483 5
1484 7
1485 7
1486 20
1487 0
1488 7
1489 6
1490 64
1491 49
1492 9
1493 1
1494 47
1495 49
1496 10
1497 2
1498 15
1499 20
1500 0
1501 49
1502 11
1503 0
1504 19
1505 1
1506 15
1507 20
1508 1
1509 7
1510 6
1511 64
1512 35
1513 1
1514 7
1515 12
1516 49
1517 8
1518 2
1519 15
1520 5
1521 7
1522 12
1523 20
1524 1
1525 7
1526 6
1527 64
1528 49
1529 9
1530 1
1531 47
1532 49
1533 10
1534 2
1535 15
1536 5
1537 7
1538 7
1539 20
1540 0
1541 7
1542 6
1543 64
1544 49
1545 9
1546 1
1547 47
1548 49
1549 10
1550 2
1551 11
1552 I
1553 6
1554 I
1555 2
1556 I
1557 0
1558 I
1559 0
1560 n
1561 p
1562 13
1563 x
1564 8
1565 WordList
1566 n
1567 x
1568 3
1569 new
1570 x
1571 8
1572 allocate
1573 x
1574 5
1575 ident
1576 x
1577 10
1578 initialize
1579 s
1580 6
1581 foobar
1582 x
1583 8
1584 reserved
1585 x
1586 3
1587 add
1588 x
1589 2
1590 []
1591 x
1592 12
1593 assert_equal
1594 x
1595 3
1596 dup
1597 x
1598 7
1599 keyword
1600 p
1601 15
1602 I
1603 0
1604 I
1605 46
1606 I
1607 0
1608 I
1609 47
1610 I
1611 29
1612 I
1613 48
1614 I
1615 39
1616 I
1617 49
1618 I
1619 41
1620 I
1621 4a
1622 I
1623 4e
1624 I
1625 4b
1626 I
1627 5e
1628 I
1629 4c
1630 I
1631 6e
1632 x
1633 59
1634 /Users/murphy/ruby/coderay-0.9/test/functional/word_list.rb
1635 p
1636 2
1637 x
1638 4
1639 list
1640 x
1641 5
1642 list2
1643 p
1644 45
1645 I
1646 2
1647 I
1648 6
1649 I
1650 b
1651 I
1652 9
1653 I
1654 e
1655 I
1656 a
1657 I
1658 23
1659 I
1660 b
1661 I
1662 2c
1663 I
1664 e
1665 I
1666 2f
1667 I
1668 f
1669 I
1670 3e
1671 I
1672 10
1673 I
1674 47
1675 I
1676 13
1677 I
1678 4a
1679 I
1680 14
1681 I
1682 59
1683 I
1684 18
1685 I
1686 78
1687 I
1688 19
1689 I
1690 7d
1691 I
1692 18
1693 I
1694 80
1695 I
1696 1a
1697 I
1698 85
1699 I
1700 18
1701 I
1702 88
1703 I
1704 1b
1705 I
1706 8d
1707 I
1708 18
1709 I
1710 94
1711 I
1712 1d
1713 I
1714 a2
1715 I
1716 22
1717 I
1718 b0
1719 I
1720 28
1721 I
1722 be
1723 I
1724 2e
1725 I
1726 cc
1727 I
1728 3a
1729 I
1730 da
1731 I
1732 46
1733 I
1734 e8
1735 x
1736 59
1737 /Users/murphy/ruby/coderay-0.9/test/functional/word_list.rb
1738 p
1739 0
1740 x
1741 13
1742 attach_method
1743 p
1744 7
1745 I
1746 0
1747 I
1748 1
1749 I
1750 9
1751 I
1752 2
1753 I
1754 12
1755 I
1756 4
1757 I
1758 35
1759 x
1760 59
1761 /Users/murphy/ruby/coderay-0.9/test/functional/word_list.rb
1762 p
1763 0
@@ -1,60 +1,61
1 1 # Be sure to restart your web server when you modify this file.
2 2
3 3 # Uncomment below to force Rails into production mode when
4 4 # you don't control web/app server and can't set it the proper way
5 5 # ENV['RAILS_ENV'] ||= 'production'
6 6
7 7 # Specifies gem version of Rails to use when vendor/rails is not present
8 8 RAILS_GEM_VERSION = '2.3.5' unless defined? RAILS_GEM_VERSION
9 9
10 10 # Bootstrap the Rails environment, frameworks, and default configuration
11 11 require File.join(File.dirname(__FILE__), 'boot')
12 12
13 13 # Load Engine plugin if available
14 14 begin
15 15 require File.join(File.dirname(__FILE__), '../vendor/plugins/engines/boot')
16 16 rescue LoadError
17 17 # Not available
18 18 end
19 19
20 20 Rails::Initializer.run do |config|
21 21 # Settings in config/environments/* take precedence those specified here
22 22
23 23 # Skip frameworks you're not going to use
24 24 # config.frameworks -= [ :action_web_service, :action_mailer ]
25 25
26 26 # Add additional load paths for sweepers
27 27 config.load_paths += %W( #{RAILS_ROOT}/app/sweepers )
28 28
29 29 # Force all environments to use the same logger level
30 30 # (by default production uses :info, the others :debug)
31 31 # config.log_level = :debug
32 32
33 33 # Enable page/fragment caching by setting a file-based store
34 34 # (remember to create the caching directory and make it readable to the application)
35 35 # config.action_controller.cache_store = :file_store, "#{RAILS_ROOT}/tmp/cache"
36 36
37 37 # Activate observers that should always be running
38 38 # config.active_record.observers = :cacher, :garbage_collector
39 39 config.active_record.observers = :message_observer, :issue_observer, :journal_observer, :news_observer, :document_observer, :wiki_content_observer
40 40
41 41 # Make Active Record use UTC-base instead of local time
42 42 # config.active_record.default_timezone = :utc
43 43
44 44 # Use Active Record's schema dumper instead of SQL when creating the test database
45 45 # (enables use of different database adapters for development and test environments)
46 46 # config.active_record.schema_format = :ruby
47 47
48 48 # Deliveries are disabled by default. Do NOT modify this section.
49 49 # Define your email configuration in email.yml instead.
50 50 # It will automatically turn deliveries on
51 51 config.action_mailer.perform_deliveries = false
52 52
53 53 config.gem 'rubytree', :lib => 'tree'
54 config.gem 'coderay', :version => '~>0.9.7'
54 55
55 56 # Load any local configuration that is kept out of source control
56 57 # (e.g. gems, patches).
57 58 if File.exists?(File.join(File.dirname(__FILE__), 'additional_environment.rb'))
58 59 instance_eval File.read(File.join(File.dirname(__FILE__), 'additional_environment.rb'))
59 60 end
60 61 end
1 NO CONTENT: file renamed from vendor/plugins/coderay-0.9.2/LICENSE to vendor/gems/coderay-0.9.7/LICENSE
@@ -1,133 +1,134
1 1 = CodeRay
2 2
3 3 [- Tired of blue'n'gray? Try the original version of this documentation on
4 4 coderay.rubychan.de[http://coderay.rubychan.de/doc/] (use Ctrl+Click to open it in its own frame.) -]
5 5
6 6 == About
7 7 CodeRay is a Ruby library for syntax highlighting.
8 8
9 9 Syntax highlighting means: You put your code in, and you get it back colored;
10 10 Keywords, strings, floats, comments - all in different colors.
11 11 And with line numbers.
12 12
13 13 *Syntax* *Highlighting*...
14 14 * makes code easier to read and maintain
15 15 * lets you detect syntax errors faster
16 16 * helps you to understand the syntax of a language
17 17 * looks nice
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.2
21 Version: 0.9.7
22 22 Author:: murphy (Kornelius Kalnbach)
23 23 Contact:: murphy rubychan de
24 24 Website:: coderay.rubychan.de[http://coderay.rubychan.de]
25 25 License:: GNU LGPL; see LICENSE file in the main directory.
26 26
27 27 == Installation
28 28
29 29 You need RubyGems[http://rubyforge.org/frs/?group_id=126].
30 30
31 31 % gem install coderay
32 32
33 33
34 34 === Dependencies
35 35
36 36 CodeRay needs Ruby 1.8.6 or later. It also runs with Ruby 1.9.1+ and JRuby 1.1+.
37 37
38 38
39 39 == Example Usage
40 40 (Forgive me, but this is not highlighted.)
41 41
42 42 require 'coderay'
43 43
44 44 tokens = CodeRay.scan "puts 'Hello, world!'", :ruby
45 45 page = tokens.html :line_numbers => :inline, :wrap => :page
46 46 puts page
47 47
48 48
49 49 == Documentation
50 50
51 51 See CodeRay.
52 52
53 53 Please report errors in this documentation to <murphy rubychan de>.
54 54
55 55
56 56 == Credits
57 57
58 58 === Special Thanks to
59 59
60 60 * licenser (Heinz N. Gies) for ending my QBasic career, inventing the Coder
61 61 project and the input/output plugin system.
62 62 CodeRay would not exist without him.
63 63 * bovi (Daniel Bovensiepen) for helping me out on various occasions.
64 64
65 65 === Thanks to
66 66
67 67 * Caleb Clausen for writing RubyLexer (see
68 68 http://rubyforge.org/projects/rubylexer) and lots of very interesting mail
69 69 traffic
70 70 * birkenfeld (Georg Brandl) and mitsuhiku (Arnim Ronacher) for PyKleur, now pygments.
71 71 You guys rock!
72 72 * Jamis Buck for writing Syntax (see http://rubyforge.org/projects/syntax)
73 73 I got some useful ideas from it.
74 74 * Doug Kearns and everyone else who worked on ruby.vim - it not only helped me
75 75 coding CodeRay, but also gave me a wonderful target to reach for the Ruby
76 76 scanner.
77 77 * everyone who uses CodeBB on http://www.rubyforen.de and http://www.python-forum.de
78 78 * iGEL, magichisoka, manveru, WoNáDo and everyone I forgot from rubyforen.de
79 79 * Dethix from ruby-mine.de
80 80 * zickzackw
81 81 * Dookie (who is no longer with us...) and Leonidas from http://www.python-forum.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 85 * Stefan Walk for the first version of the JavaScript and PHP scanners.
86 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 93 * Keith Pitt for his SQL scanners
94 94 * Rob Aldred for the terminal encoder
95 95 * Trans for pointing out $DEBUG dependencies
96 96 * Flameeyes for finding that Term::ANSIColor was obsolete
97 * Etienne Massip for reporting a serious bug in JavaScript scanner
97 98 * matz and all Ruby gods and gurus
98 99 * The inventors of: the computer, the internet, the true color display, HTML &
99 100 CSS, VIM, Ruby, pizza, microwaves, guitars, scouting, programming, anime,
100 101 manga, coke and green ice tea.
101 102
102 103 Where would we be without all those people?
103 104
104 105 === Created using
105 106
106 107 * Ruby[http://ruby-lang.org/]
107 108 * Chihiro (my Sony VAIO laptop); Henrietta (my old MacBook);
108 109 Triella, born Rico (my new MacBook); as well as
109 110 Seras and Hikari (my PCs)
110 111 * RDE[http://homepage2.nifty.com/sakazuki/rde_e.html],
111 112 VIM[http://vim.org] and TextMate[http://macromates.com]
112 113 * Subversion[http://subversion.tigris.org/]
113 114 * Redmine[http://redmine.org/]
114 115 * Firefox[http://www.mozilla.org/products/firefox/],
115 116 Firebug[http://getfirebug.com/], Safari[http://www.apple.com/safari/], and
116 117 Thunderbird[http://www.mozilla.org/products/thunderbird/]
117 118 * RubyGems[http://docs.rubygems.org/] and Rake[http://rake.rubyforge.org/]
118 119 * TortoiseSVN[http://tortoisesvn.tigris.org/] using Apache via
119 120 XAMPP[http://www.apachefriends.org/en/xampp.html]
120 121 * RDoc (though I'm quite unsatisfied with it)
121 122 * Microsoft Windows (yes, I confess!) and MacOS X
122 123 * GNUWin32, MinGW and some other tools to make the shell under windows a bit
123 124 less useless
124 125 * Term::ANSIColor[http://term-ansicolor.rubyforge.org/]
125 126 * PLEAC[http://pleac.sourceforge.net/] code examples
126 127
127 128 === Free
128 129
129 130 * As you can see, CodeRay was created under heavy use of *free* software.
130 131 * So CodeRay is also *free*.
131 132 * If you use CodeRay to create software, think about making this software
132 133 *free*, too.
133 134 * Thanks :)
@@ -1,322 +1,322
1 1 # = CodeRay Library
2 2 #
3 3 # CodeRay is a Ruby library for syntax highlighting.
4 4 #
5 5 # I try to make CodeRay easy to use and intuitive, but at the same time fully featured, complete,
6 6 # fast and efficient.
7 7 #
8 8 # See README.
9 9 #
10 10 # It consists mainly of
11 11 # * the main engine: CodeRay (Scanners::Scanner, Tokens/TokenStream, Encoders::Encoder), PluginHost
12 12 # * the scanners in CodeRay::Scanners
13 13 # * the encoders in CodeRay::Encoders
14 14 #
15 15 # Here's a fancy graphic to light up this gray docu:
16 16 #
17 17 # http://cycnus.de/raindark/coderay/scheme.png
18 18 #
19 19 # == Documentation
20 20 #
21 21 # See CodeRay, Encoders, Scanners, Tokens.
22 22 #
23 23 # == Usage
24 24 #
25 25 # Remember you need RubyGems to use CodeRay, unless you have it in your load path. Run Ruby with
26 26 # -rubygems option if required.
27 27 #
28 28 # === Highlight Ruby code in a string as html
29 29 #
30 30 # require 'coderay'
31 31 # print CodeRay.scan('puts "Hello, world!"', :ruby).html
32 32 #
33 33 # # prints something like this:
34 34 # puts <span class="s">&quot;Hello, world!&quot;</span>
35 35 #
36 36 #
37 37 # === Highlight C code from a file in a html div
38 38 #
39 39 # require 'coderay'
40 40 # print CodeRay.scan(File.read('ruby.h'), :c).div
41 41 # print CodeRay.scan_file('ruby.h').html.div
42 42 #
43 43 # You can include this div in your page. The used CSS styles can be printed with
44 44 #
45 45 # % coderay_stylesheet
46 46 #
47 47 # === Highlight without typing too much
48 48 #
49 49 # If you are one of the hasty (or lazy, or extremely curious) people, just run this file:
50 50 #
51 51 # % ruby -rubygems /path/to/coderay/coderay.rb > example.html
52 52 #
53 53 # and look at the file it created in your browser.
54 54 #
55 55 # = CodeRay Module
56 56 #
57 57 # The CodeRay module provides convenience methods for the engine.
58 58 #
59 59 # * The +lang+ and +format+ arguments select Scanner and Encoder to use. These are
60 60 # simply lower-case symbols, like <tt>:python</tt> or <tt>:html</tt>.
61 61 # * All methods take an optional hash as last parameter, +options+, that is send to
62 62 # the Encoder / Scanner.
63 63 # * Input and language are always sorted in this order: +code+, +lang+.
64 64 # (This is in alphabetical order, if you need a mnemonic ;)
65 65 #
66 66 # You should be able to highlight everything you want just using these methods;
67 67 # so there is no need to dive into CodeRay's deep class hierarchy.
68 68 #
69 69 # The examples in the demo directory demonstrate common cases using this interface.
70 70 #
71 71 # = Basic Access Ways
72 72 #
73 73 # Read this to get a general view what CodeRay provides.
74 74 #
75 75 # == Scanning
76 76 #
77 77 # Scanning means analysing an input string, splitting it up into Tokens.
78 78 # Each Token knows about what type it is: string, comment, class name, etc.
79 79 #
80 80 # Each +lang+ (language) has its own Scanner; for example, <tt>:ruby</tt> code is
81 81 # handled by CodeRay::Scanners::Ruby.
82 82 #
83 83 # CodeRay.scan:: Scan a string in a given language into Tokens.
84 84 # This is the most common method to use.
85 85 # CodeRay.scan_file:: Scan a file and guess the language using FileType.
86 86 #
87 87 # The Tokens object you get from these methods can encode itself; see Tokens.
88 88 #
89 89 # == Encoding
90 90 #
91 91 # Encoding means compiling Tokens into an output. This can be colored HTML or
92 92 # LaTeX, a textual statistic or just the number of non-whitespace tokens.
93 93 #
94 94 # Each Encoder provides output in a specific +format+, so you select Encoders via
95 95 # formats like <tt>:html</tt> or <tt>:statistic</tt>.
96 96 #
97 97 # CodeRay.encode:: Scan and encode a string in a given language.
98 98 # CodeRay.encode_tokens:: Encode the given tokens.
99 99 # CodeRay.encode_file:: Scan a file, guess the language using FileType and encode it.
100 100 #
101 101 # == Streaming
102 102 #
103 103 # Streaming saves RAM by running Scanner and Encoder in some sort of
104 104 # pipe mode; see TokenStream.
105 105 #
106 106 # CodeRay.scan_stream:: Scan in stream mode.
107 107 #
108 108 # == All-in-One Encoding
109 109 #
110 110 # CodeRay.encode:: Highlight a string with a given input and output format.
111 111 #
112 112 # == Instanciating
113 113 #
114 114 # You can use an Encoder instance to highlight multiple inputs. This way, the setup
115 115 # for this Encoder must only be done once.
116 116 #
117 117 # CodeRay.encoder:: Create an Encoder instance with format and options.
118 118 # CodeRay.scanner:: Create an Scanner instance for lang, with '' as default code.
119 119 #
120 120 # To make use of CodeRay.scanner, use CodeRay::Scanner::code=.
121 121 #
122 122 # The scanning methods provide more flexibility; we recommend to use these.
123 123 #
124 124 # == Reusing Scanners and Encoders
125 125 #
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 130 $CODERAY_DEBUG ||= false
131 131
132 132 # Version: Major.Minor.Teeny[.Revision]
133 133 # Major: 0 for pre-stable, 1 for stable
134 134 # Minor: feature milestone
135 135 # Teeny: development state, 0 for pre-release
136 136 # Revision: Subversion Revision number (generated on rake gem:make)
137 VERSION = '0.9.2'
137 VERSION = '0.9.7'
138 138
139 139 require 'coderay/tokens'
140 140 require 'coderay/token_classes'
141 141 require 'coderay/scanner'
142 142 require 'coderay/encoder'
143 143 require 'coderay/duo'
144 144 require 'coderay/style'
145 145
146 146
147 147 class << self
148 148
149 149 # Scans the given +code+ (a String) with the Scanner for +lang+.
150 150 #
151 151 # This is a simple way to use CodeRay. Example:
152 152 # require 'coderay'
153 153 # page = CodeRay.scan("puts 'Hello, world!'", :ruby).html
154 154 #
155 155 # See also demo/demo_simple.
156 156 def scan code, lang, options = {}, &block
157 157 scanner = Scanners[lang].new code, options, &block
158 158 scanner.tokenize
159 159 end
160 160
161 161 # Scans +filename+ (a path to a code file) with the Scanner for +lang+.
162 162 #
163 163 # If +lang+ is :auto or omitted, the CodeRay::FileType module is used to
164 164 # determine it. If it cannot find out what type it is, it uses
165 165 # CodeRay::Scanners::Plaintext.
166 166 #
167 167 # Calls CodeRay.scan.
168 168 #
169 169 # Example:
170 170 # require 'coderay'
171 171 # page = CodeRay.scan_file('some_c_code.c').html
172 172 def scan_file filename, lang = :auto, options = {}, &block
173 173 file = IO.read filename
174 174 if lang == :auto
175 175 require 'coderay/helpers/file_type'
176 176 lang = FileType.fetch filename, :plaintext, true
177 177 end
178 178 scan file, lang, options = {}, &block
179 179 end
180 180
181 181 # Scan the +code+ (a string) with the scanner for +lang+.
182 182 #
183 183 # Calls scan.
184 184 #
185 185 # See CodeRay.scan.
186 186 def scan_stream code, lang, options = {}, &block
187 187 options[:stream] = true
188 188 scan code, lang, options, &block
189 189 end
190 190
191 191 # Encode a string in Streaming mode.
192 192 #
193 193 # This starts scanning +code+ with the the Scanner for +lang+
194 194 # while encodes the output with the Encoder for +format+.
195 195 # +options+ will be passed to the Encoder.
196 196 #
197 197 # See CodeRay::Encoder.encode_stream
198 198 def encode_stream code, lang, format, options = {}
199 199 encoder(format, options).encode_stream code, lang, options
200 200 end
201 201
202 202 # Encode a string.
203 203 #
204 204 # This scans +code+ with the the Scanner for +lang+ and then
205 205 # encodes it with the Encoder for +format+.
206 206 # +options+ will be passed to the Encoder.
207 207 #
208 208 # See CodeRay::Encoder.encode
209 209 def encode code, lang, format, options = {}
210 210 encoder(format, options).encode code, lang, options
211 211 end
212 212
213 213 # Highlight a string into a HTML <div>.
214 214 #
215 215 # CSS styles use classes, so you have to include a stylesheet
216 216 # in your output.
217 217 #
218 218 # See encode.
219 219 def highlight code, lang, options = { :css => :class }, format = :div
220 220 encode code, lang, format, options
221 221 end
222 222
223 223 # Encode pre-scanned Tokens.
224 224 # Use this together with CodeRay.scan:
225 225 #
226 226 # require 'coderay'
227 227 #
228 228 # # Highlight a short Ruby code example in a HTML span
229 229 # tokens = CodeRay.scan '1 + 2', :ruby
230 230 # puts CodeRay.encode_tokens(tokens, :span)
231 231 #
232 232 def encode_tokens tokens, format, options = {}
233 233 encoder(format, options).encode_tokens tokens, options
234 234 end
235 235
236 236 # Encodes +filename+ (a path to a code file) with the Scanner for +lang+.
237 237 #
238 238 # See CodeRay.scan_file.
239 239 # Notice that the second argument is the output +format+, not the input language.
240 240 #
241 241 # Example:
242 242 # require 'coderay'
243 243 # page = CodeRay.encode_file 'some_c_code.c', :html
244 244 def encode_file filename, format, options = {}
245 245 tokens = scan_file filename, :auto, get_scanner_options(options)
246 246 encode_tokens tokens, format, options
247 247 end
248 248
249 249 # Highlight a file into a HTML <div>.
250 250 #
251 251 # CSS styles use classes, so you have to include a stylesheet
252 252 # in your output.
253 253 #
254 254 # See encode.
255 255 def highlight_file filename, options = { :css => :class }, format = :div
256 256 encode_file filename, format, options
257 257 end
258 258
259 259 # Finds the Encoder class for +format+ and creates an instance, passing
260 260 # +options+ to it.
261 261 #
262 262 # Example:
263 263 # require 'coderay'
264 264 #
265 265 # stats = CodeRay.encoder(:statistic)
266 266 # stats.encode("puts 17 + 4\n", :ruby)
267 267 #
268 268 # puts '%d out of %d tokens have the kind :integer.' % [
269 269 # stats.type_stats[:integer].count,
270 270 # stats.real_token_count
271 271 # ]
272 272 # #-> 2 out of 4 tokens have the kind :integer.
273 273 def encoder format, options = {}
274 274 Encoders[format].new options
275 275 end
276 276
277 277 # Finds the Scanner class for +lang+ and creates an instance, passing
278 278 # +options+ to it.
279 279 #
280 280 # See Scanner.new.
281 281 def scanner lang, options = {}
282 282 Scanners[lang].new '', options
283 283 end
284 284
285 285 # Extract the options for the scanner from the +options+ hash.
286 286 #
287 287 # Returns an empty Hash if <tt>:scanner_options</tt> is not set.
288 288 #
289 289 # This is used if a method like CodeRay.encode has to provide options
290 290 # for Encoder _and_ scanner.
291 291 def get_scanner_options options
292 292 options.fetch :scanner_options, {}
293 293 end
294 294
295 295 end
296 296
297 297 # This Exception is raised when you try to stream with something that is not
298 298 # capable of streaming.
299 299 class NotStreamableError < Exception
300 300 def initialize obj
301 301 @obj = obj
302 302 end
303 303
304 304 def to_s
305 305 '%s is not Streamable!' % @obj.class
306 306 end
307 307 end
308 308
309 309 # A dummy module that is included by subclasses of CodeRay::Scanner an CodeRay::Encoder
310 310 # to show that they are able to handle streams.
311 311 module Streamable
312 312 end
313 313
314 314 end
315 315
316 316 # Run a test script.
317 317 if $0 == __FILE__
318 318 $stderr.print 'Press key to print demo.'; gets
319 319 # Just use this file as an example of Ruby code.
320 320 code = File.read(__FILE__)[/module CodeRay.*/m]
321 321 print CodeRay.scan(code, :ruby).html
322 322 end
1 NO CONTENT: file renamed from vendor/plugins/coderay-0.9.2/lib/coderay/duo.rb to vendor/gems/coderay-0.9.7/lib/coderay/duo.rb
1 NO CONTENT: file renamed from vendor/plugins/coderay-0.9.2/lib/coderay/encoder.rb to vendor/gems/coderay-0.9.7/lib/coderay/encoder.rb
1 NO CONTENT: file renamed from vendor/plugins/coderay-0.9.2/lib/coderay/encoders/_map.rb to vendor/gems/coderay-0.9.7/lib/coderay/encoders/_map.rb
1 NO CONTENT: file renamed from vendor/plugins/coderay-0.9.2/lib/coderay/encoders/comment_filter.rb to vendor/gems/coderay-0.9.7/lib/coderay/encoders/comment_filter.rb
1 NO CONTENT: file renamed from vendor/plugins/coderay-0.9.2/lib/coderay/encoders/count.rb to vendor/gems/coderay-0.9.7/lib/coderay/encoders/count.rb
1 NO CONTENT: file renamed from vendor/plugins/coderay-0.9.2/lib/coderay/encoders/debug.rb to vendor/gems/coderay-0.9.7/lib/coderay/encoders/debug.rb
1 NO CONTENT: file renamed from vendor/plugins/coderay-0.9.2/lib/coderay/encoders/div.rb to vendor/gems/coderay-0.9.7/lib/coderay/encoders/div.rb
1 NO CONTENT: file renamed from vendor/plugins/coderay-0.9.2/lib/coderay/encoders/filter.rb to vendor/gems/coderay-0.9.7/lib/coderay/encoders/filter.rb
@@ -1,305 +1,309
1 1 require 'set'
2 2
3 3 module CodeRay
4 4 module Encoders
5 5
6 6 # = HTML Encoder
7 7 #
8 8 # This is CodeRay's most important highlighter:
9 9 # It provides save, fast XHTML generation and CSS support.
10 10 #
11 11 # == Usage
12 12 #
13 13 # require 'coderay'
14 14 # puts CodeRay.scan('Some /code/', :ruby).html #-> a HTML page
15 15 # puts CodeRay.scan('Some /code/', :ruby).html(:wrap => :span)
16 16 # #-> <span class="CodeRay"><span class="co">Some</span> /code/</span>
17 17 # puts CodeRay.scan('Some /code/', :ruby).span #-> the same
18 18 #
19 19 # puts CodeRay.scan('Some code', :ruby).html(
20 20 # :wrap => nil,
21 21 # :line_numbers => :inline,
22 22 # :css => :style
23 23 # )
24 24 # #-> <span class="no">1</span> <span style="color:#036; font-weight:bold;">Some</span> code
25 25 #
26 26 # == Options
27 27 #
28 28 # === :tab_width
29 29 # Convert \t characters to +n+ spaces (a number.)
30 30 # Default: 8
31 31 #
32 32 # === :css
33 33 # How to include the styles; can be :class or :style.
34 34 #
35 35 # Default: :class
36 36 #
37 37 # === :wrap
38 38 # Wrap in :page, :div, :span or nil.
39 39 #
40 40 # You can also use Encoders::Div and Encoders::Span.
41 41 #
42 42 # Default: nil
43 43 #
44 44 # === :title
45 45 #
46 46 # The title of the HTML page (works only when :wrap is set to :page.)
47 47 #
48 48 # Default: 'CodeRay output'
49 49 #
50 50 # === :line_numbers
51 51 # Include line numbers in :table, :inline, :list or nil (no line numbers)
52 52 #
53 53 # Default: nil
54 54 #
55 55 # === :line_number_start
56 56 # Where to start with line number counting.
57 57 #
58 58 # Default: 1
59 59 #
60 60 # === :bold_every
61 61 # Make every +n+-th number appear bold.
62 62 #
63 63 # Default: 10
64 64 #
65 65 # === :highlight_lines
66 66 #
67 67 # Highlights certain line numbers.
68 68 # Can be any Enumerable, typically just an Array or Range, of numbers.
69 69 #
70 70 # Bolding is deactivated when :highlight_lines is set. It only makes sense
71 71 # in combination with :line_numbers.
72 72 #
73 73 # Default: nil
74 74 #
75 75 # === :hint
76 76 # Include some information into the output using the title attribute.
77 77 # Can be :info (show token type on mouse-over), :info_long (with full path)
78 78 # or :debug (via inspect).
79 79 #
80 80 # Default: false
81 81 class HTML < Encoder
82 82
83 83 include Streamable
84 84 register_for :html
85 85
86 86 FILE_EXTENSION = 'html'
87 87
88 88 DEFAULT_OPTIONS = {
89 89 :tab_width => 8,
90 90
91 91 :css => :class,
92 92
93 93 :style => :cycnus,
94 94 :wrap => nil,
95 95 :title => 'CodeRay output',
96 96
97 97 :line_numbers => nil,
98 98 :line_number_start => 1,
99 99 :bold_every => 10,
100 100 :highlight_lines => nil,
101 101
102 102 :hint => false,
103 103 }
104 104
105 105 helper :output, :css
106 106
107 107 attr_reader :css
108 108
109 109 protected
110 110
111 111 HTML_ESCAPE = { #:nodoc:
112 112 '&' => '&amp;',
113 113 '"' => '&quot;',
114 114 '>' => '&gt;',
115 115 '<' => '&lt;',
116 116 }
117 117
118 118 # This was to prevent illegal HTML.
119 119 # Strange chars should still be avoided in codes.
120 120 evil_chars = Array(0x00...0x20) - [?\n, ?\t, ?\s]
121 121 evil_chars.each { |i| HTML_ESCAPE[i.chr] = ' ' }
122 122 #ansi_chars = Array(0x7f..0xff)
123 123 #ansi_chars.each { |i| HTML_ESCAPE[i.chr] = '&#%d;' % i }
124 124 # \x9 (\t) and \xA (\n) not included
125 125 #HTML_ESCAPE_PATTERN = /[\t&"><\0-\x8\xB-\x1f\x7f-\xff]/
126 126 HTML_ESCAPE_PATTERN = /[\t"&><\0-\x8\xB-\x1f]/
127 127
128 128 TOKEN_KIND_TO_INFO = Hash.new { |h, kind|
129 129 h[kind] =
130 130 case kind
131 131 when :pre_constant
132 132 'Predefined constant'
133 133 else
134 134 kind.to_s.gsub(/_/, ' ').gsub(/\b\w/) { $&.capitalize }
135 135 end
136 136 }
137 137
138 138 TRANSPARENT_TOKEN_KINDS = [
139 139 :delimiter, :modifier, :content, :escape, :inline_delimiter,
140 140 ].to_set
141 141
142 142 # Generate a hint about the given +classes+ in a +hint+ style.
143 143 #
144 144 # +hint+ may be :info, :info_long or :debug.
145 145 def self.token_path_to_hint hint, classes
146 146 title =
147 147 case hint
148 148 when :info
149 149 TOKEN_KIND_TO_INFO[classes.first]
150 150 when :info_long
151 151 classes.reverse.map { |kind| TOKEN_KIND_TO_INFO[kind] }.join('/')
152 152 when :debug
153 153 classes.inspect
154 154 end
155 155 title ? " title=\"#{title}\"" : ''
156 156 end
157 157
158 158 def setup options
159 159 super
160 160
161 161 @HTML_ESCAPE = HTML_ESCAPE.dup
162 162 @HTML_ESCAPE["\t"] = ' ' * options[:tab_width]
163 163
164 164 @opened = [nil]
165 165 @css = CSS.new options[:style]
166 166
167 167 hint = options[:hint]
168 168 if hint and not [:debug, :info, :info_long].include? hint
169 169 raise ArgumentError, "Unknown value %p for :hint; \
170 170 expected :info, :debug, false, or nil." % hint
171 171 end
172 172
173 173 case options[:css]
174 174
175 175 when :class
176 176 @css_style = Hash.new do |h, k|
177 177 c = CodeRay::Tokens::ClassOfKind[k.first]
178 178 if c == :NO_HIGHLIGHT and not hint
179 179 h[k.dup] = false
180 180 else
181 181 title = if hint
182 182 HTML.token_path_to_hint(hint, k[1..-1] << k.first)
183 183 else
184 184 ''
185 185 end
186 186 if c == :NO_HIGHLIGHT
187 187 h[k.dup] = '<span%s>' % [title]
188 188 else
189 189 h[k.dup] = '<span%s class="%s">' % [title, c]
190 190 end
191 191 end
192 192 end
193 193
194 194 when :style
195 195 @css_style = Hash.new do |h, k|
196 196 if k.is_a? ::Array
197 197 styles = k.dup
198 198 else
199 199 styles = [k]
200 200 end
201 201 type = styles.first
202 202 classes = styles.map { |c| Tokens::ClassOfKind[c] }
203 203 if classes.first == :NO_HIGHLIGHT and not hint
204 204 h[k] = false
205 205 else
206 206 styles.shift if TRANSPARENT_TOKEN_KINDS.include? styles.first
207 207 title = HTML.token_path_to_hint hint, styles
208 208 style = @css[*classes]
209 209 h[k] =
210 210 if style
211 211 '<span%s style="%s">' % [title, style]
212 212 else
213 213 false
214 214 end
215 215 end
216 216 end
217 217
218 218 else
219 219 raise ArgumentError, "Unknown value %p for :css." % options[:css]
220 220
221 221 end
222 222 end
223 223
224 224 def finish options
225 225 not_needed = @opened.shift
226 226 @out << '</span>' * @opened.size
227 227 unless @opened.empty?
228 228 warn '%d tokens still open: %p' % [@opened.size, @opened]
229 229 end
230 230
231 231 @out.extend Output
232 232 @out.css = @css
233 233 @out.numerize! options[:line_numbers], options
234 234 @out.wrap! options[:wrap]
235 235 @out.apply_title! options[:title]
236 236
237 237 super
238 238 end
239 239
240 240 def token text, type = :plain
241 241 case text
242 242
243 243 when nil
244 244 # raise 'Token with nil as text was given: %p' % [[text, type]]
245 245
246 246 when String
247 247 if text =~ /#{HTML_ESCAPE_PATTERN}/o
248 248 text = text.gsub(/#{HTML_ESCAPE_PATTERN}/o) { |m| @HTML_ESCAPE[m] }
249 249 end
250 250 @opened[0] = type
251 251 if text != "\n" && style = @css_style[@opened]
252 252 @out << style << text << '</span>'
253 253 else
254 254 @out << text
255 255 end
256 256
257 257
258 258 # token groups, eg. strings
259 259 when :open
260 260 @opened[0] = type
261 261 @out << (@css_style[@opened] || '<span>')
262 262 @opened << type
263 263 when :close
264 264 if @opened.empty?
265 265 # nothing to close
266 266 else
267 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
271 271 @out << '</span>'
272 272 @opened.pop
273 273 end
274 274
275 275 # whole lines to be highlighted, eg. a deleted line in a diff
276 276 when :begin_line
277 277 @opened[0] = type
278 278 if style = @css_style[@opened]
279 @out << style.sub('<span', '<div')
279 if style['class="']
280 @out << style.sub('class="', 'class="line ')
281 else
282 @out << style.sub('>', ' class="line">')
283 end
280 284 else
281 @out << '<div>'
285 @out << '<span class="line">'
282 286 end
283 287 @opened << type
284 288 when :end_line
285 289 if @opened.empty?
286 290 # nothing to close
287 291 else
288 292 if $CODERAY_DEBUG and (@opened.size == 1 or @opened.last != type)
289 293 raise 'Malformed token stream: Trying to close a line (%p) \
290 294 that is not open. Open are: %p.' % [type, @opened[1..-1]]
291 295 end
292 @out << '</div>'
296 @out << '</span>'
293 297 @opened.pop
294 298 end
295 299
296 300 else
297 301 raise 'unknown token kind: %p' % [text]
298 302
299 303 end
300 304 end
301 305
302 306 end
303 307
304 308 end
305 309 end
1 NO CONTENT: file renamed from vendor/plugins/coderay-0.9.2/lib/coderay/encoders/html/css.rb to vendor/gems/coderay-0.9.7/lib/coderay/encoders/html/css.rb
@@ -1,133 +1,133
1 1 module CodeRay
2 2 module Encoders
3 3
4 4 class HTML
5 5
6 6 module Output
7 7
8 8 def numerize *args
9 9 clone.numerize!(*args)
10 10 end
11 11
12 12 =begin NUMERIZABLE_WRAPPINGS = {
13 13 :table => [:div, :page, nil],
14 14 :inline => :all,
15 15 :list => [:div, :page, nil]
16 16 }
17 17 NUMERIZABLE_WRAPPINGS.default = :all
18 18 =end
19 19 def numerize! mode = :table, options = {}
20 20 return self unless mode
21 21
22 22 options = DEFAULT_OPTIONS.merge options
23 23
24 24 start = options[:line_number_start]
25 25 unless start.is_a? Integer
26 26 raise ArgumentError, "Invalid value %p for :line_number_start; Integer expected." % start
27 27 end
28 28
29 29 #allowed_wrappings = NUMERIZABLE_WRAPPINGS[mode]
30 30 #unless allowed_wrappings == :all or allowed_wrappings.include? options[:wrap]
31 31 # raise ArgumentError, "Can't numerize, :wrap must be in %p, but is %p" % [NUMERIZABLE_WRAPPINGS, options[:wrap]]
32 32 #end
33 33
34 34 bold_every = options[:bold_every]
35 35 highlight_lines = options[:highlight_lines]
36 36 bolding =
37 37 if bold_every == false && highlight_lines == nil
38 38 proc { |line| line.to_s }
39 39 elsif highlight_lines.is_a? Enumerable
40 40 highlight_lines = highlight_lines.to_set
41 41 proc do |line|
42 42 if highlight_lines.include? line
43 43 "<strong class=\"highlighted\">#{line}</strong>" # highlighted line numbers in bold
44 44 else
45 45 line.to_s
46 46 end
47 47 end
48 48 elsif bold_every.is_a? Integer
49 49 raise ArgumentError, ":bolding can't be 0." if bold_every == 0
50 50 proc do |line|
51 51 if line % bold_every == 0
52 52 "<strong>#{line}</strong>" # every bold_every-th number in bold
53 53 else
54 54 line.to_s
55 55 end
56 56 end
57 57 else
58 58 raise ArgumentError, 'Invalid value %p for :bolding; false or Integer expected.' % bold_every
59 59 end
60 60
61 61 case mode
62 62 when :inline
63 63 max_width = (start + line_count).to_s.size
64 64 line_number = start
65 65 gsub!(/^/) do
66 66 line_number_text = bolding.call line_number
67 67 indent = ' ' * (max_width - line_number.to_s.size) # TODO: Optimize (10^x)
68 68 res = "<span class=\"no\">#{indent}#{line_number_text}</span> "
69 69 line_number += 1
70 70 res
71 71 end
72 72
73 73 when :table
74 74 # This is really ugly.
75 75 # Because even monospace fonts seem to have different heights when bold,
76 76 # I make the newline bold, both in the code and the line numbers.
77 77 # FIXME Still not working perfect for Mr. Internet Exploder
78 78 line_numbers = (start ... start + line_count).to_a.map(&bolding).join("\n")
79 79 line_numbers << "\n" # also for Mr. MS Internet Exploder :-/
80 80 line_numbers.gsub!(/\n/) { "<tt>\n</tt>" }
81 81
82 82 line_numbers_table_tpl = TABLE.apply('LINE_NUMBERS', line_numbers)
83 gsub!(/<\/div>\n/) { '</div>' }
84 gsub!(/\n/) { "<tt>\n</tt>" }
83 gsub!("</div>\n", '</div>')
84 gsub!("\n", "<tt>\n</tt>")
85 85 wrap_in! line_numbers_table_tpl
86 86 @wrapped_in = :div
87 87
88 88 when :list
89 89 opened_tags = []
90 90 gsub!(/^.*$\n?/) do |line|
91 91 line.chomp!
92 92
93 93 open = opened_tags.join
94 94 line.scan(%r!<(/)?span[^>]*>?!) do |close,|
95 95 if close
96 96 opened_tags.pop
97 97 else
98 98 opened_tags << $&
99 99 end
100 100 end
101 101 close = '</span>' * opened_tags.size
102 102
103 103 "<li>#{open}#{line}#{close}</li>\n"
104 104 end
105 105 chomp!("\n")
106 106 wrap_in! LIST
107 107 @wrapped_in = :div
108 108
109 109 else
110 110 raise ArgumentError, 'Unknown value %p for mode: expected one of %p' %
111 111 [mode, [:table, :list, :inline]]
112 112 end
113 113
114 114 self
115 115 end
116 116
117 117 def line_count
118 118 line_count = count("\n")
119 119 position_of_last_newline = rindex(?\n)
120 120 if position_of_last_newline
121 121 after_last_newline = self[position_of_last_newline + 1 .. -1]
122 122 ends_with_newline = after_last_newline[/\A(?:<\/span>)*\z/]
123 123 line_count += 1 if not ends_with_newline
124 124 end
125 125 line_count
126 126 end
127 127
128 128 end
129 129
130 130 end
131 131
132 132 end
133 133 end
1 NO CONTENT: file renamed from vendor/plugins/coderay-0.9.2/lib/coderay/encoders/html/output.rb to vendor/gems/coderay-0.9.7/lib/coderay/encoders/html/output.rb
1 NO CONTENT: file renamed from vendor/plugins/coderay-0.9.2/lib/coderay/encoders/json.rb to vendor/gems/coderay-0.9.7/lib/coderay/encoders/json.rb
1 NO CONTENT: file renamed from vendor/plugins/coderay-0.9.2/lib/coderay/encoders/lines_of_code.rb to vendor/gems/coderay-0.9.7/lib/coderay/encoders/lines_of_code.rb
1 NO CONTENT: file renamed from vendor/plugins/coderay-0.9.2/lib/coderay/encoders/null.rb to vendor/gems/coderay-0.9.7/lib/coderay/encoders/null.rb
1 NO CONTENT: file renamed from vendor/plugins/coderay-0.9.2/lib/coderay/encoders/page.rb to vendor/gems/coderay-0.9.7/lib/coderay/encoders/page.rb
1 NO CONTENT: file renamed from vendor/plugins/coderay-0.9.2/lib/coderay/encoders/span.rb to vendor/gems/coderay-0.9.7/lib/coderay/encoders/span.rb
1 NO CONTENT: file renamed from vendor/plugins/coderay-0.9.2/lib/coderay/encoders/statistic.rb to vendor/gems/coderay-0.9.7/lib/coderay/encoders/statistic.rb
1 NO CONTENT: file renamed from vendor/plugins/coderay-0.9.2/lib/coderay/encoders/term.rb to vendor/gems/coderay-0.9.7/lib/coderay/encoders/term.rb
1 NO CONTENT: file renamed from vendor/plugins/coderay-0.9.2/lib/coderay/encoders/text.rb to vendor/gems/coderay-0.9.7/lib/coderay/encoders/text.rb
1 NO CONTENT: file renamed from vendor/plugins/coderay-0.9.2/lib/coderay/encoders/token_class_filter.rb to vendor/gems/coderay-0.9.7/lib/coderay/encoders/token_class_filter.rb
1 NO CONTENT: file renamed from vendor/plugins/coderay-0.9.2/lib/coderay/encoders/xml.rb to vendor/gems/coderay-0.9.7/lib/coderay/encoders/xml.rb
1 NO CONTENT: file renamed from vendor/plugins/coderay-0.9.2/lib/coderay/encoders/yaml.rb to vendor/gems/coderay-0.9.7/lib/coderay/encoders/yaml.rb
1 NO CONTENT: file renamed from vendor/plugins/coderay-0.9.2/lib/coderay/for_redcloth.rb to vendor/gems/coderay-0.9.7/lib/coderay/for_redcloth.rb
1 NO CONTENT: file renamed from vendor/plugins/coderay-0.9.2/lib/coderay/helpers/file_type.rb to vendor/gems/coderay-0.9.7/lib/coderay/helpers/file_type.rb
1 NO CONTENT: file renamed from vendor/plugins/coderay-0.9.2/lib/coderay/helpers/gzip_simple.rb to vendor/gems/coderay-0.9.7/lib/coderay/helpers/gzip_simple.rb
1 NO CONTENT: file renamed from vendor/plugins/coderay-0.9.2/lib/coderay/helpers/plugin.rb to vendor/gems/coderay-0.9.7/lib/coderay/helpers/plugin.rb
1 NO CONTENT: file renamed from vendor/plugins/coderay-0.9.2/lib/coderay/helpers/word_list.rb to vendor/gems/coderay-0.9.7/lib/coderay/helpers/word_list.rb
@@ -1,292 +1,298
1 1 module CodeRay
2 2
3 3 require 'coderay/helpers/plugin'
4 4
5 5 # = Scanners
6 6 #
7 7 # This module holds the Scanner class and its subclasses.
8 8 # For example, the Ruby scanner is named CodeRay::Scanners::Ruby
9 9 # can be found in coderay/scanners/ruby.
10 10 #
11 11 # Scanner also provides methods and constants for the register
12 12 # mechanism and the [] method that returns the Scanner class
13 13 # belonging to the given lang.
14 14 #
15 15 # See PluginHost.
16 16 module Scanners
17 17 extend PluginHost
18 18 plugin_path File.dirname(__FILE__), 'scanners'
19 19
20 20 require 'strscan'
21 21
22 22 # = Scanner
23 23 #
24 24 # The base class for all Scanners.
25 25 #
26 26 # It is a subclass of Ruby's great +StringScanner+, which
27 27 # makes it easy to access the scanning methods inside.
28 28 #
29 29 # It is also +Enumerable+, so you can use it like an Array of
30 30 # Tokens:
31 31 #
32 32 # require 'coderay'
33 33 #
34 34 # c_scanner = CodeRay::Scanners[:c].new "if (*p == '{') nest++;"
35 35 #
36 36 # for text, kind in c_scanner
37 37 # puts text if kind == :operator
38 38 # end
39 39 #
40 40 # # prints: (*==)++;
41 41 #
42 42 # OK, this is a very simple example :)
43 43 # You can also use +map+, +any?+, +find+ and even +sort_by+,
44 44 # if you want.
45 45 class Scanner < StringScanner
46 46
47 47 extend Plugin
48 48 plugin_host Scanners
49 49
50 50 # Raised if a Scanner fails while scanning
51 51 ScanError = Class.new(Exception)
52 52
53 53 require 'coderay/helpers/word_list'
54 54
55 55 # The default options for all scanner classes.
56 56 #
57 57 # Define @default_options for subclasses.
58 58 DEFAULT_OPTIONS = { :stream => false }
59 59
60 60 KINDS_NOT_LOC = [:comment, :doctype]
61 61
62 62 class << self
63 63
64 64 # Returns if the Scanner can be used in streaming mode.
65 65 def streamable?
66 66 is_a? Streamable
67 67 end
68 68
69 69 def normify code
70 70 code = code.to_s
71 if code.respond_to? :force_encoding
72 debug, $DEBUG = $DEBUG, false
73 begin
74 code.force_encoding 'utf-8'
75 code[/\z/] # raises an ArgumentError when code contains a non-UTF-8 char
76 rescue ArgumentError
77 code.force_encoding 'binary'
78 ensure
79 $DEBUG = debug
71 if code.respond_to?(:encoding) && (code.encoding.name != 'UTF-8' || !code.valid_encoding?)
72 code = code.dup
73 original_encoding = code.encoding
74 code.force_encoding 'Windows-1252'
75 unless code.valid_encoding?
76 code.force_encoding original_encoding
77 if code.encoding.name == 'UTF-8'
78 code.encode! 'UTF-16BE', :invalid => :replace, :undef => :replace, :replace => '?'
79 end
80 code.encode! 'UTF-8', :invalid => :replace, :undef => :replace, :replace => '?'
80 81 end
81 82 end
82 83 code.to_unix
83 84 end
84 85
85 86 def file_extension extension = nil
86 87 if extension
87 88 @file_extension = extension.to_s
88 89 else
89 90 @file_extension ||= plugin_id.to_s
90 91 end
91 92 end
92 93
93 94 end
94 95
95 96 =begin
96 97 ## Excluded for speed reasons; protected seems to make methods slow.
97 98
98 99 # Save the StringScanner methods from being called.
99 100 # This would not be useful for highlighting.
100 101 strscan_public_methods =
101 102 StringScanner.instance_methods -
102 103 StringScanner.ancestors[1].instance_methods
103 104 protected(*strscan_public_methods)
104 105 =end
105 106
106 107 # Create a new Scanner.
107 108 #
108 109 # * +code+ is the input String and is handled by the superclass
109 110 # StringScanner.
110 111 # * +options+ is a Hash with Symbols as keys.
111 112 # It is merged with the default options of the class (you can
112 113 # overwrite default options here.)
113 114 # * +block+ is the callback for streamed highlighting.
114 115 #
115 116 # If you set :stream to +true+ in the options, the Scanner uses a
116 117 # TokenStream with the +block+ as callback to handle the tokens.
117 118 #
118 119 # Else, a Tokens object is used.
119 120 def initialize code='', options = {}, &block
120 121 raise "I am only the basic Scanner class. I can't scan "\
121 122 "anything. :( Use my subclasses." if self.class == Scanner
122 123
123 124 @options = self.class::DEFAULT_OPTIONS.merge options
124 125
125 126 super Scanner.normify(code)
126 127
127 128 @tokens = options[:tokens]
128 129 if @options[:stream]
129 130 warn "warning in CodeRay::Scanner.new: :stream is set, "\
130 131 "but no block was given" unless block_given?
131 132 raise NotStreamableError, self unless kind_of? Streamable
132 133 @tokens ||= TokenStream.new(&block)
133 134 else
134 135 warn "warning in CodeRay::Scanner.new: Block given, "\
135 136 "but :stream is #{@options[:stream]}" if block_given?
136 137 @tokens ||= Tokens.new
137 138 end
138 139 @tokens.scanner = self
139 140
140 141 setup
141 142 end
142 143
143 144 def reset
144 145 super
145 146 reset_instance
146 147 end
147 148
148 149 def string= code
149 150 code = Scanner.normify(code)
150 super code
151 if defined?(RUBY_DESCRIPTION) && RUBY_DESCRIPTION['rubinius 1.0.1']
152 reset_state
153 @string = code
154 else
155 super code
156 end
151 157 reset_instance
152 158 end
153 159
154 160 # More mnemonic accessor name for the input string.
155 161 alias code string
156 162 alias code= string=
157 163
158 164 # Returns the Plugin ID for this scanner.
159 165 def lang
160 166 self.class.plugin_id
161 167 end
162 168
163 169 # Scans the code and returns all tokens in a Tokens object.
164 170 def tokenize new_string=nil, options = {}
165 171 options = @options.merge(options)
166 172 self.string = new_string if new_string
167 173 @cached_tokens =
168 174 if @options[:stream] # :stream must have been set already
169 175 reset unless new_string
170 176 scan_tokens @tokens, options
171 177 @tokens
172 178 else
173 179 scan_tokens @tokens, options
174 180 end
175 181 end
176 182
177 183 def tokens
178 184 @cached_tokens ||= tokenize
179 185 end
180 186
181 187 # Whether the scanner is in streaming mode.
182 188 def streaming?
183 189 !!@options[:stream]
184 190 end
185 191
186 192 # Traverses the tokens.
187 193 def each &block
188 194 raise ArgumentError,
189 195 'Cannot traverse TokenStream.' if @options[:stream]
190 196 tokens.each(&block)
191 197 end
192 198 include Enumerable
193 199
194 200 # The current line position of the scanner.
195 201 #
196 202 # Beware, this is implemented inefficiently. It should be used
197 203 # for debugging only.
198 204 def line
199 205 string[0..pos].count("\n") + 1
200 206 end
201 207
202 208 def column pos = self.pos
203 209 return 0 if pos <= 0
204 210 string = string()
205 211 if string.respond_to?(:bytesize) && (defined?(@bin_string) || string.bytesize != string.size)
206 212 @bin_string ||= string.dup.force_encoding('binary')
207 213 string = @bin_string
208 214 end
209 215 pos - (string.rindex(?\n, pos) || 0)
210 216 end
211 217
212 218 def marshal_dump
213 219 @options
214 220 end
215 221
216 222 def marshal_load options
217 223 @options = options
218 224 end
219 225
220 226 protected
221 227
222 228 # Can be implemented by subclasses to do some initialization
223 229 # that has to be done once per instance.
224 230 #
225 231 # Use reset for initialization that has to be done once per
226 232 # scan.
227 233 def setup
228 234 end
229 235
230 236 # This is the central method, and commonly the only one a
231 237 # subclass implements.
232 238 #
233 239 # Subclasses must implement this method; it must return +tokens+
234 240 # and must only use Tokens#<< for storing scanned tokens!
235 241 def scan_tokens tokens, options
236 242 raise NotImplementedError,
237 243 "#{self.class}#scan_tokens not implemented."
238 244 end
239 245
240 246 def reset_instance
241 247 @tokens.clear unless @options[:keep_tokens]
242 248 @cached_tokens = nil
243 249 @bin_string = nil if defined? @bin_string
244 250 end
245 251
246 252 # Scanner error with additional status information
247 253 def raise_inspect msg, tokens, state = 'No state given!', ambit = 30
248 254 raise ScanError, <<-EOE % [
249 255
250 256
251 257 ***ERROR in %s: %s (after %d tokens)
252 258
253 259 tokens:
254 260 %s
255 261
256 262 current line: %d column: %d pos: %d
257 263 matched: %p state: %p
258 264 bol? = %p, eos? = %p
259 265
260 266 surrounding code:
261 267 %p ~~ %p
262 268
263 269
264 270 ***ERROR***
265 271
266 272 EOE
267 273 File.basename(caller[0]),
268 274 msg,
269 275 tokens.size,
270 276 tokens.last(10).map { |t| t.inspect }.join("\n"),
271 277 line, column, pos,
272 278 matched, state, bol?, eos?,
273 279 string[pos - ambit, ambit],
274 280 string[pos, ambit],
275 281 ]
276 282 end
277 283
278 284 end
279 285
280 286 end
281 287 end
282 288
283 289 class String
284 290 # I love this hack. It seems to silence all dos/unix/mac newline problems.
285 291 def to_unix
286 292 if index ?\r
287 293 gsub(/\r\n?/, "\n")
288 294 else
289 295 self
290 296 end
291 297 end
292 298 end
1 NO CONTENT: file renamed from vendor/plugins/coderay-0.9.2/lib/coderay/scanners/_map.rb to vendor/gems/coderay-0.9.7/lib/coderay/scanners/_map.rb
1 NO CONTENT: file renamed from vendor/plugins/coderay-0.9.2/lib/coderay/scanners/c.rb to vendor/gems/coderay-0.9.7/lib/coderay/scanners/c.rb
1 NO CONTENT: file renamed from vendor/plugins/coderay-0.9.2/lib/coderay/scanners/cpp.rb to vendor/gems/coderay-0.9.7/lib/coderay/scanners/cpp.rb
@@ -1,210 +1,209
1 1 module CodeRay
2 2 module Scanners
3 3
4 4 class CSS < Scanner
5 5
6 6 register_for :css
7 7
8 8 KINDS_NOT_LOC = [
9 9 :comment,
10 10 :class, :pseudo_class, :type,
11 11 :constant, :directive,
12 12 :key, :value, :operator, :color, :float,
13 13 :error, :important,
14 14 ]
15 15
16 16 module RE
17 NonASCII = /[\x80-\xFF]/
18 17 Hex = /[0-9a-fA-F]/
19 18 Unicode = /\\#{Hex}{1,6}(?:\r\n|\s)?/ # differs from standard because it allows uppercase hex too
20 19 Escape = /#{Unicode}|\\[^\r\n\f0-9a-fA-F]/
21 NMChar = /[-_a-zA-Z0-9]|#{NonASCII}|#{Escape}/
22 NMStart = /[_a-zA-Z]|#{NonASCII}|#{Escape}/
20 NMChar = /[-_a-zA-Z0-9]|#{Escape}/
21 NMStart = /[_a-zA-Z]|#{Escape}/
23 22 NL = /\r\n|\r|\n|\f/
24 23 String1 = /"(?:[^\n\r\f\\"]|\\#{NL}|#{Escape})*"?/ # FIXME: buggy regexp
25 24 String2 = /'(?:[^\n\r\f\\']|\\#{NL}|#{Escape})*'?/ # FIXME: buggy regexp
26 25 String = /#{String1}|#{String2}/
27 26
28 27 HexColor = /#(?:#{Hex}{6}|#{Hex}{3})/
29 28 Color = /#{HexColor}/
30 29
31 30 Num = /-?(?:[0-9]+|[0-9]*\.[0-9]+)/
32 31 Name = /#{NMChar}+/
33 32 Ident = /-?#{NMStart}#{NMChar}*/
34 33 AtKeyword = /@#{Ident}/
35 34 Percentage = /#{Num}%/
36 35
37 36 reldimensions = %w[em ex px]
38 37 absdimensions = %w[in cm mm pt pc]
39 38 Unit = Regexp.union(*(reldimensions + absdimensions))
40 39
41 40 Dimension = /#{Num}#{Unit}/
42 41
43 42 Comment = %r! /\* (?: .*? \*/ | .* ) !mx
44 43 Function = /(?:url|alpha)\((?:[^)\n\r\f]|\\\))*\)?/
45 44
46 45 Id = /##{Name}/
47 46 Class = /\.#{Name}/
48 47 PseudoClass = /:#{Name}/
49 48 AttributeSelector = /\[[^\]]*\]?/
50 49
51 50 end
52 51
53 52 def scan_tokens tokens, options
54 53
55 54 value_expected = nil
56 55 states = [:initial]
57 56
58 57 until eos?
59 58
60 59 kind = nil
61 60 match = nil
62 61
63 62 if scan(/\s+/)
64 63 kind = :space
65 64
66 65 elsif case states.last
67 66 when :initial, :media
68 67 if scan(/(?>#{RE::Ident})(?!\()|\*/ox)
69 68 kind = :type
70 69 elsif scan RE::Class
71 70 kind = :class
72 71 elsif scan RE::Id
73 72 kind = :constant
74 73 elsif scan RE::PseudoClass
75 74 kind = :pseudo_class
76 75 elsif match = scan(RE::AttributeSelector)
77 76 # TODO: Improve highlighting inside of attribute selectors.
78 77 tokens << [:open, :string]
79 78 tokens << [match[0,1], :delimiter]
80 79 tokens << [match[1..-2], :content] if match.size > 2
81 80 tokens << [match[-1,1], :delimiter] if match[-1] == ?]
82 81 tokens << [:close, :string]
83 82 next
84 83 elsif match = scan(/@media/)
85 84 kind = :directive
86 85 states.push :media_before_name
87 86 end
88 87
89 88 when :block
90 89 if scan(/(?>#{RE::Ident})(?!\()/ox)
91 90 if value_expected
92 91 kind = :value
93 92 else
94 93 kind = :key
95 94 end
96 95 end
97 96
98 97 when :media_before_name
99 98 if scan RE::Ident
100 99 kind = :type
101 100 states[-1] = :media_after_name
102 101 end
103 102
104 103 when :media_after_name
105 104 if scan(/\{/)
106 105 kind = :operator
107 106 states[-1] = :media
108 107 end
109 108
110 109 when :comment
111 110 if scan(/(?:[^*\s]|\*(?!\/))+/)
112 111 kind = :comment
113 112 elsif scan(/\*\//)
114 113 kind = :comment
115 114 states.pop
116 115 elsif scan(/\s+/)
117 116 kind = :space
118 117 end
119 118
120 119 else
121 120 raise_inspect 'Unknown state', tokens
122 121
123 122 end
124 123
125 124 elsif scan(/\/\*/)
126 125 kind = :comment
127 126 states.push :comment
128 127
129 128 elsif scan(/\{/)
130 129 value_expected = false
131 130 kind = :operator
132 131 states.push :block
133 132
134 133 elsif scan(/\}/)
135 134 value_expected = false
136 135 if states.last == :block || states.last == :media
137 136 kind = :operator
138 137 states.pop
139 138 else
140 139 kind = :error
141 140 end
142 141
143 142 elsif match = scan(/#{RE::String}/o)
144 143 tokens << [:open, :string]
145 144 tokens << [match[0, 1], :delimiter]
146 145 tokens << [match[1..-2], :content] if match.size > 2
147 146 tokens << [match[-1, 1], :delimiter] if match.size >= 2
148 147 tokens << [:close, :string]
149 148 next
150 149
151 150 elsif match = scan(/#{RE::Function}/o)
152 151 tokens << [:open, :string]
153 152 start = match[/^\w+\(/]
154 153 tokens << [start, :delimiter]
155 154 if match[-1] == ?)
156 155 tokens << [match[start.size..-2], :content]
157 156 tokens << [')', :delimiter]
158 157 else
159 158 tokens << [match[start.size..-1], :content]
160 159 end
161 160 tokens << [:close, :string]
162 161 next
163 162
164 163 elsif scan(/(?: #{RE::Dimension} | #{RE::Percentage} | #{RE::Num} )/ox)
165 164 kind = :float
166 165
167 166 elsif scan(/#{RE::Color}/o)
168 167 kind = :color
169 168
170 169 elsif scan(/! *important/)
171 170 kind = :important
172 171
173 172 elsif scan(/rgb\([^()\n]*\)?/)
174 173 kind = :color
175 174
176 175 elsif scan(/#{RE::AtKeyword}/o)
177 176 kind = :directive
178 177
179 178 elsif match = scan(/ [+>:;,.=()\/] /x)
180 179 if match == ':'
181 180 value_expected = true
182 181 elsif match == ';'
183 182 value_expected = false
184 183 end
185 184 kind = :operator
186 185
187 186 else
188 187 getch
189 188 kind = :error
190 189
191 190 end
192 191
193 192 match ||= matched
194 193 if $CODERAY_DEBUG and not kind
195 194 raise_inspect 'Error token %p in line %d' %
196 195 [[match, kind], line], tokens
197 196 end
198 197 raise_inspect 'Empty token', tokens unless match
199 198
200 199 tokens << [match, kind]
201 200
202 201 end
203 202
204 203 tokens
205 204 end
206 205
207 206 end
208 207
209 208 end
210 209 end
1 NO CONTENT: file renamed from vendor/plugins/coderay-0.9.2/lib/coderay/scanners/debug.rb to vendor/gems/coderay-0.9.7/lib/coderay/scanners/debug.rb
1 NO CONTENT: file renamed from vendor/plugins/coderay-0.9.2/lib/coderay/scanners/delphi.rb to vendor/gems/coderay-0.9.7/lib/coderay/scanners/delphi.rb
@@ -1,105 +1,110
1 1 module CodeRay
2 2 module Scanners
3 3
4 4 class Diff < Scanner
5 5
6 6 register_for :diff
7 7 title 'diff output'
8 8
9 9 def scan_tokens tokens, options
10 10
11 11 line_kind = nil
12 12 state = :initial
13 13
14 14 until eos?
15 15 kind = match = nil
16 16
17 17 if match = scan(/\n/)
18 18 if line_kind
19 19 tokens << [:end_line, line_kind]
20 20 line_kind = nil
21 21 end
22 22 tokens << [match, :space]
23 23 next
24 24 end
25 25
26 26 case state
27 27
28 28 when :initial
29 29 if match = scan(/--- |\+\+\+ |=+|_+/)
30 30 tokens << [:begin_line, line_kind = :head]
31 31 tokens << [match, :head]
32 32 next unless match = scan(/.+/)
33 33 kind = :plain
34 34 elsif match = scan(/Index: |Property changes on: /)
35 35 tokens << [:begin_line, line_kind = :head]
36 36 tokens << [match, :head]
37 37 next unless match = scan(/.+/)
38 38 kind = :plain
39 39 elsif match = scan(/Added: /)
40 40 tokens << [:begin_line, line_kind = :head]
41 41 tokens << [match, :head]
42 42 next unless match = scan(/.+/)
43 43 kind = :plain
44 44 state = :added
45 45 elsif match = scan(/\\ /)
46 46 tokens << [:begin_line, line_kind = :change]
47 47 tokens << [match, :change]
48 48 next unless match = scan(/.+/)
49 49 kind = :plain
50 elsif scan(/(@@)((?>[^@\n]*))(@@)/)
51 tokens << [:begin_line, line_kind = :change]
52 tokens << [self[1], :change]
53 tokens << [self[2], :plain]
54 tokens << [self[3], :change]
50 elsif match = scan(/@@(?>[^@\n]*)@@/)
51 if check(/\n|$/)
52 tokens << [:begin_line, line_kind = :change]
53 else
54 tokens << [:open, :change]
55 end
56 tokens << [match[0,2], :change]
57 tokens << [match[2...-2], :plain]
58 tokens << [match[-2,2], :change]
59 tokens << [:close, :change] unless line_kind
55 60 next unless match = scan(/.+/)
56 61 kind = :plain
57 62 elsif match = scan(/\+/)
58 63 tokens << [:begin_line, line_kind = :insert]
59 64 tokens << [match, :insert]
60 65 next unless match = scan(/.+/)
61 66 kind = :plain
62 67 elsif match = scan(/-/)
63 68 tokens << [:begin_line, line_kind = :delete]
64 69 tokens << [match, :delete]
65 70 next unless match = scan(/.+/)
66 71 kind = :plain
67 72 elsif scan(/ .*/)
68 73 kind = :comment
69 74 elsif scan(/.+/)
70 tokens << [:begin_line, line_kind = :head]
75 tokens << [:begin_line, line_kind = :comment]
71 76 kind = :plain
72 77 else
73 78 raise_inspect 'else case rached'
74 79 end
75 80
76 81 when :added
77 82 if match = scan(/ \+/)
78 83 tokens << [:begin_line, line_kind = :insert]
79 84 tokens << [match, :insert]
80 85 next unless match = scan(/.+/)
81 86 kind = :plain
82 87 else
83 88 state = :initial
84 89 next
85 90 end
86 91 end
87 92
88 93 match ||= matched
89 94 if $CODERAY_DEBUG and not kind
90 95 raise_inspect 'Error token %p in line %d' %
91 96 [[match, kind], line], tokens
92 97 end
93 98 raise_inspect 'Empty token', tokens unless match
94 99
95 100 tokens << [match, kind]
96 101 end
97 102
98 103 tokens << [:end_line, line_kind] if line_kind
99 104 tokens
100 105 end
101 106
102 107 end
103 108
104 109 end
105 110 end
1 NO CONTENT: file renamed from vendor/plugins/coderay-0.9.2/lib/coderay/scanners/groovy.rb to vendor/gems/coderay-0.9.7/lib/coderay/scanners/groovy.rb
@@ -1,182 +1,182
1 1 module CodeRay
2 2 module Scanners
3 3
4 4 # HTML Scanner
5 5 class HTML < Scanner
6 6
7 7 include Streamable
8 8 register_for :html
9 9
10 10 KINDS_NOT_LOC = [
11 11 :comment, :doctype, :preprocessor,
12 12 :tag, :attribute_name, :operator,
13 13 :attribute_value, :delimiter, :content,
14 14 :plain, :entity, :error
15 15 ]
16 16
17 17 ATTR_NAME = /[\w.:-]+/
18 18 ATTR_VALUE_UNQUOTED = ATTR_NAME
19 19 TAG_END = /\/?>/
20 20 HEX = /[0-9a-fA-F]/
21 21 ENTITY = /
22 22 &
23 23 (?:
24 24 \w+
25 25 |
26 26 \#
27 27 (?:
28 28 \d+
29 29 |
30 30 x#{HEX}+
31 31 )
32 32 )
33 33 ;
34 34 /ox
35 35
36 36 PLAIN_STRING_CONTENT = {
37 37 "'" => /[^&'>\n]+/,
38 38 '"' => /[^&">\n]+/,
39 39 }
40 40
41 41 def reset
42 42 super
43 43 @state = :initial
44 44 end
45 45
46 46 private
47 47 def setup
48 48 @state = :initial
49 49 @plain_string_content = nil
50 50 end
51 51
52 52 def scan_tokens tokens, options
53 53
54 54 state = @state
55 55 plain_string_content = @plain_string_content
56 56
57 57 until eos?
58 58
59 59 kind = nil
60 60 match = nil
61 61
62 62 if scan(/\s+/m)
63 63 kind = :space
64 64
65 65 else
66 66
67 67 case state
68 68
69 69 when :initial
70 70 if scan(/<!--.*?-->/m)
71 71 kind = :comment
72 72 elsif scan(/<!DOCTYPE.*?>/m)
73 73 kind = :doctype
74 74 elsif scan(/<\?xml.*?\?>/m)
75 75 kind = :preprocessor
76 76 elsif scan(/<\?.*?\?>|<%.*?%>/m)
77 77 kind = :comment
78 78 elsif scan(/<\/[-\w.:]*>/m)
79 79 kind = :tag
80 80 elsif match = scan(/<[-\w.:]+>?/m)
81 81 kind = :tag
82 82 state = :attribute unless match[-1] == ?>
83 83 elsif scan(/[^<>&]+/)
84 84 kind = :plain
85 85 elsif scan(/#{ENTITY}/ox)
86 86 kind = :entity
87 87 elsif scan(/[<>&]/)
88 88 kind = :error
89 89 else
90 90 raise_inspect '[BUG] else-case reached with state %p' % [state], tokens
91 91 end
92 92
93 93 when :attribute
94 if scan(/#{TAG_END}/)
94 if scan(/#{TAG_END}/o)
95 95 kind = :tag
96 96 state = :initial
97 97 elsif scan(/#{ATTR_NAME}/o)
98 98 kind = :attribute_name
99 99 state = :attribute_equal
100 100 else
101 101 kind = :error
102 102 getch
103 103 end
104 104
105 105 when :attribute_equal
106 106 if scan(/=/)
107 107 kind = :operator
108 108 state = :attribute_value
109 109 elsif scan(/#{ATTR_NAME}/o)
110 110 kind = :attribute_name
111 111 elsif scan(/#{TAG_END}/o)
112 112 kind = :tag
113 113 state = :initial
114 114 elsif scan(/./)
115 115 kind = :error
116 116 state = :attribute
117 117 end
118 118
119 119 when :attribute_value
120 120 if scan(/#{ATTR_VALUE_UNQUOTED}/o)
121 121 kind = :attribute_value
122 122 state = :attribute
123 123 elsif match = scan(/["']/)
124 124 tokens << [:open, :string]
125 125 state = :attribute_value_string
126 126 plain_string_content = PLAIN_STRING_CONTENT[match]
127 127 kind = :delimiter
128 128 elsif scan(/#{TAG_END}/o)
129 129 kind = :tag
130 130 state = :initial
131 131 else
132 132 kind = :error
133 133 getch
134 134 end
135 135
136 136 when :attribute_value_string
137 137 if scan(plain_string_content)
138 138 kind = :content
139 139 elsif scan(/['"]/)
140 140 tokens << [matched, :delimiter]
141 141 tokens << [:close, :string]
142 142 state = :attribute
143 143 next
144 144 elsif scan(/#{ENTITY}/ox)
145 145 kind = :entity
146 146 elsif scan(/&/)
147 147 kind = :content
148 148 elsif scan(/[\n>]/)
149 149 tokens << [:close, :string]
150 150 kind = :error
151 151 state = :initial
152 152 end
153 153
154 154 else
155 155 raise_inspect 'Unknown state: %p' % [state], tokens
156 156
157 157 end
158 158
159 159 end
160 160
161 161 match ||= matched
162 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
166 166 raise_inspect 'Empty token', tokens unless match
167 167
168 168 tokens << [match, kind]
169 169 end
170 170
171 171 if options[:keep_state]
172 172 @state = state
173 173 @plain_string_content = plain_string_content
174 174 end
175 175
176 176 tokens
177 177 end
178 178
179 179 end
180 180
181 181 end
182 182 end
@@ -1,176 +1,176
1 1 module CodeRay
2 2 module Scanners
3 3
4 4 class Java < Scanner
5 5
6 6 include Streamable
7 7 register_for :java
8 8 helper :builtin_types
9 9
10 10 # http://java.sun.com/docs/books/tutorial/java/nutsandbolts/_keywords.html
11 11 KEYWORDS = %w[
12 12 assert break case catch continue default do else
13 13 finally for if instanceof import new package
14 14 return switch throw try typeof while
15 15 debugger export
16 16 ]
17 17 RESERVED = %w[ const goto ]
18 18 CONSTANTS = %w[ false null true ]
19 19 MAGIC_VARIABLES = %w[ this super ]
20 20 TYPES = %w[
21 21 boolean byte char class double enum float int interface long
22 22 short void
23 23 ] << '[]' # because int[] should be highlighted as a type
24 24 DIRECTIVES = %w[
25 25 abstract extends final implements native private protected public
26 26 static strictfp synchronized throws transient volatile
27 27 ]
28 28
29 29 IDENT_KIND = WordList.new(:ident).
30 30 add(KEYWORDS, :keyword).
31 31 add(RESERVED, :reserved).
32 32 add(CONSTANTS, :pre_constant).
33 33 add(MAGIC_VARIABLES, :local_variable).
34 34 add(TYPES, :type).
35 35 add(BuiltinTypes::List, :pre_type).
36 36 add(BuiltinTypes::List.select { |builtin| builtin[/(Error|Exception)$/] }, :exception).
37 37 add(DIRECTIVES, :directive)
38 38
39 39 ESCAPE = / [bfnrtv\n\\'"] | x[a-fA-F0-9]{1,2} | [0-7]{1,3} /x
40 40 UNICODE_ESCAPE = / u[a-fA-F0-9]{4} | U[a-fA-F0-9]{8} /x
41 41 STRING_CONTENT_PATTERN = {
42 42 "'" => /[^\\']+/,
43 43 '"' => /[^\\"]+/,
44 44 '/' => /[^\\\/]+/,
45 45 }
46 46 IDENT = /[a-zA-Z_][A-Za-z_0-9]*/
47 47
48 48 def scan_tokens tokens, options
49 49
50 50 state = :initial
51 51 string_delimiter = nil
52 52 import_clause = class_name_follows = last_token_dot = false
53 53
54 54 until eos?
55 55
56 56 kind = nil
57 57 match = nil
58 58
59 59 case state
60 60
61 61 when :initial
62 62
63 63 if match = scan(/ \s+ | \\\n /x)
64 64 tokens << [match, :space]
65 65 next
66 66
67 67 elsif match = scan(%r! // [^\n\\]* (?: \\. [^\n\\]* )* | /\* (?: .*? \*/ | .* ) !mx)
68 68 tokens << [match, :comment]
69 69 next
70 70
71 71 elsif import_clause && scan(/ #{IDENT} (?: \. #{IDENT} )* /ox)
72 72 kind = :include
73 73
74 74 elsif match = scan(/ #{IDENT} | \[\] /ox)
75 75 kind = IDENT_KIND[match]
76 76 if last_token_dot
77 77 kind = :ident
78 78 elsif class_name_follows
79 79 kind = :class
80 80 class_name_follows = false
81 81 else
82 82 import_clause = true if match == 'import'
83 83 class_name_follows = true if match == 'class' || match == 'interface'
84 84 end
85 85
86 86 elsif scan(/ \.(?!\d) | [,?:()\[\]}] | -- | \+\+ | && | \|\| | \*\*=? | [-+*\/%^~&|<>=!]=? | <<<?=? | >>>?=? /x)
87 87 kind = :operator
88 88
89 89 elsif scan(/;/)
90 90 import_clause = false
91 91 kind = :operator
92 92
93 93 elsif scan(/\{/)
94 94 class_name_follows = false
95 95 kind = :operator
96 96
97 97 elsif check(/[\d.]/)
98 98 if scan(/0[xX][0-9A-Fa-f]+/)
99 99 kind = :hex
100 100 elsif scan(/(?>0[0-7]+)(?![89.eEfF])/)
101 101 kind = :oct
102 102 elsif scan(/\d+[fFdD]|\d*\.\d+(?:[eE][+-]?\d+)?[fFdD]?|\d+[eE][+-]?\d+[fFdD]?/)
103 103 kind = :float
104 104 elsif scan(/\d+[lL]?/)
105 105 kind = :integer
106 106 end
107 107
108 108 elsif match = scan(/["']/)
109 109 tokens << [:open, :string]
110 110 state = :string
111 111 string_delimiter = match
112 112 kind = :delimiter
113 113
114 114 elsif scan(/ @ #{IDENT} /ox)
115 115 kind = :annotation
116 116
117 117 else
118 118 getch
119 119 kind = :error
120 120
121 121 end
122 122
123 123 when :string
124 124 if scan(STRING_CONTENT_PATTERN[string_delimiter])
125 125 kind = :content
126 126 elsif match = scan(/["'\/]/)
127 127 tokens << [match, :delimiter]
128 128 tokens << [:close, state]
129 129 string_delimiter = nil
130 130 state = :initial
131 131 next
132 132 elsif state == :string && (match = scan(/ \\ (?: #{ESCAPE} | #{UNICODE_ESCAPE} ) /mox))
133 133 if string_delimiter == "'" && !(match == "\\\\" || match == "\\'")
134 134 kind = :content
135 135 else
136 136 kind = :char
137 137 end
138 138 elsif scan(/\\./m)
139 139 kind = :content
140 140 elsif scan(/ \\ | $ /x)
141 tokens << [:close, :delimiter]
141 tokens << [:close, state]
142 142 kind = :error
143 143 state = :initial
144 144 else
145 145 raise_inspect "else case \" reached; %p not handled." % peek(1), tokens
146 146 end
147 147
148 148 else
149 149 raise_inspect 'Unknown state', tokens
150 150
151 151 end
152 152
153 153 match ||= matched
154 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
158 158 raise_inspect 'Empty token', tokens unless match
159 159
160 160 last_token_dot = match == '.'
161 161
162 162 tokens << [match, kind]
163 163
164 164 end
165 165
166 166 if state == :string
167 167 tokens << [:close, state]
168 168 end
169 169
170 170 tokens
171 171 end
172 172
173 173 end
174 174
175 175 end
176 176 end
1 NO CONTENT: file renamed from vendor/plugins/coderay-0.9.2/lib/coderay/scanners/java/builtin_types.rb to vendor/gems/coderay-0.9.7/lib/coderay/scanners/java/builtin_types.rb
@@ -1,224 +1,224
1 1 module CodeRay
2 2 module Scanners
3 3
4 4 class JavaScript < Scanner
5 5
6 6 include Streamable
7 7
8 8 register_for :java_script
9 9 file_extension 'js'
10 10
11 11 # The actual JavaScript keywords.
12 12 KEYWORDS = %w[
13 13 break case catch continue default delete do else
14 14 finally for function if in instanceof new
15 15 return switch throw try typeof var void while with
16 16 ]
17 17 PREDEFINED_CONSTANTS = %w[
18 18 false null true undefined
19 19 ]
20 20
21 21 MAGIC_VARIABLES = %w[ this arguments ] # arguments was introduced in JavaScript 1.4
22 22
23 23 KEYWORDS_EXPECTING_VALUE = WordList.new.add %w[
24 24 case delete in instanceof new return throw typeof with
25 25 ]
26 26
27 27 # Reserved for future use.
28 28 RESERVED_WORDS = %w[
29 29 abstract boolean byte char class debugger double enum export extends
30 30 final float goto implements import int interface long native package
31 31 private protected public short static super synchronized throws transient
32 32 volatile
33 33 ]
34 34
35 35 IDENT_KIND = WordList.new(:ident).
36 36 add(RESERVED_WORDS, :reserved).
37 37 add(PREDEFINED_CONSTANTS, :pre_constant).
38 38 add(MAGIC_VARIABLES, :local_variable).
39 39 add(KEYWORDS, :keyword)
40 40
41 41 ESCAPE = / [bfnrtv\n\\'"] | x[a-fA-F0-9]{1,2} | [0-7]{1,3} /x
42 42 UNICODE_ESCAPE = / u[a-fA-F0-9]{4} | U[a-fA-F0-9]{8} /x
43 43 REGEXP_ESCAPE = / [bBdDsSwW] /x
44 44 STRING_CONTENT_PATTERN = {
45 45 "'" => /[^\\']+/,
46 46 '"' => /[^\\"]+/,
47 47 '/' => /[^\\\/]+/,
48 48 }
49 49 KEY_CHECK_PATTERN = {
50 50 "'" => / [^\\']* (?: \\.? [^\\']* )* '? \s* : /x,
51 51 '"' => / [^\\"]* (?: \\.? [^\\"]* )* "? \s* : /x,
52 52 }
53 53
54 54 def scan_tokens tokens, options
55 55
56 56 state = :initial
57 57 string_delimiter = nil
58 58 value_expected = true
59 59 key_expected = false
60 60 function_expected = false
61 61
62 62 until eos?
63 63
64 64 kind = nil
65 65 match = nil
66 66
67 67 case state
68 68
69 69 when :initial
70 70
71 71 if match = scan(/ \s+ | \\\n /x)
72 72 value_expected = true if !value_expected && match.index(?\n)
73 73 tokens << [match, :space]
74 74 next
75 75
76 76 elsif scan(%r! // [^\n\\]* (?: \\. [^\n\\]* )* | /\* (?: .*? \*/ | .* ) !mx)
77 77 value_expected = true
78 78 kind = :comment
79 79
80 80 elsif check(/\.?\d/)
81 81 key_expected = value_expected = false
82 82 if scan(/0[xX][0-9A-Fa-f]+/)
83 83 kind = :hex
84 84 elsif scan(/(?>0[0-7]+)(?![89.eEfF])/)
85 85 kind = :oct
86 86 elsif scan(/\d+[fF]|\d*\.\d+(?:[eE][+-]?\d+)?[fF]?|\d+[eE][+-]?\d+[fF]?/)
87 87 kind = :float
88 88 elsif scan(/\d+/)
89 89 kind = :integer
90 90 end
91 91
92 92 elsif value_expected && match = scan(/<([[:alpha:]]\w*) (?: [^\/>]*\/> | .*?<\/\1>)/xim)
93 93 # FIXME: scan over nested tags
94 94 xml_scanner.tokenize match
95 95 value_expected = false
96 96 next
97 97
98 98 elsif match = scan(/ [-+*=<>?:;,!&^|(\[{~%]+ | \.(?!\d) /x)
99 99 value_expected = true
100 100 last_operator = match[-1]
101 101 key_expected = (last_operator == ?{) || (last_operator == ?,)
102 102 function_expected = false
103 103 kind = :operator
104 104
105 105 elsif scan(/ [)\]}]+ /x)
106 106 function_expected = key_expected = value_expected = false
107 107 kind = :operator
108 108
109 109 elsif match = scan(/ [$a-zA-Z_][A-Za-z_0-9$]* /x)
110 110 kind = IDENT_KIND[match]
111 111 value_expected = (kind == :keyword) && KEYWORDS_EXPECTING_VALUE[match]
112 112 # TODO: labels
113 113 if kind == :ident
114 114 if match.index(?$) # $ allowed inside an identifier
115 115 kind = :predefined
116 116 elsif function_expected
117 117 kind = :function
118 118 elsif check(/\s*[=:]\s*function\b/)
119 119 kind = :function
120 120 elsif key_expected && check(/\s*:/)
121 121 kind = :key
122 122 end
123 123 end
124 124 function_expected = (kind == :keyword) && (match == 'function')
125 125 key_expected = false
126 126
127 127 elsif match = scan(/["']/)
128 128 if key_expected && check(KEY_CHECK_PATTERN[match])
129 129 state = :key
130 130 else
131 131 state = :string
132 132 end
133 133 tokens << [:open, state]
134 134 string_delimiter = match
135 135 kind = :delimiter
136 136
137 137 elsif value_expected && (match = scan(/\/(?=\S)/))
138 138 tokens << [:open, :regexp]
139 139 state = :regexp
140 140 string_delimiter = '/'
141 141 kind = :delimiter
142 142
143 143 elsif scan(/ \/ /x)
144 144 value_expected = true
145 145 key_expected = false
146 146 kind = :operator
147 147
148 148 else
149 149 getch
150 150 kind = :error
151 151
152 152 end
153 153
154 154 when :string, :regexp, :key
155 155 if scan(STRING_CONTENT_PATTERN[string_delimiter])
156 156 kind = :content
157 157 elsif match = scan(/["'\/]/)
158 158 tokens << [match, :delimiter]
159 159 if state == :regexp
160 160 modifiers = scan(/[gim]+/)
161 161 tokens << [modifiers, :modifier] if modifiers && !modifiers.empty?
162 162 end
163 163 tokens << [:close, state]
164 164 string_delimiter = nil
165 165 key_expected = value_expected = false
166 166 state = :initial
167 167 next
168 168 elsif state != :regexp && (match = scan(/ \\ (?: #{ESCAPE} | #{UNICODE_ESCAPE} ) /mox))
169 169 if string_delimiter == "'" && !(match == "\\\\" || match == "\\'")
170 170 kind = :content
171 171 else
172 172 kind = :char
173 173 end
174 174 elsif state == :regexp && scan(/ \\ (?: #{ESCAPE} | #{REGEXP_ESCAPE} | #{UNICODE_ESCAPE} ) /mox)
175 175 kind = :char
176 176 elsif scan(/\\./m)
177 177 kind = :content
178 178 elsif scan(/ \\ | $ /x)
179 179 tokens << [:close, state]
180 180 kind = :error
181 181 key_expected = value_expected = false
182 182 state = :initial
183 183 else
184 184 raise_inspect "else case \" reached; %p not handled." % peek(1), tokens
185 185 end
186 186
187 187 else
188 188 raise_inspect 'Unknown state', tokens
189 189
190 190 end
191 191
192 192 match ||= matched
193 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
197 197 raise_inspect 'Empty token', tokens unless match
198 198
199 199 tokens << [match, kind]
200 200
201 201 end
202 202
203 203 if [:string, :regexp].include? state
204 204 tokens << [:close, state]
205 205 end
206 206
207 207 tokens
208 208 end
209 209
210 210 protected
211 211
212 212 def reset_instance
213 213 super
214 214 @xml_scanner.reset if defined? @xml_scanner
215 215 end
216 216
217 217 def xml_scanner
218 @xml_scanner ||= CodeRay.scanner :xml, :tokens => @tokens, :keep_tokens => true, :keep_state => true
218 @xml_scanner ||= CodeRay.scanner :xml, :tokens => @tokens, :keep_tokens => true, :keep_state => false
219 219 end
220 220
221 221 end
222 222
223 223 end
224 224 end
@@ -1,112 +1,108
1 1 module CodeRay
2 2 module Scanners
3 3
4 4 class JSON < Scanner
5 5
6 6 include Streamable
7 7
8 8 register_for :json
9 9 file_extension 'json'
10 10
11 11 KINDS_NOT_LOC = [
12 12 :float, :char, :content, :delimiter,
13 13 :error, :integer, :operator, :value,
14 14 ]
15 15
16 CONSTANTS = %w( true false null )
17 IDENT_KIND = WordList.new(:key).add(CONSTANTS, :value)
18
19 16 ESCAPE = / [bfnrt\\"\/] /x
20 17 UNICODE_ESCAPE = / u[a-fA-F0-9]{4} /x
21 18
22 19 def scan_tokens tokens, options
23 20
24 21 state = :initial
25 22 stack = []
26 string_delimiter = nil
27 23 key_expected = false
28 24
29 25 until eos?
30 26
31 27 kind = nil
32 28 match = nil
33 29
34 30 case state
35 31
36 32 when :initial
37 33 if match = scan(/ \s+ | \\\n /x)
38 34 tokens << [match, :space]
39 35 next
40 36 elsif match = scan(/ [:,\[{\]}] /x)
41 37 kind = :operator
42 38 case match
43 39 when '{' then stack << :object; key_expected = true
44 40 when '[' then stack << :array
45 41 when ':' then key_expected = false
46 42 when ',' then key_expected = true if stack.last == :object
47 43 when '}', ']' then stack.pop # no error recovery, but works for valid JSON
48 44 end
49 45 elsif match = scan(/ true | false | null /x)
50 kind = IDENT_KIND[match]
46 kind = :value
51 47 elsif match = scan(/-?(?:0|[1-9]\d*)/)
52 48 kind = :integer
53 49 if scan(/\.\d+(?:[eE][-+]?\d+)?|[eE][-+]?\d+/)
54 50 match << matched
55 51 kind = :float
56 52 end
57 53 elsif match = scan(/"/)
58 54 state = key_expected ? :key : :string
59 55 tokens << [:open, state]
60 56 kind = :delimiter
61 57 else
62 58 getch
63 59 kind = :error
64 60 end
65 61
66 62 when :string, :key
67 63 if scan(/[^\\"]+/)
68 64 kind = :content
69 65 elsif scan(/"/)
70 66 tokens << ['"', :delimiter]
71 67 tokens << [:close, state]
72 68 state = :initial
73 69 next
74 70 elsif scan(/ \\ (?: #{ESCAPE} | #{UNICODE_ESCAPE} ) /mox)
75 71 kind = :char
76 72 elsif scan(/\\./m)
77 73 kind = :content
78 74 elsif scan(/ \\ | $ /x)
79 tokens << [:close, :delimiter]
75 tokens << [:close, state]
80 76 kind = :error
81 77 state = :initial
82 78 else
83 79 raise_inspect "else case \" reached; %p not handled." % peek(1), tokens
84 80 end
85 81
86 82 else
87 83 raise_inspect 'Unknown state', tokens
88 84
89 85 end
90 86
91 87 match ||= matched
92 88 if $CODERAY_DEBUG and not kind
93 89 raise_inspect 'Error token %p in line %d' %
94 90 [[match, kind], line], tokens
95 91 end
96 92 raise_inspect 'Empty token', tokens unless match
97 93
98 94 tokens << [match, kind]
99 95
100 96 end
101 97
102 98 if [:string, :key].include? state
103 99 tokens << [:close, state]
104 100 end
105 101
106 102 tokens
107 103 end
108 104
109 105 end
110 106
111 107 end
112 108 end
1 NO CONTENT: file renamed from vendor/plugins/coderay-0.9.2/lib/coderay/scanners/nitro_xhtml.rb to vendor/gems/coderay-0.9.7/lib/coderay/scanners/nitro_xhtml.rb
@@ -1,527 +1,533
1 1 module CodeRay
2 2 module Scanners
3 3
4 4 load :html
5 5
6 6 # Original by Stefan Walk.
7 7 class PHP < Scanner
8 8
9 9 register_for :php
10 10 file_extension 'php'
11 11
12 12 KINDS_NOT_LOC = HTML::KINDS_NOT_LOC
13 13
14 14 def setup
15 15 @html_scanner = CodeRay.scanner :html, :tokens => @tokens, :keep_tokens => true, :keep_state => true
16 16 end
17 17
18 18 def reset_instance
19 19 super
20 20 @html_scanner.reset
21 21 end
22 22
23 23 module Words
24 24
25 25 # according to http://www.php.net/manual/en/reserved.keywords.php
26 26 KEYWORDS = %w[
27 27 abstract and array as break case catch class clone const continue declare default do else elseif
28 28 enddeclare endfor endforeach endif endswitch endwhile extends final for foreach function global
29 29 goto if implements interface instanceof namespace new or private protected public static switch
30 30 throw try use var while xor
31 31 cfunction old_function
32 32 ]
33 33
34 34 TYPES = %w[ int integer float double bool boolean string array object resource ]
35 35
36 36 LANGUAGE_CONSTRUCTS = %w[
37 37 die echo empty exit eval include include_once isset list
38 38 require require_once return print unset
39 39 ]
40 40
41 41 CLASSES = %w[ Directory stdClass __PHP_Incomplete_Class exception php_user_filter Closure ]
42 42
43 43 # according to http://php.net/quickref.php on 2009-04-21;
44 44 # all functions with _ excluded (module functions) and selected additional functions
45 45 BUILTIN_FUNCTIONS = %w[
46 46 abs acos acosh addcslashes addslashes aggregate array arsort ascii2ebcdic asin asinh asort assert atan atan2
47 47 atanh basename bcadd bccomp bcdiv bcmod bcmul bcpow bcpowmod bcscale bcsqrt bcsub bin2hex bindec
48 48 bindtextdomain bzclose bzcompress bzdecompress bzerrno bzerror bzerrstr bzflush bzopen bzread bzwrite
49 49 calculhmac ceil chdir checkdate checkdnsrr chgrp chmod chop chown chr chroot clearstatcache closedir closelog
50 50 compact constant copy cos cosh count crc32 crypt current date dcgettext dcngettext deaggregate decbin dechex
51 51 decoct define defined deg2rad delete dgettext die dirname diskfreespace dl dngettext doubleval each
52 52 ebcdic2ascii echo empty end ereg eregi escapeshellarg escapeshellcmd eval exec exit exp explode expm1 extract
53 53 fclose feof fflush fgetc fgetcsv fgets fgetss file fileatime filectime filegroup fileinode filemtime fileowner
54 54 fileperms filepro filesize filetype floatval flock floor flush fmod fnmatch fopen fpassthru fprintf fputcsv
55 55 fputs fread frenchtojd fscanf fseek fsockopen fstat ftell ftok ftruncate fwrite getallheaders getcwd getdate
56 56 getenv gethostbyaddr gethostbyname gethostbynamel getimagesize getlastmod getmxrr getmygid getmyinode getmypid
57 57 getmyuid getopt getprotobyname getprotobynumber getrandmax getrusage getservbyname getservbyport gettext
58 58 gettimeofday gettype glob gmdate gmmktime gmstrftime gregoriantojd gzclose gzcompress gzdecode gzdeflate
59 59 gzencode gzeof gzfile gzgetc gzgets gzgetss gzinflate gzopen gzpassthru gzputs gzread gzrewind gzseek gztell
60 60 gzuncompress gzwrite hash header hebrev hebrevc hexdec htmlentities htmlspecialchars hypot iconv idate
61 61 implode include intval ip2long iptcembed iptcparse isset
62 62 jddayofweek jdmonthname jdtofrench jdtogregorian jdtojewish jdtojulian jdtounix jewishtojd join jpeg2wbmp
63 63 juliantojd key krsort ksort lcfirst lchgrp lchown levenshtein link linkinfo list localeconv localtime log
64 64 log10 log1p long2ip lstat ltrim mail main max md5 metaphone mhash microtime min mkdir mktime msql natcasesort
65 65 natsort next ngettext nl2br nthmac octdec opendir openlog
66 66 ord overload pack passthru pathinfo pclose pfsockopen phpcredits phpinfo phpversion pi png2wbmp popen pos pow
67 67 prev print printf putenv quotemeta rad2deg rand range rawurldecode rawurlencode readdir readfile readgzfile
68 68 readline readlink realpath recode rename require reset rewind rewinddir rmdir round rsort rtrim scandir
69 69 serialize setcookie setlocale setrawcookie settype sha1 shuffle signeurlpaiement sin sinh sizeof sleep snmpget
70 70 snmpgetnext snmprealwalk snmpset snmpwalk snmpwalkoid sort soundex split spliti sprintf sqrt srand sscanf stat
71 71 strcasecmp strchr strcmp strcoll strcspn strftime stripcslashes stripos stripslashes stristr strlen
72 72 strnatcasecmp strnatcmp strncasecmp strncmp strpbrk strpos strptime strrchr strrev strripos strrpos strspn
73 73 strstr strtok strtolower strtotime strtoupper strtr strval substr symlink syslog system tan tanh tempnam
74 74 textdomain time tmpfile touch trim uasort ucfirst ucwords uksort umask uniqid unixtojd unlink unpack
75 75 unserialize unset urldecode urlencode usleep usort vfprintf virtual vprintf vsprintf wordwrap
76 76 array_change_key_case array_chunk array_combine array_count_values array_diff array_diff_assoc
77 77 array_diff_key array_diff_uassoc array_diff_ukey array_fill array_fill_keys array_filter array_flip
78 78 array_intersect array_intersect_assoc array_intersect_key array_intersect_uassoc array_intersect_ukey
79 79 array_key_exists array_keys array_map array_merge array_merge_recursive array_multisort array_pad
80 80 array_pop array_product array_push array_rand array_reduce array_reverse array_search array_shift
81 81 array_slice array_splice array_sum array_udiff array_udiff_assoc array_udiff_uassoc array_uintersect
82 82 array_uintersect_assoc array_uintersect_uassoc array_unique array_unshift array_values array_walk
83 83 array_walk_recursive
84 84 assert_options base_convert base64_decode base64_encode
85 85 chunk_split class_exists class_implements class_parents
86 86 count_chars debug_backtrace debug_print_backtrace debug_zval_dump
87 87 error_get_last error_log error_reporting extension_loaded
88 88 file_exists file_get_contents file_put_contents load_file
89 89 func_get_arg func_get_args func_num_args function_exists
90 90 get_browser get_called_class get_cfg_var get_class get_class_methods get_class_vars
91 91 get_current_user get_declared_classes get_declared_interfaces get_defined_constants
92 92 get_defined_functions get_defined_vars get_extension_funcs get_headers get_html_translation_table
93 93 get_include_path get_included_files get_loaded_extensions get_magic_quotes_gpc get_magic_quotes_runtime
94 94 get_meta_tags get_object_vars get_parent_class get_required_filesget_resource_type
95 95 gc_collect_cycles gc_disable gc_enable gc_enabled
96 96 halt_compiler headers_list headers_sent highlight_file highlight_string
97 97 html_entity_decode htmlspecialchars_decode
98 98 in_array include_once inclued_get_data
99 99 is_a is_array is_binary is_bool is_buffer is_callable is_dir is_double is_executable is_file is_finite
100 100 is_float is_infinite is_int is_integer is_link is_long is_nan is_null is_numeric is_object is_readable
101 101 is_real is_resource is_scalar is_soap_fault is_string is_subclass_of is_unicode is_uploaded_file
102 102 is_writable is_writeable
103 103 locale_get_default locale_set_default
104 104 number_format override_function parse_str parse_url
105 105 php_check_syntax php_ini_loaded_file php_ini_scanned_files php_logo_guid php_sapi_name
106 106 php_strip_whitespace php_uname
107 107 preg_filter preg_grep preg_last_error preg_match preg_match_all preg_quote preg_replace
108 108 preg_replace_callback preg_split print_r
109 109 require_once register_shutdown_function register_tick_function
110 110 set_error_handler set_exception_handler set_file_buffer set_include_path
111 111 set_magic_quotes_runtime set_time_limit shell_exec
112 112 str_getcsv str_ireplace str_pad str_repeat str_replace str_rot13 str_shuffle str_split str_word_count
113 113 strip_tags substr_compare substr_count substr_replace
114 114 time_nanosleep time_sleep_until
115 115 token_get_all token_name trigger_error
116 116 unregister_tick_function use_soap_error_handler user_error
117 117 utf8_decode utf8_encode var_dump var_export
118 118 version_compare
119 119 zend_logo_guid zend_thread_id zend_version
120 120 create_function call_user_func_array
121 121 posix_access posix_ctermid posix_get_last_error posix_getcwd posix_getegid
122 122 posix_geteuid posix_getgid posix_getgrgid posix_getgrnam posix_getgroups
123 123 posix_getlogin posix_getpgid posix_getpgrp posix_getpid posix_getppid
124 124 posix_getpwnam posix_getpwuid posix_getrlimit posix_getsid posix_getuid
125 125 posix_initgroups posix_isatty posix_kill posix_mkfifo posix_mknod
126 126 posix_setegid posix_seteuid posix_setgid posix_setpgid posix_setsid
127 127 posix_setuid posix_strerror posix_times posix_ttyname posix_uname
128 128 pcntl_alarm pcntl_exec pcntl_fork pcntl_getpriority pcntl_setpriority
129 129 pcntl_signal pcntl_signal_dispatch pcntl_sigprocmask pcntl_sigtimedwait
130 130 pcntl_sigwaitinfo pcntl_wait pcntl_waitpid pcntl_wexitstatus pcntl_wifexited
131 131 pcntl_wifsignaled pcntl_wifstopped pcntl_wstopsig pcntl_wtermsig
132 132 ]
133 133 # TODO: more built-in PHP functions?
134 134
135 135 EXCEPTIONS = %w[
136 136 E_ERROR E_WARNING E_PARSE E_NOTICE E_CORE_ERROR E_CORE_WARNING E_COMPILE_ERROR E_COMPILE_WARNING
137 137 E_USER_ERROR E_USER_WARNING E_USER_NOTICE E_DEPRECATED E_USER_DEPRECATED E_ALL E_STRICT
138 138 ]
139 139
140 140 CONSTANTS = %w[
141 141 null true false self parent
142 142 __LINE__ __DIR__ __FILE__ __LINE__
143 143 __CLASS__ __NAMESPACE__ __METHOD__ __FUNCTION__
144 144 PHP_VERSION PHP_MAJOR_VERSION PHP_MINOR_VERSION PHP_RELEASE_VERSION PHP_VERSION_ID PHP_EXTRA_VERSION PHP_ZTS
145 145 PHP_DEBUG PHP_MAXPATHLEN PHP_OS PHP_SAPI PHP_EOL PHP_INT_MAX PHP_INT_SIZE DEFAULT_INCLUDE_PATH
146 146 PEAR_INSTALL_DIR PEAR_EXTENSION_DIR PHP_EXTENSION_DIR PHP_PREFIX PHP_BINDIR PHP_LIBDIR PHP_DATADIR
147 147 PHP_SYSCONFDIR PHP_LOCALSTATEDIR PHP_CONFIG_FILE_PATH PHP_CONFIG_FILE_SCAN_DIR PHP_SHLIB_SUFFIX
148 148 PHP_OUTPUT_HANDLER_START PHP_OUTPUT_HANDLER_CONT PHP_OUTPUT_HANDLER_END
149 149 __COMPILER_HALT_OFFSET__
150 150 EXTR_OVERWRITE EXTR_SKIP EXTR_PREFIX_SAME EXTR_PREFIX_ALL EXTR_PREFIX_INVALID EXTR_PREFIX_IF_EXISTS
151 151 EXTR_IF_EXISTS SORT_ASC SORT_DESC SORT_REGULAR SORT_NUMERIC SORT_STRING CASE_LOWER CASE_UPPER COUNT_NORMAL
152 152 COUNT_RECURSIVE ASSERT_ACTIVE ASSERT_CALLBACK ASSERT_BAIL ASSERT_WARNING ASSERT_QUIET_EVAL CONNECTION_ABORTED
153 153 CONNECTION_NORMAL CONNECTION_TIMEOUT INI_USER INI_PERDIR INI_SYSTEM INI_ALL M_E M_LOG2E M_LOG10E M_LN2 M_LN10
154 154 M_PI M_PI_2 M_PI_4 M_1_PI M_2_PI M_2_SQRTPI M_SQRT2 M_SQRT1_2 CRYPT_SALT_LENGTH CRYPT_STD_DES CRYPT_EXT_DES
155 155 CRYPT_MD5 CRYPT_BLOWFISH DIRECTORY_SEPARATOR SEEK_SET SEEK_CUR SEEK_END LOCK_SH LOCK_EX LOCK_UN LOCK_NB
156 156 HTML_SPECIALCHARS HTML_ENTITIES ENT_COMPAT ENT_QUOTES ENT_NOQUOTES INFO_GENERAL INFO_CREDITS
157 157 INFO_CONFIGURATION INFO_MODULES INFO_ENVIRONMENT INFO_VARIABLES INFO_LICENSE INFO_ALL CREDITS_GROUP
158 158 CREDITS_GENERAL CREDITS_SAPI CREDITS_MODULES CREDITS_DOCS CREDITS_FULLPAGE CREDITS_QA CREDITS_ALL STR_PAD_LEFT
159 159 STR_PAD_RIGHT STR_PAD_BOTH PATHINFO_DIRNAME PATHINFO_BASENAME PATHINFO_EXTENSION PATH_SEPARATOR CHAR_MAX
160 160 LC_CTYPE LC_NUMERIC LC_TIME LC_COLLATE LC_MONETARY LC_ALL LC_MESSAGES ABDAY_1 ABDAY_2 ABDAY_3 ABDAY_4 ABDAY_5
161 161 ABDAY_6 ABDAY_7 DAY_1 DAY_2 DAY_3 DAY_4 DAY_5 DAY_6 DAY_7 ABMON_1 ABMON_2 ABMON_3 ABMON_4 ABMON_5 ABMON_6
162 162 ABMON_7 ABMON_8 ABMON_9 ABMON_10 ABMON_11 ABMON_12 MON_1 MON_2 MON_3 MON_4 MON_5 MON_6 MON_7 MON_8 MON_9
163 163 MON_10 MON_11 MON_12 AM_STR PM_STR D_T_FMT D_FMT T_FMT T_FMT_AMPM ERA ERA_YEAR ERA_D_T_FMT ERA_D_FMT ERA_T_FMT
164 164 ALT_DIGITS INT_CURR_SYMBOL CURRENCY_SYMBOL CRNCYSTR MON_DECIMAL_POINT MON_THOUSANDS_SEP MON_GROUPING
165 165 POSITIVE_SIGN NEGATIVE_SIGN INT_FRAC_DIGITS FRAC_DIGITS P_CS_PRECEDES P_SEP_BY_SPACE N_CS_PRECEDES
166 166 N_SEP_BY_SPACE P_SIGN_POSN N_SIGN_POSN DECIMAL_POINT RADIXCHAR THOUSANDS_SEP THOUSEP GROUPING YESEXPR NOEXPR
167 167 YESSTR NOSTR CODESET LOG_EMERG LOG_ALERT LOG_CRIT LOG_ERR LOG_WARNING LOG_NOTICE LOG_INFO LOG_DEBUG LOG_KERN
168 168 LOG_USER LOG_MAIL LOG_DAEMON LOG_AUTH LOG_SYSLOG LOG_LPR LOG_NEWS LOG_UUCP LOG_CRON LOG_AUTHPRIV LOG_LOCAL0
169 169 LOG_LOCAL1 LOG_LOCAL2 LOG_LOCAL3 LOG_LOCAL4 LOG_LOCAL5 LOG_LOCAL6 LOG_LOCAL7 LOG_PID LOG_CONS LOG_ODELAY
170 170 LOG_NDELAY LOG_NOWAIT LOG_PERROR
171 171 ]
172 172
173 173 PREDEFINED = %w[
174 174 $GLOBALS $_SERVER $_GET $_POST $_FILES $_REQUEST $_SESSION $_ENV
175 175 $_COOKIE $php_errormsg $HTTP_RAW_POST_DATA $http_response_header
176 176 $argc $argv
177 177 ]
178 178
179 179 IDENT_KIND = CaseIgnoringWordList.new(:ident).
180 180 add(KEYWORDS, :reserved).
181 181 add(TYPES, :pre_type).
182 182 add(LANGUAGE_CONSTRUCTS, :reserved).
183 183 add(BUILTIN_FUNCTIONS, :predefined).
184 184 add(CLASSES, :pre_constant).
185 185 add(EXCEPTIONS, :exception).
186 186 add(CONSTANTS, :pre_constant)
187 187
188 188 VARIABLE_KIND = WordList.new(:local_variable).
189 189 add(PREDEFINED, :predefined)
190 190 end
191 191
192 192 module RE
193 193
194 194 PHP_START = /
195 195 <script\s+[^>]*?language\s*=\s*"php"[^>]*?> |
196 196 <script\s+[^>]*?language\s*=\s*'php'[^>]*?> |
197 197 <\?php\d? |
198 198 <\?(?!xml)
199 199 /xi
200 200
201 201 PHP_END = %r!
202 202 </script> |
203 203 \?>
204 204 !xi
205 205
206 206 HTML_INDICATOR = /<!DOCTYPE html|<(?:html|body|div|p)[> ]/i
207 207
208 208 IDENTIFIER = /[a-z_\x7f-\xFF][a-z0-9_\x7f-\xFF]*/i
209 209 VARIABLE = /\$#{IDENTIFIER}/
210 210
211 211 OPERATOR = /
212 212 \.(?!\d)=? | # dot that is not decimal point, string concatenation
213 213 && | \|\| | # logic
214 214 :: | -> | => | # scope, member, dictionary
215 215 \\(?!\n) | # namespace
216 216 \+\+ | -- | # increment, decrement
217 217 [,;?:()\[\]{}] | # simple delimiters
218 218 [-+*\/%&|^]=? | # ordinary math, binary logic, assignment shortcuts
219 219 [~$] | # whatever
220 220 =& | # reference assignment
221 221 [=!]=?=? | <> | # comparison and assignment
222 222 <<=? | >>=? | [<>]=? # comparison and shift
223 223 /x
224 224
225 225 end
226 226
227 227 def scan_tokens tokens, options
228 if string.respond_to?(:encoding)
229 unless string.encoding == Encoding::ASCII_8BIT
230 self.string = string.encode Encoding::ASCII_8BIT,
231 :invalid => :replace, :undef => :replace, :replace => '?'
232 end
233 end
228 234
229 235 if check(RE::PHP_START) || # starts with <?
230 236 (match?(/\s*<\S/) && exist?(RE::PHP_START)) || # starts with tag and contains <?
231 237 exist?(RE::HTML_INDICATOR) ||
232 238 check(/.{1,100}#{RE::PHP_START}/om) # PHP start after max 100 chars
233 239 # is HTML with embedded PHP, so start with HTML
234 240 states = [:initial]
235 241 else
236 242 # is just PHP, so start with PHP surrounded by HTML
237 243 states = [:initial, :php]
238 244 end
239 245
240 246 label_expected = true
241 247 case_expected = false
242 248
243 249 heredoc_delimiter = nil
244 250 delimiter = nil
245 251 modifier = nil
246 252
247 253 until eos?
248 254
249 255 match = nil
250 256 kind = nil
251 257
252 258 case states.last
253 259
254 260 when :initial # HTML
255 261 if scan RE::PHP_START
256 262 kind = :inline_delimiter
257 263 label_expected = true
258 264 states << :php
259 265 else
260 266 match = scan_until(/(?=#{RE::PHP_START})/o) || scan_until(/\z/)
261 267 @html_scanner.tokenize match unless match.empty?
262 268 next
263 269 end
264 270
265 271 when :php
266 272 if match = scan(/\s+/)
267 273 tokens << [match, :space]
268 274 next
269 275
270 276 elsif scan(%r! (?m: \/\* (?: .*? \*\/ | .* ) ) | (?://|\#) .*? (?=#{RE::PHP_END}|$) !xo)
271 277 kind = :comment
272 278
273 279 elsif match = scan(RE::IDENTIFIER)
274 280 kind = Words::IDENT_KIND[match]
275 281 if kind == :ident && label_expected && check(/:(?!:)/)
276 282 kind = :label
277 283 label_expected = true
278 284 else
279 285 label_expected = false
280 286 if kind == :ident && match =~ /^[A-Z]/
281 287 kind = :constant
282 288 elsif kind == :reserved
283 289 case match
284 290 when 'class'
285 291 states << :class_expected
286 292 when 'function'
287 293 states << :function_expected
288 294 when 'case', 'default'
289 295 case_expected = true
290 296 end
291 297 elsif match == 'b' && check(/['"]/) # binary string literal
292 298 modifier = match
293 299 next
294 300 end
295 301 end
296 302
297 303 elsif scan(/(?:\d+\.\d*|\d*\.\d+)(?:e[-+]?\d+)?|\d+e[-+]?\d+/i)
298 304 label_expected = false
299 305 kind = :float
300 306
301 307 elsif scan(/0x[0-9a-fA-F]+/)
302 308 label_expected = false
303 309 kind = :hex
304 310
305 311 elsif scan(/\d+/)
306 312 label_expected = false
307 313 kind = :integer
308 314
309 315 elsif scan(/'/)
310 316 tokens << [:open, :string]
311 317 if modifier
312 318 tokens << [modifier, :modifier]
313 319 modifier = nil
314 320 end
315 321 kind = :delimiter
316 322 states.push :sqstring
317 323
318 324 elsif match = scan(/["`]/)
319 325 tokens << [:open, :string]
320 326 if modifier
321 327 tokens << [modifier, :modifier]
322 328 modifier = nil
323 329 end
324 330 delimiter = match
325 331 kind = :delimiter
326 332 states.push :dqstring
327 333
328 334 elsif match = scan(RE::VARIABLE)
329 335 label_expected = false
330 336 kind = Words::VARIABLE_KIND[match]
331 337
332 338 elsif scan(/\{/)
333 339 kind = :operator
334 340 label_expected = true
335 341 states.push :php
336 342
337 343 elsif scan(/\}/)
338 344 if states.size == 1
339 345 kind = :error
340 346 else
341 347 states.pop
342 348 if states.last.is_a?(::Array)
343 349 delimiter = states.last[1]
344 350 states[-1] = states.last[0]
345 351 tokens << [matched, :delimiter]
346 352 tokens << [:close, :inline]
347 353 next
348 354 else
349 355 kind = :operator
350 356 label_expected = true
351 357 end
352 358 end
353 359
354 360 elsif scan(/@/)
355 361 label_expected = false
356 362 kind = :exception
357 363
358 364 elsif scan RE::PHP_END
359 365 kind = :inline_delimiter
360 366 states = [:initial]
361 367
362 368 elsif match = scan(/<<<(?:(#{RE::IDENTIFIER})|"(#{RE::IDENTIFIER})"|'(#{RE::IDENTIFIER})')/o)
363 369 tokens << [:open, :string]
364 370 warn 'heredoc in heredoc?' if heredoc_delimiter
365 371 heredoc_delimiter = Regexp.escape(self[1] || self[2] || self[3])
366 372 kind = :delimiter
367 373 states.push self[3] ? :sqstring : :dqstring
368 374 heredoc_delimiter = /#{heredoc_delimiter}(?=;?$)/
369 375
370 376 elsif match = scan(/#{RE::OPERATOR}/o)
371 377 label_expected = match == ';'
372 378 if case_expected
373 379 label_expected = true if match == ':'
374 380 case_expected = false
375 381 end
376 382 kind = :operator
377 383
378 384 else
379 385 getch
380 386 kind = :error
381 387
382 388 end
383 389
384 390 when :sqstring
385 391 if scan(heredoc_delimiter ? /[^\\\n]+/ : /[^'\\]+/)
386 392 kind = :content
387 393 elsif !heredoc_delimiter && scan(/'/)
388 394 tokens << [matched, :delimiter]
389 395 tokens << [:close, :string]
390 396 delimiter = nil
391 397 label_expected = false
392 398 states.pop
393 399 next
394 400 elsif heredoc_delimiter && match = scan(/\n/)
395 401 kind = :content
396 402 if scan heredoc_delimiter
397 403 tokens << ["\n", :content]
398 404 tokens << [matched, :delimiter]
399 405 tokens << [:close, :string]
400 406 heredoc_delimiter = nil
401 407 label_expected = false
402 408 states.pop
403 409 next
404 410 end
405 411 elsif scan(heredoc_delimiter ? /\\\\/ : /\\[\\'\n]/)
406 412 kind = :char
407 413 elsif scan(/\\./m)
408 414 kind = :content
409 415 elsif scan(/\\/)
410 416 kind = :error
411 417 end
412 418
413 419 when :dqstring
414 420 if scan(heredoc_delimiter ? /[^${\\\n]+/ : (delimiter == '"' ? /[^"${\\]+/ : /[^`${\\]+/))
415 421 kind = :content
416 422 elsif !heredoc_delimiter && scan(delimiter == '"' ? /"/ : /`/)
417 423 tokens << [matched, :delimiter]
418 424 tokens << [:close, :string]
419 425 delimiter = nil
420 426 label_expected = false
421 427 states.pop
422 428 next
423 429 elsif heredoc_delimiter && match = scan(/\n/)
424 430 kind = :content
425 431 if scan heredoc_delimiter
426 432 tokens << ["\n", :content]
427 433 tokens << [matched, :delimiter]
428 434 tokens << [:close, :string]
429 435 heredoc_delimiter = nil
430 436 label_expected = false
431 437 states.pop
432 438 next
433 439 end
434 440 elsif scan(/\\(?:x[0-9A-Fa-f]{1,2}|[0-7]{1,3})/)
435 441 kind = :char
436 442 elsif scan(heredoc_delimiter ? /\\[nrtvf\\$]/ : (delimiter == '"' ? /\\[nrtvf\\$"]/ : /\\[nrtvf\\$`]/))
437 443 kind = :char
438 444 elsif scan(/\\./m)
439 445 kind = :content
440 446 elsif scan(/\\/)
441 447 kind = :error
442 448 elsif match = scan(/#{RE::VARIABLE}/o)
443 449 kind = :local_variable
444 450 if check(/\[#{RE::IDENTIFIER}\]/o)
445 451 tokens << [:open, :inline]
446 452 tokens << [match, :local_variable]
447 453 tokens << [scan(/\[/), :operator]
448 454 tokens << [scan(/#{RE::IDENTIFIER}/o), :ident]
449 455 tokens << [scan(/\]/), :operator]
450 456 tokens << [:close, :inline]
451 457 next
452 458 elsif check(/\[/)
453 459 match << scan(/\[['"]?#{RE::IDENTIFIER}?['"]?\]?/o)
454 460 kind = :error
455 461 elsif check(/->#{RE::IDENTIFIER}/o)
456 462 tokens << [:open, :inline]
457 463 tokens << [match, :local_variable]
458 464 tokens << [scan(/->/), :operator]
459 465 tokens << [scan(/#{RE::IDENTIFIER}/o), :ident]
460 466 tokens << [:close, :inline]
461 467 next
462 468 elsif check(/->/)
463 469 match << scan(/->/)
464 470 kind = :error
465 471 end
466 472 elsif match = scan(/\{/)
467 473 if check(/\$/)
468 474 kind = :delimiter
469 475 states[-1] = [states.last, delimiter]
470 476 delimiter = nil
471 477 states.push :php
472 478 tokens << [:open, :inline]
473 479 else
474 480 kind = :string
475 481 end
476 482 elsif scan(/\$\{#{RE::IDENTIFIER}\}/o)
477 483 kind = :local_variable
478 484 elsif scan(/\$/)
479 485 kind = :content
480 486 end
481 487
482 488 when :class_expected
483 489 if scan(/\s+/)
484 490 kind = :space
485 491 elsif match = scan(/#{RE::IDENTIFIER}/o)
486 492 kind = :class
487 493 states.pop
488 494 else
489 495 states.pop
490 496 next
491 497 end
492 498
493 499 when :function_expected
494 500 if scan(/\s+/)
495 501 kind = :space
496 502 elsif scan(/&/)
497 503 kind = :operator
498 504 elsif match = scan(/#{RE::IDENTIFIER}/o)
499 505 kind = :function
500 506 states.pop
501 507 else
502 508 states.pop
503 509 next
504 510 end
505 511
506 512 else
507 513 raise_inspect 'Unknown state!', tokens, states
508 514 end
509 515
510 516 match ||= matched
511 517 if $CODERAY_DEBUG and not kind
512 518 raise_inspect 'Error token %p in line %d' %
513 519 [[match, kind], line], tokens, states
514 520 end
515 521 raise_inspect 'Empty token', tokens, states unless match
516 522
517 523 tokens << [match, kind]
518 524
519 525 end
520 526
521 527 tokens
522 528 end
523 529
524 530 end
525 531
526 532 end
527 533 end
1 NO CONTENT: file renamed from vendor/plugins/coderay-0.9.2/lib/coderay/scanners/plaintext.rb to vendor/gems/coderay-0.9.7/lib/coderay/scanners/plaintext.rb
1 NO CONTENT: file renamed from vendor/plugins/coderay-0.9.2/lib/coderay/scanners/python.rb to vendor/gems/coderay-0.9.7/lib/coderay/scanners/python.rb
@@ -1,74 +1,78
1 1 module CodeRay
2 2 module Scanners
3 3
4 4 load :html
5 5 load :ruby
6 6
7 7 # RHTML Scanner
8 8 class RHTML < Scanner
9 9
10 10 include Streamable
11 11 register_for :rhtml
12 12 title 'HTML ERB Template'
13 13
14 14 KINDS_NOT_LOC = HTML::KINDS_NOT_LOC
15 15
16 16 ERB_RUBY_BLOCK = /
17 17 <%(?!%)[=-]?
18 18 (?>
19 19 [^\-%]* # normal*
20 20 (?> # special
21 21 (?: %(?!>) | -(?!%>) )
22 22 [^\-%]* # normal*
23 23 )*
24 24 )
25 25 (?: -?%> )?
26 26 /x
27 27
28 28 START_OF_ERB = /
29 29 <%(?!%)
30 30 /x
31 31
32 32 private
33 33
34 34 def setup
35 35 @ruby_scanner = CodeRay.scanner :ruby, :tokens => @tokens, :keep_tokens => true
36 36 @html_scanner = CodeRay.scanner :html, :tokens => @tokens, :keep_tokens => true, :keep_state => true
37 37 end
38 38
39 39 def reset_instance
40 40 super
41 41 @html_scanner.reset
42 42 end
43 43
44 44 def scan_tokens tokens, options
45 45
46 46 until eos?
47 47
48 48 if (match = scan_until(/(?=#{START_OF_ERB})/o) || scan_until(/\z/)) and not match.empty?
49 49 @html_scanner.tokenize match
50 50
51 51 elsif match = scan(/#{ERB_RUBY_BLOCK}/o)
52 start_tag = match[/\A<%[-=]?/]
52 start_tag = match[/\A<%[-=#]?/]
53 53 end_tag = match[/-?%?>?\z/]
54 54 tokens << [:open, :inline]
55 55 tokens << [start_tag, :inline_delimiter]
56 56 code = match[start_tag.size .. -1 - end_tag.size]
57 @ruby_scanner.tokenize code
57 if start_tag == '<%#'
58 tokens << [code, :comment]
59 else
60 @ruby_scanner.tokenize code
61 end
58 62 tokens << [end_tag, :inline_delimiter] unless end_tag.empty?
59 63 tokens << [:close, :inline]
60 64
61 65 else
62 66 raise_inspect 'else-case reached!', tokens
63 67 end
64 68
65 69 end
66 70
67 71 tokens
68 72
69 73 end
70 74
71 75 end
72 76
73 77 end
74 78 end
@@ -1,413 +1,444
1 # encoding: utf-8
1 2 module CodeRay
2 3 module Scanners
3 4
4 5 # This scanner is really complex, since Ruby _is_ a complex language!
5 6 #
6 7 # It tries to highlight 100% of all common code,
7 8 # and 90% of strange codes.
8 9 #
9 10 # It is optimized for HTML highlighting, and is not very useful for
10 11 # parsing or pretty printing.
11 12 #
12 13 # For now, I think it's better than the scanners in VIM or Syntax, or
13 14 # any highlighter I was able to find, except Caleb's RubyLexer.
14 15 #
15 16 # I hope it's also better than the rdoc/irb lexer.
16 17 class Ruby < Scanner
17 18
18 19 include Streamable
19 20
20 21 register_for :ruby
21 22 file_extension 'rb'
22 23
23 24 helper :patterns
24 25
25 26 if not defined? EncodingError
26 27 EncodingError = Class.new Exception
27 28 end
28 29
29 30 private
30 31 def scan_tokens tokens, options
32 if string.respond_to?(:encoding)
33 unless string.encoding == Encoding::UTF_8
34 self.string = string.encode Encoding::UTF_8,
35 :invalid => :replace, :undef => :replace, :replace => '?'
36 end
37 unicode = false
38 else
39 unicode = exist?(/[^\x00-\x7f]/)
40 end
41
31 42 last_token_dot = false
32 43 value_expected = true
33 44 heredocs = nil
34 45 last_state = nil
35 46 state = :initial
36 47 depth = nil
37 48 inline_block_stack = []
38 unicode = string.respond_to?(:encoding) && string.encoding.name == 'UTF-8'
49
39 50
40 51 patterns = Patterns # avoid constant lookup
41 52
42 53 until eos?
43 54 match = nil
44 55 kind = nil
45 56
46 57 if state.instance_of? patterns::StringState
47 58 # {{{
48 59 match = scan_until(state.pattern) || scan_until(/\z/)
49 60 tokens << [match, :content] unless match.empty?
50 61 break if eos?
51 62
52 63 if state.heredoc and self[1] # end of heredoc
53 64 match = getch.to_s
54 65 match << scan_until(/$/) unless eos?
55 66 tokens << [match, :delimiter]
56 67 tokens << [:close, state.type]
57 68 state = state.next_state
58 69 next
59 70 end
60 71
61 72 case match = getch
62 73
63 74 when state.delim
64 75 if state.paren
65 76 state.paren_depth -= 1
66 77 if state.paren_depth > 0
67 78 tokens << [match, :nesting_delimiter]
68 79 next
69 80 end
70 81 end
71 82 tokens << [match, :delimiter]
72 83 if state.type == :regexp and not eos?
73 84 modifiers = scan(/#{patterns::REGEXP_MODIFIERS}/ox)
74 85 tokens << [modifiers, :modifier] unless modifiers.empty?
75 86 end
76 87 tokens << [:close, state.type]
77 88 value_expected = false
78 89 state = state.next_state
79 90
80 91 when '\\'
81 92 if state.interpreted
82 93 if esc = scan(/ #{patterns::ESCAPE} /ox)
83 94 tokens << [match + esc, :char]
84 95 else
85 96 tokens << [match, :error]
86 97 end
87 98 else
88 99 case m = getch
89 100 when state.delim, '\\'
90 101 tokens << [match + m, :char]
91 102 when nil
92 103 tokens << [match, :error]
93 104 else
94 105 tokens << [match + m, :content]
95 106 end
96 107 end
97 108
98 109 when '#'
99 110 case peek(1)
100 111 when '{'
101 112 inline_block_stack << [state, depth, heredocs]
102 113 value_expected = true
103 114 state = :initial
104 115 depth = 1
105 116 tokens << [:open, :inline]
106 117 tokens << [match + getch, :inline_delimiter]
107 118 when '$', '@'
108 119 tokens << [match, :escape]
109 120 last_state = state # scan one token as normal code, then return here
110 121 state = :initial
111 122 else
112 123 raise_inspect 'else-case # reached; #%p not handled' % peek(1), tokens
113 124 end
114 125
115 126 when state.paren
116 127 state.paren_depth += 1
117 128 tokens << [match, :nesting_delimiter]
118 129
119 130 when /#{patterns::REGEXP_SYMBOLS}/ox
120 131 tokens << [match, :function]
121 132
122 133 else
123 134 raise_inspect 'else-case " reached; %p not handled, state = %p' % [match, state], tokens
124 135
125 136 end
126 137 next
127 138 # }}}
128 139 else
129 140 # {{{
130 141 if match = scan(/[ \t\f]+/)
131 142 kind = :space
132 143 match << scan(/\s*/) unless eos? || heredocs
133 144 value_expected = true if match.index(?\n)
134 145 tokens << [match, kind]
135 146 next
136 147
137 148 elsif match = scan(/\\?\n/)
138 149 kind = :space
139 150 if match == "\n"
140 151 value_expected = true
141 152 state = :initial if state == :undef_comma_expected
142 153 end
143 154 if heredocs
144 155 unscan # heredoc scanning needs \n at start
145 156 state = heredocs.shift
146 157 tokens << [:open, state.type]
147 158 heredocs = nil if heredocs.empty?
148 159 next
149 160 else
150 161 match << scan(/\s*/) unless eos?
151 162 end
152 163 tokens << [match, kind]
153 164 next
154 165
155 166 elsif bol? && match = scan(/\#!.*/)
156 167 tokens << [match, :doctype]
157 168 next
158 169
159 170 elsif match = scan(/\#.*/) or
160 171 ( bol? and match = scan(/#{patterns::RUBYDOC_OR_DATA}/o) )
161 172 kind = :comment
162 173 tokens << [match, kind]
163 174 next
164 175
165 176 elsif state == :initial
166 177
167 178 # IDENTS #
168 179 if match = scan(unicode ? /#{patterns::METHOD_NAME}/uo :
169 180 /#{patterns::METHOD_NAME}/o)
170 181 if last_token_dot
171 182 kind = if match[/^[A-Z]/] and not match?(/\(/) then :constant else :ident end
172 183 else
173 kind = patterns::IDENT_KIND[match]
174 if kind == :ident and match[/^[A-Z]/] and not match[/[!?]$/] and not match?(/\(/)
175 kind = :constant
176 elsif kind == :reserved
177 state = patterns::DEF_NEW_STATE[match]
178 value_expected = :set if patterns::KEYWORDS_EXPECTING_VALUE[match]
184 if value_expected != :expect_colon && scan(/:(?= )/)
185 tokens << [match, :key]
186 match = ':'
187 kind = :operator
188 else
189 kind = patterns::IDENT_KIND[match]
190 if kind == :ident
191 if match[/\A[A-Z]/] and not match[/[!?]$/] and not match?(/\(/)
192 kind = :constant
193 end
194 elsif kind == :reserved
195 state = patterns::DEF_NEW_STATE[match]
196 value_expected = :set if patterns::KEYWORDS_EXPECTING_VALUE[match]
197 end
179 198 end
180 199 end
181 200 value_expected = :set if check(/#{patterns::VALUE_FOLLOWS}/o)
182 201
183 202 elsif last_token_dot and match = scan(/#{patterns::METHOD_NAME_OPERATOR}|\(/o)
184 203 kind = :ident
185 value_expected = :set if check(/#{patterns::VALUE_FOLLOWS}/o)
204 value_expected = :set if check(unicode ? /#{patterns::VALUE_FOLLOWS}/uo :
205 /#{patterns::VALUE_FOLLOWS}/o)
186 206
187 207 # OPERATORS #
188 208 elsif not last_token_dot and match = scan(/ \.\.\.? | (?:\.|::)() | [,\(\)\[\]\{\}] | ==?=? /x)
189 209 if match !~ / [.\)\]\}] /x or match =~ /\.\.\.?/
190 210 value_expected = :set
191 211 end
192 212 last_token_dot = :set if self[1]
193 213 kind = :operator
194 214 unless inline_block_stack.empty?
195 215 case match
196 216 when '{'
197 217 depth += 1
198 218 when '}'
199 219 depth -= 1
200 220 if depth == 0 # closing brace of inline block reached
201 221 state, depth, heredocs = inline_block_stack.pop
202 222 heredocs = nil if heredocs && heredocs.empty?
203 223 tokens << [match, :inline_delimiter]
204 224 kind = :inline
205 225 match = :close
206 226 end
207 227 end
208 228 end
209 229
210 230 elsif match = scan(/ ['"] /mx)
211 231 tokens << [:open, :string]
212 232 kind = :delimiter
213 233 state = patterns::StringState.new :string, match == '"', match # important for streaming
214 234
215 elsif match = scan(/#{patterns::INSTANCE_VARIABLE}/o)
235 elsif match = scan(unicode ? /#{patterns::INSTANCE_VARIABLE}/uo :
236 /#{patterns::INSTANCE_VARIABLE}/o)
216 237 kind = :instance_variable
217 238
218 239 elsif value_expected and match = scan(/\//)
219 240 tokens << [:open, :regexp]
220 241 kind = :delimiter
221 242 interpreted = true
222 243 state = patterns::StringState.new :regexp, interpreted, match
223 244
224 245 # elsif match = scan(/[-+]?#{patterns::NUMERIC}/o)
225 246 elsif match = value_expected ? scan(/[-+]?#{patterns::NUMERIC}/o) : scan(/#{patterns::NUMERIC}/o)
226 247 kind = self[1] ? :float : :integer
227 248
228 elsif match = scan(/#{patterns::SYMBOL}/o)
249 elsif match = scan(unicode ? /#{patterns::SYMBOL}/uo :
250 /#{patterns::SYMBOL}/o)
229 251 case delim = match[1]
230 252 when ?', ?"
231 253 tokens << [:open, :symbol]
232 254 tokens << [':', :symbol]
233 255 match = delim.chr
234 256 kind = :delimiter
235 257 state = patterns::StringState.new :symbol, delim == ?", match
236 258 else
237 259 kind = :symbol
238 260 end
239 261
240 elsif match = scan(/ [-+!~^]=? | [*|&]{1,2}=? | >>? /x)
262 elsif match = scan(/ -[>=]? | [+!~^]=? | [*|&]{1,2}=? | >>? /x)
241 263 value_expected = :set
242 264 kind = :operator
243 265
244 elsif value_expected and match = scan(/#{patterns::HEREDOC_OPEN}/o)
266 elsif value_expected and match = scan(unicode ? /#{patterns::HEREDOC_OPEN}/uo :
267 /#{patterns::HEREDOC_OPEN}/o)
245 268 indented = self[1] == '-'
246 269 quote = self[3]
247 270 delim = self[quote ? 4 : 2]
248 271 kind = patterns::QUOTE_TO_TYPE[quote]
249 272 tokens << [:open, kind]
250 273 tokens << [match, :delimiter]
251 274 match = :close
252 275 heredoc = patterns::StringState.new kind, quote != '\'', delim, (indented ? :indented : :linestart )
253 276 heredocs ||= [] # create heredocs if empty
254 277 heredocs << heredoc
255 278
256 279 elsif value_expected and match = scan(/#{patterns::FANCY_START_CORRECT}/o)
257 280 kind, interpreted = *patterns::FancyStringType.fetch(self[1]) do
258 281 raise_inspect 'Unknown fancy string: %%%p' % k, tokens
259 282 end
260 283 tokens << [:open, kind]
261 284 state = patterns::StringState.new kind, interpreted, self[2]
262 285 kind = :delimiter
263 286
264 elsif value_expected and match = scan(/#{patterns::CHARACTER}/o)
287 elsif value_expected and match = scan(unicode ? /#{patterns::CHARACTER}/uo :
288 /#{patterns::CHARACTER}/o)
265 289 kind = :integer
266 290
267 291 elsif match = scan(/ [\/%]=? | <(?:<|=>?)? | [?:;] /x)
268 292 value_expected = :set
269 293 kind = :operator
270 294
271 295 elsif match = scan(/`/)
272 296 if last_token_dot
273 297 kind = :operator
274 298 else
275 299 tokens << [:open, :shell]
276 300 kind = :delimiter
277 301 state = patterns::StringState.new :shell, true, match
278 302 end
279 303
280 elsif match = scan(/#{patterns::GLOBAL_VARIABLE}/o)
304 elsif match = scan(unicode ? /#{patterns::GLOBAL_VARIABLE}/uo :
305 /#{patterns::GLOBAL_VARIABLE}/o)
281 306 kind = :global_variable
282 307
283 elsif match = scan(/#{patterns::CLASS_VARIABLE}/o)
308 elsif match = scan(unicode ? /#{patterns::CLASS_VARIABLE}/uo :
309 /#{patterns::CLASS_VARIABLE}/o)
284 310 kind = :class_variable
285 311
286 312 else
287 if !unicode
313 if !unicode && !string.respond_to?(:encoding)
288 314 # check for unicode
289 315 debug, $DEBUG = $DEBUG, false
290 316 begin
291 317 if check(/./mu).size > 1
292 318 # seems like we should try again with unicode
293 319 unicode = true
294 320 end
295 321 rescue
296 322 # bad unicode char; use getch
297 323 ensure
298 324 $DEBUG = debug
299 325 end
300 326 next if unicode
301 327 end
302 328 kind = :error
303 match = getch
329 match = scan(unicode ? /./mu : /./m)
304 330
305 331 end
306 332
307 333 elsif state == :def_expected
308 334 state = :initial
309 335 if scan(/self\./)
310 336 tokens << ['self', :pre_constant]
311 337 tokens << ['.', :operator]
312 338 end
313 339 if match = scan(unicode ? /(?>#{patterns::METHOD_NAME_EX})(?!\.|::)/uo :
314 340 /(?>#{patterns::METHOD_NAME_EX})(?!\.|::)/o)
315 341 kind = :method
316 342 else
317 343 next
318 344 end
319 345
320 346 elsif state == :module_expected
321 347 if match = scan(/<</)
322 348 kind = :operator
323 349 else
324 350 state = :initial
325 if match = scan(/ (?:#{patterns::IDENT}::)* #{patterns::IDENT} /ox)
351 if match = scan(unicode ? /(?:#{patterns::IDENT}::)*#{patterns::IDENT}/uo :
352 /(?:#{patterns::IDENT}::)*#{patterns::IDENT}/o)
326 353 kind = :class
327 354 else
328 355 next
329 356 end
330 357 end
331 358
332 359 elsif state == :undef_expected
333 360 state = :undef_comma_expected
334 if match = scan(/#{patterns::METHOD_NAME_EX}/o)
361 if match = scan(unicode ? /#{patterns::METHOD_NAME_EX}/uo :
362 /#{patterns::METHOD_NAME_EX}/o)
335 363 kind = :method
336 elsif match = scan(/#{patterns::SYMBOL}/o)
364 elsif match = scan(unicode ? /#{patterns::SYMBOL}/uo :
365 /#{patterns::SYMBOL}/o)
337 366 case delim = match[1]
338 367 when ?', ?"
339 368 tokens << [:open, :symbol]
340 369 tokens << [':', :symbol]
341 370 match = delim.chr
342 371 kind = :delimiter
343 372 state = patterns::StringState.new :symbol, delim == ?", match
344 373 state.next_state = :undef_comma_expected
345 374 else
346 375 kind = :symbol
347 376 end
348 377 else
349 378 state = :initial
350 379 next
351 380 end
352 381
353 382 elsif state == :alias_expected
354 383 match = scan(unicode ? /(#{patterns::METHOD_NAME_OR_SYMBOL})([ \t]+)(#{patterns::METHOD_NAME_OR_SYMBOL})/uo :
355 384 /(#{patterns::METHOD_NAME_OR_SYMBOL})([ \t]+)(#{patterns::METHOD_NAME_OR_SYMBOL})/o)
356 385
357 386 if match
358 387 tokens << [self[1], (self[1][0] == ?: ? :symbol : :method)]
359 388 tokens << [self[2], :space]
360 389 tokens << [self[3], (self[3][0] == ?: ? :symbol : :method)]
361 390 end
362 391 state = :initial
363 392 next
364 393
365 394 elsif state == :undef_comma_expected
366 395 if match = scan(/,/)
367 396 kind = :operator
368 397 state = :undef_expected
369 398 else
370 399 state = :initial
371 400 next
372 401 end
373 402
374 403 end
375 404 # }}}
376 405
377 406 unless kind == :error
378 value_expected = value_expected == :set
407 if value_expected = value_expected == :set
408 value_expected = :expect_colon if match == '?' || match == 'when'
409 end
379 410 last_token_dot = last_token_dot == :set
380 411 end
381 412
382 413 if $CODERAY_DEBUG and not kind
383 414 raise_inspect 'Error token %p in line %d' %
384 415 [[match, kind], line], tokens, state
385 416 end
386 417 raise_inspect 'Empty token', tokens unless match
387 418
388 419 tokens << [match, kind]
389 420
390 421 if last_state
391 422 state = last_state
392 423 last_state = nil
393 424 end
394 425 end
395 426 end
396 427
397 428 inline_block_stack << [state] if state.is_a? patterns::StringState
398 429 until inline_block_stack.empty?
399 430 this_block = inline_block_stack.pop
400 431 tokens << [:close, :inline] if this_block.size > 1
401 432 state = this_block.first
402 433 tokens << [:close, state.type]
403 434 end
404 435
405 436 tokens
406 437 end
407 438
408 439 end
409 440
410 441 end
411 442 end
412 443
413 444 # vim:fdm=marker
@@ -1,238 +1,252
1 1 # encoding: utf-8
2 2 module CodeRay
3 3 module Scanners
4 4
5 5 module Ruby::Patterns # :nodoc:
6 6
7 7 RESERVED_WORDS = %w[
8 8 and def end in or unless begin
9 9 defined? ensure module redo super until
10 10 BEGIN break do next rescue then
11 11 when END case else for retry
12 12 while alias class elsif if not return
13 13 undef yield
14 14 ]
15 15
16 16 DEF_KEYWORDS = %w[ def ]
17 17 UNDEF_KEYWORDS = %w[ undef ]
18 18 ALIAS_KEYWORDS = %w[ alias ]
19 MODULE_KEYWORDS = %w[class module]
19 MODULE_KEYWORDS = %w[ class module ]
20 20 DEF_NEW_STATE = WordList.new(:initial).
21 21 add(DEF_KEYWORDS, :def_expected).
22 22 add(UNDEF_KEYWORDS, :undef_expected).
23 23 add(ALIAS_KEYWORDS, :alias_expected).
24 24 add(MODULE_KEYWORDS, :module_expected)
25 25
26 26 PREDEFINED_CONSTANTS = %w[
27 27 nil true false self
28 DATA ARGV ARGF __FILE__ __LINE__
28 DATA ARGV ARGF
29 __FILE__ __LINE__ __ENCODING__
29 30 ]
30 31
31 32 IDENT_KIND = WordList.new(:ident).
32 33 add(RESERVED_WORDS, :reserved).
33 34 add(PREDEFINED_CONSTANTS, :pre_constant)
34 35
35 IDENT = 'ä'[/[[:alpha:]]/] == 'ä' ? /[[:alpha:]_][[:alnum:]_]*/ : /[^\W\d]\w*/
36 if /\w/u === '∑'
37 # MRI 1.8.6, 1.8.7
38 IDENT = /[^\W\d]\w*/
39 else
40 if //.respond_to? :encoding
41 # MRI 1.9.1, 1.9.2
42 IDENT = Regexp.new '[\p{L}\p{M}\p{Pc}\p{Sm}&&[^\x00-\x40\x5b-\x5e\x60\x7b-\x7f]][\p{L}\p{M}\p{N}\p{Pc}\p{Sm}&&[^\x00-\x2f\x3a-\x40\x5b-\x5e\x60\x7b-\x7f]]*'
43 else
44 # JRuby, Rubinius
45 IDENT = /[^\x00-\x40\x5b-\x5e\x60\x7b-\x7f][^\x00-\x2f\x3a-\x40\x5b-\x5e\x60\x7b-\x7f]*/
46 end
47 end
36 48
37 49 METHOD_NAME = / #{IDENT} [?!]? /ox
38 50 METHOD_NAME_OPERATOR = /
39 51 \*\*? # multiplication and power
40 52 | [-+~]@? # plus, minus, tilde with and without at sign
41 53 | [\/%&|^`] # division, modulo or format strings, and, or, xor, system
42 54 | \[\]=? # array getter and setter
43 55 | << | >> # append or shift left, shift right
44 56 | <=?>? | >=? # comparison, rocket operator
45 57 | ===? | =~ # simple equality, case equality, match
46 58 | ![~=@]? # negation with and without at sign, not-equal and not-match
47 59 /ox
48 60 METHOD_NAME_EX = / #{IDENT} (?:[?!]|=(?!>))? | #{METHOD_NAME_OPERATOR} /ox
49 61 INSTANCE_VARIABLE = / @ #{IDENT} /ox
50 62 CLASS_VARIABLE = / @@ #{IDENT} /ox
51 63 OBJECT_VARIABLE = / @@? #{IDENT} /ox
52 64 GLOBAL_VARIABLE = / \$ (?: #{IDENT} | [1-9]\d* | 0\w* | [~&+`'=\/,;_.<>!@$?*":\\] | -[a-zA-Z_0-9] ) /ox
53 65 PREFIX_VARIABLE = / #{GLOBAL_VARIABLE} | #{OBJECT_VARIABLE} /ox
54 66 VARIABLE = / @?@? #{IDENT} | #{GLOBAL_VARIABLE} /ox
55 67
56 68 QUOTE_TO_TYPE = {
57 69 '`' => :shell,
58 70 '/'=> :regexp,
59 71 }
60 72 QUOTE_TO_TYPE.default = :string
61 73
62 74 REGEXP_MODIFIERS = /[mixounse]*/
63 75 REGEXP_SYMBOLS = /[|?*+(){}\[\].^$]/
64 76
65 77 DECIMAL = /\d+(?:_\d+)*/
66 78 OCTAL = /0_?[0-7]+(?:_[0-7]+)*/
67 79 HEXADECIMAL = /0x[0-9A-Fa-f]+(?:_[0-9A-Fa-f]+)*/
68 80 BINARY = /0b[01]+(?:_[01]+)*/
69 81
70 82 EXPONENT = / [eE] [+-]? #{DECIMAL} /ox
71 83 FLOAT_SUFFIX = / #{EXPONENT} | \. #{DECIMAL} #{EXPONENT}? /ox
72 84 FLOAT_OR_INT = / #{DECIMAL} (?: #{FLOAT_SUFFIX} () )? /ox
73 85 NUMERIC = / (?: (?=0) (?: #{OCTAL} | #{HEXADECIMAL} | #{BINARY} ) | #{FLOAT_OR_INT} ) /ox
74 86
75 87 SYMBOL = /
76 88 :
77 89 (?:
78 90 #{METHOD_NAME_EX}
79 91 | #{PREFIX_VARIABLE}
80 92 | ['"]
81 93 )
82 94 /ox
83 95 METHOD_NAME_OR_SYMBOL = / #{METHOD_NAME_EX} | #{SYMBOL} /ox
84 96
85 97 SIMPLE_ESCAPE = /
86 98 [abefnrstv]
87 99 | [0-7]{1,3}
88 100 | x[0-9A-Fa-f]{1,2}
89 101 | .?
90 102 /mx
91 103
92 104 CONTROL_META_ESCAPE = /
93 105 (?: M-|C-|c )
94 106 (?: \\ (?: M-|C-|c ) )*
95 107 (?: [^\\] | \\ #{SIMPLE_ESCAPE} )?
96 108 /mox
97 109
98 110 ESCAPE = /
99 111 #{CONTROL_META_ESCAPE} | #{SIMPLE_ESCAPE}
100 112 /mox
101 113
102 114 CHARACTER = /
103 115 \?
104 116 (?:
105 117 [^\s\\]
106 118 | \\ #{ESCAPE}
107 119 )
108 120 /mox
109 121
110 122 # NOTE: This is not completely correct, but
111 123 # nobody needs heredoc delimiters ending with \n.
124 # Also, delimiters starting with numbers are allowed.
125 # but they are more often than not a false positive.
112 126 HEREDOC_OPEN = /
113 127 << (-)? # $1 = float
114 128 (?:
115 ( [A-Za-z_0-9]+ ) # $2 = delim
129 ( #{IDENT} ) # $2 = delim
116 130 |
117 131 ( ["'`\/] ) # $3 = quote, type
118 132 ( [^\n]*? ) \3 # $4 = delim
119 133 )
120 134 /mx
121 135
122 136 RUBYDOC = /
123 137 =begin (?!\S)
124 138 .*?
125 139 (?: \Z | ^=end (?!\S) [^\n]* )
126 140 /mx
127 141
128 142 DATA = /
129 143 __END__$
130 144 .*?
131 145 (?: \Z | (?=^\#CODE) )
132 146 /mx
133 147
134 148 # Checks for a valid value to follow. This enables
135 149 # value_expected in method calls without parentheses.
136 150 VALUE_FOLLOWS = /
137 151 (?>[ \t\f\v]+)
138 152 (?:
139 153 [%\/][^\s=]
140 154 | <<-?\S
141 155 | [-+] \d
142 156 | #{CHARACTER}
143 157 )
144 158 /x
145 159 KEYWORDS_EXPECTING_VALUE = WordList.new.add(%w[
146 160 and end in or unless begin
147 161 defined? ensure redo super until
148 162 break do next rescue then
149 163 when case else for retry
150 164 while elsif if not return
151 165 yield
152 166 ])
153 167
154 168 RUBYDOC_OR_DATA = / #{RUBYDOC} | #{DATA} /xo
155 169
156 170 RDOC_DATA_START = / ^=begin (?!\S) | ^__END__$ /x
157 171
158 172 FANCY_START_CORRECT = / % ( [qQwWxsr] | (?![a-zA-Z0-9]) ) ([^a-zA-Z0-9]) /mx
159 173
160 174 FancyStringType = {
161 175 'q' => [:string, false],
162 176 'Q' => [:string, true],
163 177 'r' => [:regexp, true],
164 178 's' => [:symbol, false],
165 179 'x' => [:shell, true]
166 180 }
167 181 FancyStringType['w'] = FancyStringType['q']
168 182 FancyStringType['W'] = FancyStringType[''] = FancyStringType['Q']
169 183
170 184 class StringState < Struct.new :type, :interpreted, :delim, :heredoc,
171 185 :paren, :paren_depth, :pattern, :next_state
172 186
173 187 CLOSING_PAREN = Hash[ *%w[
174 188 ( )
175 189 [ ]
176 190 < >
177 191 { }
178 192 ] ]
179 193
180 194 CLOSING_PAREN.each { |k,v| k.freeze; v.freeze } # debug, if I try to change it with <<
181 195 OPENING_PAREN = CLOSING_PAREN.invert
182 196
183 197 STRING_PATTERN = Hash.new do |h, k|
184 198 delim, interpreted = *k
185 199 delim_pattern = Regexp.escape(delim.dup) # dup: workaround for old Ruby
186 200 if closing_paren = CLOSING_PAREN[delim]
187 201 delim_pattern = delim_pattern[0..-1] if defined? JRUBY_VERSION # JRuby fix
188 202 delim_pattern << Regexp.escape(closing_paren)
189 203 end
190 204 delim_pattern << '\\\\' unless delim == '\\'
191 205
192 206 special_escapes =
193 207 case interpreted
194 208 when :regexp_symbols
195 209 '| ' + REGEXP_SYMBOLS.source
196 210 when :words
197 211 '| \s'
198 212 end
199 213
200 214 h[k] =
201 215 if interpreted and not delim == '#'
202 216 / (?= [#{delim_pattern}] | \# [{$@] #{special_escapes} ) /mx
203 217 else
204 218 / (?= [#{delim_pattern}] #{special_escapes} ) /mx
205 219 end
206 220 end
207 221
208 222 HEREDOC_PATTERN = Hash.new do |h, k|
209 223 delim, interpreted, indented = *k
210 224 delim_pattern = Regexp.escape(delim.dup) # dup: workaround for old Ruby
211 225 delim_pattern = / \n #{ '(?>[\ \t]*)' if indented } #{ Regexp.new delim_pattern } $ /x
212 226 h[k] =
213 227 if interpreted
214 228 / (?= #{delim_pattern}() | \\ | \# [{$@] ) /mx # $1 set == end of heredoc
215 229 else
216 230 / (?= #{delim_pattern}() | \\ ) /mx
217 231 end
218 232 end
219 233
220 234 def initialize kind, interpreted, delim, heredoc = false
221 235 if heredoc
222 236 pattern = HEREDOC_PATTERN[ [delim, interpreted, heredoc == :indented] ]
223 237 delim = nil
224 238 else
225 239 pattern = STRING_PATTERN[ [delim, interpreted] ]
226 240 if paren = CLOSING_PAREN[delim]
227 241 delim, paren = paren, delim
228 242 paren_depth = 1
229 243 end
230 244 end
231 245 super kind, interpreted, delim, heredoc, paren, paren_depth, pattern, :initial
232 246 end
233 247 end unless defined? StringState
234 248
235 249 end
236 250
237 251 end
238 252 end
1 NO CONTENT: file renamed from vendor/plugins/coderay-0.9.2/lib/coderay/scanners/scheme.rb to vendor/gems/coderay-0.9.7/lib/coderay/scanners/scheme.rb
@@ -1,162 +1,162
1 1 module CodeRay module Scanners
2 2
3 3 # by Josh Goebel
4 4 class SQL < Scanner
5 5
6 6 register_for :sql
7 7
8 8 RESERVED_WORDS = %w(
9 9 create database table index trigger drop primary key set select
10 10 insert update delete replace into
11 11 on from values before and or if exists case when
12 12 then else as group order by avg where
13 13 join inner outer union engine not
14 14 like end using collate show columns begin
15 15 )
16 16
17 17 PREDEFINED_TYPES = %w(
18 18 char varchar enum binary text tinytext mediumtext
19 19 longtext blob tinyblob mediumblob longblob timestamp
20 20 date time datetime year double decimal float int
21 21 integer tinyint mediumint bigint smallint unsigned bit
22 22 bool boolean hex bin oct
23 23 )
24 24
25 25 PREDEFINED_FUNCTIONS = %w( sum cast abs pi count min max avg )
26 26
27 27 DIRECTIVES = %w( auto_increment unique default charset )
28 28
29 29 PREDEFINED_CONSTANTS = %w( null true false )
30 30
31 31 IDENT_KIND = CaseIgnoringWordList.new(:ident).
32 32 add(RESERVED_WORDS, :reserved).
33 33 add(PREDEFINED_TYPES, :pre_type).
34 34 add(PREDEFINED_CONSTANTS, :pre_constant).
35 35 add(PREDEFINED_FUNCTIONS, :predefined).
36 36 add(DIRECTIVES, :directive)
37 37
38 38 ESCAPE = / [rbfntv\n\\\/'"] | x[a-fA-F0-9]{1,2} | [0-7]{1,3} | . /mx
39 39 UNICODE_ESCAPE = / u[a-fA-F0-9]{4} | U[a-fA-F0-9]{8} /x
40 40
41 41 STRING_PREFIXES = /[xnb]|_\w+/i
42 42
43 43 def scan_tokens tokens, options
44 44
45 45 state = :initial
46 46 string_type = nil
47 47 string_content = ''
48 48
49 49 until eos?
50 50
51 51 kind = nil
52 52 match = nil
53 53
54 54 if state == :initial
55 55
56 56 if scan(/ \s+ | \\\n /x)
57 57 kind = :space
58 58
59 elsif scan(/^(?:--\s?|#).*/)
59 elsif scan(/(?:--\s?|#).*/)
60 60 kind = :comment
61 61
62 62 elsif scan(%r! /\* (?: .*? \*/ | .* ) !mx)
63 63 kind = :comment
64 64
65 65 elsif scan(/ [-+*\/=<>;,!&^|()\[\]{}~%] | \.(?!\d) /x)
66 66 kind = :operator
67 67
68 68 elsif scan(/(#{STRING_PREFIXES})?([`"'])/o)
69 69 prefix = self[1]
70 70 string_type = self[2]
71 71 tokens << [:open, :string]
72 72 tokens << [prefix, :modifier] if prefix
73 73 match = string_type
74 74 state = :string
75 75 kind = :delimiter
76 76
77 77 elsif match = scan(/ @? [A-Za-z_][A-Za-z_0-9]* /x)
78 78 kind = match[0] == ?@ ? :variable : IDENT_KIND[match.downcase]
79 79
80 80 elsif scan(/0[xX][0-9A-Fa-f]+/)
81 81 kind = :hex
82 82
83 83 elsif scan(/0[0-7]+(?![89.eEfF])/)
84 84 kind = :oct
85 85
86 86 elsif scan(/(?>\d+)(?![.eEfF])/)
87 87 kind = :integer
88 88
89 89 elsif scan(/\d[fF]|\d*\.\d+(?:[eE][+-]?\d+)?|\d+[eE][+-]?\d+/)
90 90 kind = :float
91 91
92 92 else
93 93 getch
94 94 kind = :error
95 95
96 96 end
97 97
98 98 elsif state == :string
99 99 if match = scan(/[^\\"'`]+/)
100 100 string_content << match
101 101 next
102 102 elsif match = scan(/["'`]/)
103 103 if string_type == match
104 104 if peek(1) == string_type # doubling means escape
105 105 string_content << string_type << getch
106 106 next
107 107 end
108 108 unless string_content.empty?
109 109 tokens << [string_content, :content]
110 110 string_content = ''
111 111 end
112 112 tokens << [matched, :delimiter]
113 113 tokens << [:close, :string]
114 114 state = :initial
115 115 string_type = nil
116 116 next
117 117 else
118 118 string_content << match
119 119 end
120 120 next
121 121 elsif scan(/ \\ (?: #{ESCAPE} | #{UNICODE_ESCAPE} ) /mox)
122 122 unless string_content.empty?
123 123 tokens << [string_content, :content]
124 124 string_content = ''
125 125 end
126 126 kind = :char
127 127 elsif match = scan(/ \\ . /mox)
128 128 string_content << match
129 129 next
130 130 elsif scan(/ \\ | $ /x)
131 131 unless string_content.empty?
132 132 tokens << [string_content, :content]
133 133 string_content = ''
134 134 end
135 135 kind = :error
136 136 state = :initial
137 137 else
138 138 raise "else case \" reached; %p not handled." % peek(1), tokens
139 139 end
140 140
141 141 else
142 142 raise 'else-case reached', tokens
143 143
144 144 end
145 145
146 146 match ||= matched
147 147 unless kind
148 148 raise_inspect 'Error token %p in line %d' %
149 149 [[match, kind], line], tokens, state
150 150 end
151 151 raise_inspect 'Empty token', tokens unless match
152 152
153 153 tokens << [match, kind]
154 154
155 155 end
156 156 tokens
157 157
158 158 end
159 159
160 160 end
161 161
162 162 end end No newline at end of file
1 NO CONTENT: file renamed from vendor/plugins/coderay-0.9.2/lib/coderay/scanners/xml.rb to vendor/gems/coderay-0.9.7/lib/coderay/scanners/xml.rb
1 NO CONTENT: file renamed from vendor/plugins/coderay-0.9.2/lib/coderay/scanners/yaml.rb to vendor/gems/coderay-0.9.7/lib/coderay/scanners/yaml.rb
1 NO CONTENT: file renamed from vendor/plugins/coderay-0.9.2/lib/coderay/style.rb to vendor/gems/coderay-0.9.7/lib/coderay/style.rb
1 NO CONTENT: file renamed from vendor/plugins/coderay-0.9.2/lib/coderay/styles/_map.rb to vendor/gems/coderay-0.9.7/lib/coderay/styles/_map.rb
@@ -1,151 +1,152
1 1 module CodeRay
2 2 module Styles
3 3
4 4 class Cycnus < Style
5 5
6 6 register_for :cycnus
7 7
8 8 code_background = '#f8f8f8'
9 9 numbers_background = '#def'
10 10 border_color = 'silver'
11 11 normal_color = '#000'
12 12
13 13 CSS_MAIN_STYLES = <<-MAIN
14 14 .CodeRay {
15 15 background-color: #{code_background};
16 16 border: 1px solid #{border_color};
17 17 font-family: 'Courier New', 'Terminal', monospace;
18 18 color: #{normal_color};
19 19 }
20 20 .CodeRay pre { margin: 0px }
21 21
22 22 div.CodeRay { }
23 23
24 24 span.CodeRay { white-space: pre; border: 0px; padding: 2px }
25 25
26 26 table.CodeRay { border-collapse: collapse; width: 100%; padding: 2px }
27 27 table.CodeRay td { padding: 2px 4px; vertical-align: top }
28 28
29 29 .CodeRay .line_numbers, .CodeRay .no {
30 30 background-color: #{numbers_background};
31 31 color: gray;
32 32 text-align: right;
33 33 }
34 34 .CodeRay .line_numbers tt { font-weight: bold }
35 35 .CodeRay .line_numbers .highlighted { color: red }
36 .CodeRay .line { display: block; float: left; width: 100%; }
36 37 .CodeRay .no { padding: 0px 4px }
37 38 .CodeRay .code { width: 100% }
38 39
39 40 ol.CodeRay { font-size: 10pt }
40 41 ol.CodeRay li { white-space: pre }
41 42
42 43 .CodeRay .code pre { overflow: auto }
43 44 MAIN
44 45
45 46 TOKEN_COLORS = <<-'TOKENS'
46 47 .debug { color:white ! important; background:blue ! important; }
47 48
48 49 .af { color:#00C }
49 50 .an { color:#007 }
50 51 .at { color:#f08 }
51 52 .av { color:#700 }
52 53 .aw { color:#C00 }
53 54 .bi { color:#509; font-weight:bold }
54 55 .c { color:#888; }
55 56
56 57 .ch { color:#04D }
57 58 .ch .k { color:#04D }
58 59 .ch .dl { color:#039 }
59 60
60 61 .cl { color:#B06; font-weight:bold }
61 62 .cm { color:#A08; font-weight:bold }
62 63 .co { color:#036; font-weight:bold }
63 64 .cr { color:#0A0 }
64 65 .cv { color:#369 }
65 66 .de { color:#B0B; }
66 67 .df { color:#099; font-weight:bold }
67 68 .di { color:#088; font-weight:bold }
68 69 .dl { color:black }
69 70 .do { color:#970 }
70 71 .dt { color:#34b }
71 72 .ds { color:#D42; font-weight:bold }
72 73 .e { color:#666; font-weight:bold }
73 74 .en { color:#800; font-weight:bold }
74 75 .er { color:#F00; background-color:#FAA }
75 76 .ex { color:#C00; font-weight:bold }
76 77 .fl { color:#60E; font-weight:bold }
77 78 .fu { color:#06B; font-weight:bold }
78 79 .gv { color:#d70; font-weight:bold }
79 80 .hx { color:#058; font-weight:bold }
80 81 .i { color:#00D; font-weight:bold }
81 82 .ic { color:#B44; font-weight:bold }
82 83
83 84 .il { background: #ddd; color: black }
84 85 .il .il { background: #ccc }
85 86 .il .il .il { background: #bbb }
86 87 .il .idl { background: #ddd; font-weight: bold; color: #666 }
87 88 .idl { background-color: #bbb; font-weight: bold; color: #666; }
88 89
89 90 .im { color:#f00; }
90 91 .in { color:#B2B; font-weight:bold }
91 92 .iv { color:#33B }
92 93 .la { color:#970; font-weight:bold }
93 94 .lv { color:#963 }
94 95 .oc { color:#40E; font-weight:bold }
95 96 .of { color:#000; font-weight:bold }
96 97 .op { }
97 98 .pc { color:#038; font-weight:bold }
98 99 .pd { color:#369; font-weight:bold }
99 100 .pp { color:#579; }
100 101 .ps { color:#00C; font-weight:bold }
101 102 .pt { color:#074; font-weight:bold }
102 103 .r, .kw { color:#080; font-weight:bold }
103 104
104 105 .ke { color: #808; }
105 106 .ke .dl { color: #606; }
106 107 .ke .ch { color: #80f; }
107 108 .vl { color: #088; }
108 109
109 110 .rx { background-color:#fff0ff }
110 111 .rx .k { color:#808 }
111 112 .rx .dl { color:#404 }
112 113 .rx .mod { color:#C2C }
113 114 .rx .fu { color:#404; font-weight: bold }
114 115
115 116 .s { background-color:#fff0f0; color: #D20; }
116 117 .s .s { background-color:#ffe0e0 }
117 118 .s .s .s { background-color:#ffd0d0 }
118 119 .s .k { }
119 120 .s .ch { color: #b0b; }
120 121 .s .dl { color: #710; }
121 122
122 123 .sh { background-color:#f0fff0; color:#2B2 }
123 124 .sh .k { }
124 125 .sh .dl { color:#161 }
125 126
126 127 .sy { color:#A60 }
127 128 .sy .k { color:#A60 }
128 129 .sy .dl { color:#630 }
129 130
130 131 .ta { color:#070 }
131 132 .tf { color:#070; font-weight:bold }
132 133 .ts { color:#D70; font-weight:bold }
133 134 .ty { color:#339; font-weight:bold }
134 135 .v { color:#036 }
135 136 .xt { color:#444 }
136 137
137 138 .ins { background: #afa; }
138 139 .del { background: #faa; }
139 140 .chg { color: #aaf; background: #007; }
140 141 .head { color: #f8f; background: #505 }
141 142
142 143 .ins .ins { color: #080; font-weight:bold }
143 144 .del .del { color: #800; font-weight:bold }
144 145 .chg .chg { color: #66f; }
145 146 .head .head { color: #f4f; }
146 147 TOKENS
147 148
148 149 end
149 150
150 151 end
151 152 end
@@ -1,132 +1,134
1 1 module CodeRay
2 2 module Styles
3 3
4 4 class Murphy < Style
5 5
6 6 register_for :murphy
7 7
8 8 code_background = '#001129'
9 9 numbers_background = code_background
10 10 border_color = 'silver'
11 11 normal_color = '#C0C0C0'
12 12
13 13 CSS_MAIN_STYLES = <<-MAIN
14 14 .CodeRay {
15 15 background-color: #{code_background};
16 16 border: 1px solid #{border_color};
17 17 font-family: 'Courier New', 'Terminal', monospace;
18 18 color: #{normal_color};
19 19 }
20 20 .CodeRay pre { margin: 0px; }
21 21
22 22 div.CodeRay { }
23 23
24 24 span.CodeRay { white-space: pre; border: 0px; padding: 2px; }
25 25
26 26 table.CodeRay { border-collapse: collapse; width: 100%; padding: 2px; }
27 27 table.CodeRay td { padding: 2px 4px; vertical-align: top; }
28 28
29 29 .CodeRay .line_numbers, .CodeRay .no {
30 30 background-color: #{numbers_background};
31 31 color: gray;
32 32 text-align: right;
33 33 }
34 34 .CodeRay .line_numbers tt { font-weight: bold; }
35 .CodeRay .line_numbers .highlighted { color: red }
36 .CodeRay .line { display: block; float: left; width: 100%; }
35 37 .CodeRay .no { padding: 0px 4px; }
36 38 .CodeRay .code { width: 100%; }
37 39
38 40 ol.CodeRay { font-size: 10pt; }
39 41 ol.CodeRay li { white-space: pre; }
40 42
41 43 .CodeRay .code pre { overflow: auto; }
42 44 MAIN
43 45
44 46 TOKEN_COLORS = <<-'TOKENS'
45 47 .af { color:#00C; }
46 48 .an { color:#007; }
47 49 .av { color:#700; }
48 50 .aw { color:#C00; }
49 51 .bi { color:#509; font-weight:bold; }
50 52 .c { color:#555; background-color: black; }
51 53
52 54 .ch { color:#88F; }
53 55 .ch .k { color:#04D; }
54 56 .ch .dl { color:#039; }
55 57
56 58 .cl { color:#e9e; font-weight:bold; }
57 59 .co { color:#5ED; font-weight:bold; }
58 60 .cr { color:#0A0; }
59 61 .cv { color:#ccf; }
60 62 .df { color:#099; font-weight:bold; }
61 63 .di { color:#088; font-weight:bold; }
62 64 .dl { color:black; }
63 65 .do { color:#970; }
64 66 .ds { color:#D42; font-weight:bold; }
65 67 .e { color:#666; font-weight:bold; }
66 68 .er { color:#F00; background-color:#FAA; }
67 69 .ex { color:#F00; font-weight:bold; }
68 70 .fl { color:#60E; font-weight:bold; }
69 71 .fu { color:#5ed; font-weight:bold; }
70 72 .gv { color:#f84; }
71 73 .hx { color:#058; font-weight:bold; }
72 74 .i { color:#66f; font-weight:bold; }
73 75 .ic { color:#B44; font-weight:bold; }
74 76 .il { }
75 77 .in { color:#B2B; font-weight:bold; }
76 78 .iv { color:#aaf; }
77 79 .la { color:#970; font-weight:bold; }
78 80 .lv { color:#963; }
79 81 .oc { color:#40E; font-weight:bold; }
80 82 .of { color:#000; font-weight:bold; }
81 83 .op { }
82 84 .pc { color:#08f; font-weight:bold; }
83 85 .pd { color:#369; font-weight:bold; }
84 86 .pp { color:#579; }
85 87 .pt { color:#66f; font-weight:bold; }
86 88 .r { color:#5de; font-weight:bold; }
87 89 .r, .kw { color:#5de; font-weight:bold }
88 90
89 91 .ke { color: #808; }
90 92
91 93 .rx { background-color:#221133; }
92 94 .rx .k { color:#f8f; }
93 95 .rx .dl { color:#f0f; }
94 96 .rx .mod { color:#f0b; }
95 97 .rx .fu { color:#404; font-weight: bold; }
96 98
97 99 .s { background-color:#331122; }
98 100 .s .s { background-color:#ffe0e0; }
99 101 .s .s .s { background-color:#ffd0d0; }
100 102 .s .k { color:#F88; }
101 103 .s .dl { color:#f55; }
102 104
103 105 .sh { background-color:#f0fff0; }
104 106 .sh .k { color:#2B2; }
105 107 .sh .dl { color:#161; }
106 108
107 109 .sy { color:#Fc8; }
108 110 .sy .k { color:#Fc8; }
109 111 .sy .dl { color:#F84; }
110 112
111 113 .ta { color:#070; }
112 114 .tf { color:#070; font-weight:bold; }
113 115 .ts { color:#D70; font-weight:bold; }
114 116 .ty { color:#339; font-weight:bold; }
115 117 .v { color:#036; }
116 118 .xt { color:#444; }
117 119
118 120 .ins { background: #afa; }
119 121 .del { background: #faa; }
120 122 .chg { color: #aaf; background: #007; }
121 123 .head { color: #f8f; background: #505 }
122 124
123 125 .ins .ins { color: #080; font-weight:bold }
124 126 .del .del { color: #800; font-weight:bold }
125 127 .chg .chg { color: #66f; }
126 128 .head .head { color: #f4f; }
127 129 TOKENS
128 130
129 131 end
130 132
131 133 end
132 134 end
1 NO CONTENT: file renamed from vendor/plugins/coderay-0.9.2/lib/coderay/token_classes.rb to vendor/gems/coderay-0.9.7/lib/coderay/token_classes.rb
@@ -1,388 +1,390
1 1 module CodeRay
2 2
3 3 # = Tokens
4 4 #
5 5 # The Tokens class represents a list of tokens returnd from
6 6 # a Scanner.
7 7 #
8 8 # A token is not a special object, just a two-element Array
9 9 # consisting of
10 # * the _token_ _text_ (the original source of the token in a String) or
11 # a _token_ _action_ (:open, :close, :begin_line, :end_line)
10 12 # * the _token_ _kind_ (a Symbol representing the type of the token)
11 # * the _token_ _text_ (the original source of the token in a String)
12 13 #
13 14 # A token looks like this:
14 15 #
15 # [:comment, '# It looks like this']
16 # [:float, '3.1415926']
17 # [:error, '$^']
16 # ['# It looks like this', :comment]
17 # ['3.1415926', :float]
18 # ['$^', :error]
18 19 #
19 # Some scanners also yield some kind of sub-tokens, represented by special
20 # token texts, namely :open and :close .
20 # Some scanners also yield sub-tokens, represented by special
21 # token actions, namely :open and :close.
21 22 #
22 23 # The Ruby scanner, for example, splits "a string" into:
23 24 #
24 25 # [
25 26 # [:open, :string],
26 # [:delimiter, '"'],
27 # [:content, 'a string'],
28 # [:delimiter, '"'],
27 # ['"', :delimiter],
28 # ['a string', :content],
29 # ['"', :delimiter],
29 30 # [:close, :string]
30 31 # ]
31 32 #
32 # Tokens is also the interface between Scanners and Encoders:
33 # Tokens is the interface between Scanners and Encoders:
33 34 # The input is split and saved into a Tokens object. The Encoder
34 35 # then builds the output from this object.
35 36 #
36 37 # Thus, the syntax below becomes clear:
37 38 #
38 39 # CodeRay.scan('price = 2.59', :ruby).html
39 40 # # the Tokens object is here -------^
40 41 #
41 42 # See how small it is? ;)
42 43 #
43 44 # Tokens gives you the power to handle pre-scanned code very easily:
44 45 # You can convert it to a webpage, a YAML file, or dump it into a gzip'ed string
45 46 # that you put in your DB.
47 #
48 # It also allows you to generate tokens directly (without using a scanner),
49 # to load them from a file, and still use any Encoder that CodeRay provides.
46 50 #
47 51 # Tokens' subclass TokenStream allows streaming to save memory.
48 52 class Tokens < Array
49 53
50 54 # The Scanner instance that created the tokens.
51 55 attr_accessor :scanner
52 56
53 57 # Whether the object is a TokenStream.
54 58 #
55 59 # Returns false.
56 60 def stream?
57 61 false
58 62 end
59 63
60 64 # Iterates over all tokens.
61 65 #
62 66 # If a filter is given, only tokens of that kind are yielded.
63 67 def each kind_filter = nil, &block
64 68 unless kind_filter
65 69 super(&block)
66 70 else
67 71 super() do |text, kind|
68 72 next unless kind == kind_filter
69 73 yield text, kind
70 74 end
71 75 end
72 76 end
73 77
74 78 # Iterates over all text tokens.
75 79 # Range tokens like [:open, :string] are left out.
76 80 #
77 81 # Example:
78 82 # tokens.each_text_token { |text, kind| text.replace html_escape(text) }
79 83 def each_text_token
80 84 each do |text, kind|
81 85 next unless text.is_a? ::String
82 86 yield text, kind
83 87 end
84 88 end
85 89
86 90 # Encode the tokens using encoder.
87 91 #
88 92 # encoder can be
89 93 # * a symbol like :html oder :statistic
90 94 # * an Encoder class
91 95 # * an Encoder object
92 96 #
93 97 # options are passed to the encoder.
94 98 def encode encoder, options = {}
95 99 unless encoder.is_a? Encoders::Encoder
96 100 unless encoder.is_a? Class
97 101 encoder_class = Encoders[encoder]
98 102 end
99 103 encoder = encoder_class.new options
100 104 end
101 105 encoder.encode_tokens self, options
102 106 end
103 107
104 108
105 109 # Turn into a string using Encoders::Text.
106 110 #
107 111 # +options+ are passed to the encoder if given.
108 112 def to_s options = {}
109 113 encode :text, options
110 114 end
111 115
112 116 # Redirects unknown methods to encoder calls.
113 117 #
114 118 # For example, if you call +tokens.html+, the HTML encoder
115 119 # is used to highlight the tokens.
116 120 def method_missing meth, options = {}
117 121 Encoders[meth].new(options).encode_tokens self
118 122 end
119 123
120 124 # Returns the tokens compressed by joining consecutive
121 125 # tokens of the same kind.
122 126 #
123 127 # This can not be undone, but should yield the same output
124 128 # in most Encoders. It basically makes the output smaller.
125 129 #
126 130 # Combined with dump, it saves space for the cost of time.
127 131 #
128 132 # If the scanner is written carefully, this is not required -
129 133 # for example, consecutive //-comment lines could already be
130 134 # joined in one comment token by the Scanner.
131 135 def optimize
132 136 last_kind = last_text = nil
133 137 new = self.class.new
134 138 for text, kind in self
135 139 if text.is_a? String
136 140 if kind == last_kind
137 141 last_text << text
138 142 else
139 143 new << [last_text, last_kind] if last_kind
140 144 last_text = text
141 145 last_kind = kind
142 146 end
143 147 else
144 148 new << [last_text, last_kind] if last_kind
145 149 last_kind = last_text = nil
146 150 new << [text, kind]
147 151 end
148 152 end
149 153 new << [last_text, last_kind] if last_kind
150 154 new
151 155 end
152 156
153 157 # Compact the object itself; see optimize.
154 158 def optimize!
155 159 replace optimize
156 160 end
157 161
158 162 # Ensure that all :open tokens have a correspondent :close one.
159 163 #
160 164 # TODO: Test this!
161 165 def fix
162 166 tokens = self.class.new
163 167 # Check token nesting using a stack of kinds.
164 168 opened = []
165 169 for type, kind in self
166 170 case type
167 171 when :open
168 172 opened.push [:close, kind]
169 173 when :begin_line
170 174 opened.push [:end_line, kind]
171 175 when :close, :end_line
172 176 expected = opened.pop
173 177 if [type, kind] != expected
174 178 # Unexpected :close; decide what to do based on the kind:
175 179 # - token was never opened: delete the :close (just skip it)
176 180 next unless opened.rindex expected
177 181 # - token was opened earlier: also close tokens in between
178 182 tokens << token until (token = opened.pop) == expected
179 183 end
180 184 end
181 185 tokens << [type, kind]
182 186 end
183 187 # Close remaining opened tokens
184 188 tokens << token while token = opened.pop
185 189 tokens
186 190 end
187 191
188 192 def fix!
189 193 replace fix
190 194 end
191 195
192 196 # TODO: Scanner#split_into_lines
193 197 #
194 198 # Makes sure that:
195 199 # - newlines are single tokens
196 200 # (which means all other token are single-line)
197 201 # - there are no open tokens at the end the line
198 202 #
199 203 # This makes it simple for encoders that work line-oriented,
200 204 # like HTML with list-style numeration.
201 205 def split_into_lines
202 206 raise NotImplementedError
203 207 end
204 208
205 209 def split_into_lines!
206 210 replace split_into_lines
207 211 end
208 212
209 213 # Dumps the object into a String that can be saved
210 214 # in files or databases.
211 215 #
212 216 # The dump is created with Marshal.dump;
213 217 # In addition, it is gzipped using GZip.gzip.
214 218 #
215 219 # The returned String object includes Undumping
216 220 # so it has an #undump method. See Tokens.load.
217 221 #
218 222 # You can configure the level of compression,
219 223 # but the default value 7 should be what you want
220 224 # in most cases as it is a good compromise between
221 225 # speed and compression rate.
222 226 #
223 227 # See GZip module.
224 228 def dump gzip_level = 7
225 229 require 'coderay/helpers/gzip_simple'
226 230 dump = Marshal.dump self
227 231 dump = dump.gzip gzip_level
228 232 dump.extend Undumping
229 233 end
230 234
231 235 # The total size of the tokens.
232 236 # Should be equal to the input size before
233 237 # scanning.
234 238 def text_size
235 239 size = 0
236 240 each_text_token do |t, k|
237 241 size + t.size
238 242 end
239 243 size
240 244 end
241 245
242 # The total size of the tokens.
243 # Should be equal to the input size before
244 # scanning.
246 # Return all text tokens joined into a single string.
245 247 def text
246 248 map { |t, k| t if t.is_a? ::String }.join
247 249 end
248 250
249 251 # Include this module to give an object an #undump
250 252 # method.
251 253 #
252 254 # The string returned by Tokens.dump includes Undumping.
253 255 module Undumping
254 256 # Calls Tokens.load with itself.
255 257 def undump
256 258 Tokens.load self
257 259 end
258 260 end
259 261
260 262 # Undump the object using Marshal.load, then
261 263 # unzip it using GZip.gunzip.
262 264 #
263 265 # The result is commonly a Tokens object, but
264 266 # this is not guaranteed.
265 267 def Tokens.load dump
266 268 require 'coderay/helpers/gzip_simple'
267 269 dump = dump.gunzip
268 270 @dump = Marshal.load dump
269 271 end
270 272
271 273 end
272 274
273 275
274 276 # = TokenStream
275 277 #
276 278 # The TokenStream class is a fake Array without elements.
277 279 #
278 280 # It redirects the method << to a block given at creation.
279 281 #
280 282 # This allows scanners and Encoders to use streaming (no
281 283 # tokens are saved, the input is highlighted the same time it
282 284 # is scanned) with the same code.
283 285 #
284 286 # See CodeRay.encode_stream and CodeRay.scan_stream
285 287 class TokenStream < Tokens
286 288
287 289 # Whether the object is a TokenStream.
288 290 #
289 291 # Returns true.
290 292 def stream?
291 293 true
292 294 end
293 295
294 296 # The Array is empty, but size counts the tokens given by <<.
295 297 attr_reader :size
296 298
297 299 # Creates a new TokenStream that calls +block+ whenever
298 300 # its << method is called.
299 301 #
300 302 # Example:
301 303 #
302 304 # require 'coderay'
303 305 #
304 # token_stream = CodeRay::TokenStream.new do |kind, text|
306 # token_stream = CodeRay::TokenStream.new do |text, kind|
305 307 # puts 'kind: %s, text size: %d.' % [kind, text.size]
306 308 # end
307 309 #
308 # token_stream << [:regexp, '/\d+/']
310 # token_stream << ['/\d+/', :regexp]
309 311 # #-> kind: rexpexp, text size: 5.
310 312 #
311 313 def initialize &block
312 314 raise ArgumentError, 'Block expected for streaming.' unless block
313 315 @callback = block
314 316 @size = 0
315 317 end
316 318
317 319 # Calls +block+ with +token+ and increments size.
318 320 #
319 321 # Returns self.
320 322 def << token
321 323 @callback.call(*token)
322 324 @size += 1
323 325 self
324 326 end
325 327
326 328 # This method is not implemented due to speed reasons. Use Tokens.
327 329 def text_size
328 330 raise NotImplementedError,
329 331 'This method is not implemented due to speed reasons.'
330 332 end
331 333
332 334 # A TokenStream cannot be dumped. Use Tokens.
333 335 def dump
334 336 raise NotImplementedError, 'A TokenStream cannot be dumped.'
335 337 end
336 338
337 339 # A TokenStream cannot be optimized. Use Tokens.
338 340 def optimize
339 341 raise NotImplementedError, 'A TokenStream cannot be optimized.'
340 342 end
341 343
342 344 end
343 345
344 346 end
345 347
346 348 if $0 == __FILE__
347 349 $VERBOSE = true
348 350 $: << File.join(File.dirname(__FILE__), '..')
349 351 eval DATA.read, nil, $0, __LINE__ + 4
350 352 end
351 353
352 354 __END__
353 355 require 'test/unit'
354 356
355 357 class TokensTest < Test::Unit::TestCase
356 358
357 359 def test_creation
358 360 assert CodeRay::Tokens < Array
359 361 tokens = nil
360 362 assert_nothing_raised do
361 363 tokens = CodeRay::Tokens.new
362 364 end
363 365 assert_kind_of Array, tokens
364 366 end
365 367
366 368 def test_adding_tokens
367 369 tokens = CodeRay::Tokens.new
368 370 assert_nothing_raised do
369 371 tokens << ['string', :type]
370 372 tokens << ['()', :operator]
371 373 end
372 374 assert_equal tokens.size, 2
373 375 end
374 376
375 377 def test_dump_undump
376 378 tokens = CodeRay::Tokens.new
377 379 assert_nothing_raised do
378 380 tokens << ['string', :type]
379 381 tokens << ['()', :operator]
380 382 end
381 383 tokens2 = nil
382 384 assert_nothing_raised do
383 385 tokens2 = tokens.dump.undump
384 386 end
385 387 assert_equal tokens, tokens2
386 388 end
387 389
388 390 end No newline at end of file
General Comments 0
You need to be logged in to leave comments. Login now