coderay 0.7.4.196 → 0.7.4.215

Sign up to get free protection for your applications and to get access to all the features.
data/README CHANGED
@@ -18,13 +18,12 @@ And with line numbers.
18
18
  * is what everybody should have on their website
19
19
  * solves all your problems and makes the girls run after you
20
20
 
21
- Version: 0.7.2 (2006.july.11)
21
+ Version: 0.7.4 (2006.october.20)
22
22
  Author:: murphy (Kornelius Kalnbach)
23
23
  Contact:: murphy rubychan de
24
24
  Website:: coderay.rubychan.de[http://coderay.rubychan.de]
25
- Old Website:: rd.cYcnus.de/coderay[http://rd.cYcnus.de/coderay]
26
25
  License:: GNU LGPL; see LICENSE file in the main directory.
27
- Subversion:: $Id: README 195 2006-10-18 10:32:41Z murphy $
26
+ Subversion:: $Id: README 206 2006-10-19 19:46:56Z murphy $
28
27
 
29
28
  -----
30
29
 
@@ -42,7 +41,7 @@ Since CodeRay is still in beta stage, nightly buildy may be useful:
42
41
  === Dependencies
43
42
 
44
43
  CodeRay needs Ruby 1.8 and the strscan[http://www.ruby-doc.org/stdlib/libdoc/strscan/rdoc/index.htm] library
45
- (part of the standard library.)
44
+ (part of the standard library.) It should also run with Ruby 1.9 and yarv.
46
45
 
47
46
 
48
47
  == Example Usage
@@ -13,7 +13,7 @@ begin
13
13
 
14
14
  if ARGV.empty?
15
15
  puts <<-USAGE
16
- CodeRay #{CodeRay::Version} (http://rd.cYcnus.de/coderay)
16
+ CodeRay #{CodeRay::VERSION} (http://rd.cYcnus.de/coderay)
17
17
  Usage:
18
18
  coderay -<lang> [-<format>] < file > output
19
19
  coderay file [-<format>]
@@ -72,6 +72,6 @@ rescue => boom
72
72
  err "Error: #{boom.message}\n"
73
73
  err boom.backtrace
74
74
  err '-' * 50
75
- err ARGV.options
75
+ err ARGV
76
76
  exit 1
77
77
  end
@@ -1,6 +1,6 @@
1
1
  # = CodeRay Library
2
2
  #
3
- # $Id: coderay.rb 188 2006-10-17 11:18:01Z murphy $
3
+ # $Id: coderay.rb 213 2006-10-20 07:12:31Z murphy $
4
4
  #
5
5
  # CodeRay is a Ruby library for syntax highlighting.
6
6
  #
@@ -170,7 +170,7 @@ module CodeRay
170
170
  def scan_file filename, lang = :auto, options = {}, &block
171
171
  file = IO.read filename
172
172
  if lang == :auto
173
- require 'coderay/helpers/filetype'
173
+ require 'coderay/helpers/file_type'
174
174
  lang = FileType.fetch filename, :plaintext, true
175
175
  end
176
176
  scan file, lang, options = {}, &block
@@ -1,3 +1,5 @@
1
+ require "set"
2
+
1
3
  module CodeRay
2
4
  module Encoders
3
5
 
@@ -10,7 +12,8 @@ module Encoders
10
12
  #
11
13
  # require 'coderay'
12
14
  # puts CodeRay.scan('Some /code/', :ruby).html #-> a HTML page
13
- # puts CodeRay.scan('Some /code/', :ruby).html(:wrap => :span) #-> <span class="CodeRay"><span class="co">Some</span> /code/</span>
15
+ # puts CodeRay.scan('Some /code/', :ruby).html(:wrap => :span)
16
+ # #-> <span class="CodeRay"><span class="co">Some</span> /code/</span>
14
17
  # puts CodeRay.scan('Some /code/', :ruby).span #-> the same
15
18
  #
16
19
  # puts CodeRay.scan('Some code', :ruby).html(
@@ -55,7 +58,8 @@ module Encoders
55
58
  #
56
59
  # === :hint
57
60
  # Include some information into the output using the title attribute.
58
- # Can be :info (show token type on mouse-over), :info_long (with full path) or :debug (via inspect).
61
+ # Can be :info (show token type on mouse-over), :info_long (with full path)
62
+ # or :debug (via inspect).
59
63
  #
60
64
  # Default: false
61
65
  class HTML < Encoder
@@ -115,6 +119,10 @@ module Encoders
115
119
  end
116
120
  }
117
121
 
122
+ TRANSPARENT_TOKEN_KINDS = Set[
123
+ :delimiter, :modifier, :content, :escape, :inline_delimiter,
124
+ ]
125
+
118
126
  # Generate a hint about the given +classes+ in a +hint+ style.
119
127
  #
120
128
  # +hint+ may be :info, :info_long or :debug.
@@ -143,7 +151,8 @@ module Encoders
143
151
 
144
152
  hint = options[:hint]
145
153
  if hint and not [:debug, :info, :info_long].include? hint
146
- raise ArgumentError, "Unknown value %p for :hint; expected :info, :debug, false or nil." % hint
154
+ raise ArgumentError, "Unknown value %p for :hint; \
155
+ expected :info, :debug, false, or nil." % hint
147
156
  end
148
157
 
149
158
  case options[:css]
@@ -176,9 +185,8 @@ module Encoders
176
185
  if classes.first == :NO_HIGHLIGHT and not hint
177
186
  h[k] = false
178
187
  else
179
- styles.shift if [:delimiter, :modifier, :content, :escape].include? styles.first
188
+ styles.shift if TRANSPARENT_TOKEN_KINDS.include? styles.first
180
189
  title = HTML.token_path_to_hint hint, styles
181
- classes.delete 'il'
182
190
  style = @css[*classes]
183
191
  h[k] =
184
192
  if style
@@ -198,7 +206,9 @@ module Encoders
198
206
  def finish options
199
207
  not_needed = @opened.shift
200
208
  @out << '</span>' * @opened.size
201
- warn '%d tokens still open: %p' % [@opened.size, @opened] unless @opened.empty?
209
+ unless @opened.empty?
210
+ warn '%d tokens still open: %p' % [@opened.size, @opened]
211
+ end
202
212
 
203
213
  @out.extend Output
204
214
  @out.css = @css
@@ -229,8 +239,9 @@ module Encoders
229
239
  if @opened.empty?
230
240
  # nothing to close
231
241
  else
232
- if @opened.size == 1 or @opened.last != type
233
- raise 'Malformed token stream: Trying to close a token (%p) that is not open. Open are: %p.' % [type, @opened[1..-1]] if $DEBUG
242
+ if $DEBUG and (@opened.size == 1 or @opened.last != type)
243
+ raise 'Malformed token stream: Trying to close a token (%p) \
244
+ that is not open. Open are: %p.' % [type, @opened[1..-1]]
234
245
  end
235
246
  @out << '</span>'
236
247
  @opened.pop
@@ -34,6 +34,7 @@ module Encoders
34
34
  :hex => 'hx',
35
35
  :include => 'ic',
36
36
  :inline => 'il',
37
+ :inline_delimiter => 'idl',
37
38
  :instance_variable => 'iv',
38
39
  :integer => 'i',
39
40
  :interpreted => 'in',
@@ -1,10 +1,11 @@
1
- # =FileType
1
+ # = FileType
2
2
  #
3
- # A simple filetype recognizer
3
+ # A simple filetype recognizer.
4
4
  #
5
- # Author: murphy (mail to murphy cYcnus de)
5
+ # Copyright (c) 2006 by murphy (Kornelius Kalnbach) <murphy rubychan de>
6
6
  #
7
- # Version: 0.1 (2005.september.1)
7
+ # License:: LGPL / ask the author
8
+ # Version:: 0.1 (2005-09-01)
8
9
  #
9
10
  # == Documentation
10
11
  #
@@ -84,6 +85,7 @@ module FileType
84
85
  'htm' => :html,
85
86
  'html' => :html,
86
87
  'xhtml' => :xhtml,
88
+ 'raydebug' => :debug,
87
89
  'rhtml' => :rhtml,
88
90
  'yaml' => :yaml,
89
91
  'yml' => :yaml,
@@ -1,15 +1,17 @@
1
1
  # = WordList
2
- #
3
- # Copyright (c) 2006 by murphy (Kornelius Kalnbach) <murphy cYcnus de>
2
+ #
3
+ # <b>A Hash subclass designed for mapping word lists to token types.</b>
4
+ #
5
+ # Copyright (c) 2006 by murphy (Kornelius Kalnbach) <murphy rubychan de>
4
6
  #
5
7
  # License:: LGPL / ask the author
6
- # Version:: 1.0 (2006-Feb-3)
8
+ # Version:: 1.1 (2006-Oct-19)
7
9
  #
8
10
  # A WordList is a Hash with some additional features.
9
11
  # It is intended to be used for keyword recognition.
10
12
  #
11
13
  # WordList is highly optimized to be used in Scanners,
12
- # typically to decide whether a given ident is a keyword.
14
+ # typically to decide whether a given ident is a special token.
13
15
  #
14
16
  # For case insensitive words use CaseIgnoringWordList.
15
17
  #
@@ -47,25 +49,30 @@
47
49
  # ...
48
50
  class WordList < Hash
49
51
 
50
- # Create a WordList for the given +words+.
51
- #
52
- # This WordList responds to [] with +true+, if the word is
53
- # in +words+, and with +false+ otherwise.
54
- def self.for words
55
- new.add words
56
- end
57
-
58
52
  # Creates a new WordList with +default+ as default value.
59
- def initialize default = false, &block
60
- super default, &block
61
- end
62
-
63
- # Checks if a word is included.
64
- def include? word
65
- has_key? word
53
+ #
54
+ # You can activate +caching+ to store the results for every [] request.
55
+ #
56
+ # With caching, methods like +include?+ or +delete+ may no longer behave
57
+ # as you expect. Therefore, it is recommended to use the [] method only.
58
+ def initialize default = false, caching = false, &block
59
+ if block
60
+ raise ArgumentError, 'Can\'t combine block with caching.' if caching
61
+ super(&block)
62
+ else
63
+ if caching
64
+ super() do |h, k|
65
+ h[k] = h.fetch k, default
66
+ end
67
+ else
68
+ super default
69
+ end
70
+ end
66
71
  end
67
72
 
68
73
  # Add words to the list and associate them with +kind+.
74
+ #
75
+ # Returns +self+, so you can concat add calls.
69
76
  def add words, kind = true
70
77
  words.each do |word|
71
78
  self[word] = kind
@@ -78,24 +85,30 @@ end
78
85
 
79
86
  # A CaseIgnoringWordList is like a WordList, only that
80
87
  # keys are compared case-insensitively.
88
+ #
89
+ # Ignoring the text case is realized by sending the +downcase+ message to
90
+ # all keys.
91
+ #
92
+ # Caching usually makes a CaseIgnoringWordList faster, but it has to be
93
+ # activated explicitely.
81
94
  class CaseIgnoringWordList < WordList
82
95
 
83
- # Creates a new WordList with +default+ as default value.
84
- #
85
- # Text case is ignored.
86
- def initialize default = false, &block
87
- block ||= proc do |h, k|
88
- h[k] = h.fetch k.downcase, default
96
+ # Creates a new case-insensitive WordList with +default+ as default value.
97
+ #
98
+ # You can activate caching to store the results for every [] request.
99
+ def initialize default = false, caching = false
100
+ if caching
101
+ super(default, false) do |h, k|
102
+ h[k] = h.fetch k.downcase, default
103
+ end
104
+ else
105
+ def self.[] key # :nodoc:
106
+ super(key.downcase)
107
+ end
89
108
  end
90
- super default
91
109
  end
92
110
 
93
- # Checks if a word is included.
94
- def include? word
95
- has_key? word.downcase
96
- end
97
-
98
- # Add words to the list and associate them with +kind+.
111
+ # Add +words+ to the list and associate them with +kind+.
99
112
  def add words, kind = true
100
113
  words.each do |word|
101
114
  self[word.downcase] = kind
@@ -0,0 +1,60 @@
1
+ module CodeRay
2
+ module Scanners
3
+
4
+ # = Debug Scanner
5
+ class Debug < Scanner
6
+
7
+ include Streamable
8
+ register_for :debug
9
+
10
+ protected
11
+ def scan_tokens tokens, options
12
+
13
+ opened_tokens = []
14
+
15
+ until eos?
16
+
17
+ kind = nil
18
+ match = nil
19
+
20
+ if scan(/\s+/)
21
+ tokens << [matched, :space]
22
+ next
23
+
24
+ elsif scan(/ (\w+) \( ( [^\)\\]* ( \\. [^\)\\]* )* ) \) /x)
25
+ kind = self[1].to_sym
26
+ match = self[2].gsub(/\\(.)/, '\1')
27
+
28
+ elsif scan(/ (\w+) < /x)
29
+ kind = self[1].to_sym
30
+ opened_tokens << kind
31
+ match = :open
32
+
33
+ elsif scan(/ > /x)
34
+ kind = opened_tokens.pop
35
+ match = :close
36
+
37
+ else
38
+ kind = :error
39
+ getch
40
+
41
+ end
42
+
43
+ match ||= matched
44
+ if $DEBUG and not kind
45
+ raise_inspect 'Error token %p in line %d' %
46
+ [[match, kind], line], tokens
47
+ end
48
+ raise_inspect 'Empty token', tokens unless match
49
+
50
+ tokens << [match, kind]
51
+
52
+ end
53
+
54
+ tokens
55
+ end
56
+
57
+ end
58
+
59
+ end
60
+ end
@@ -29,13 +29,18 @@ module Scanners
29
29
  'virtual', 'write', 'writeonly'
30
30
  ]
31
31
 
32
- IDENT_KIND = CaseIgnoringWordList.new(:ident).
32
+ IDENT_KIND = CaseIgnoringWordList.new(:ident, caching=true).
33
33
  add(RESERVED_WORDS, :reserved).
34
34
  add(DIRECTIVES, :directive)
35
+
36
+ NAME_FOLLOWS = CaseIgnoringWordList.new(false, caching=true).
37
+ add(%w(procedure function .))
35
38
 
39
+ private
36
40
  def scan_tokens tokens, options
37
41
 
38
42
  state = :initial
43
+ last_token = ''
39
44
 
40
45
  until eos?
41
46
 
@@ -45,19 +50,29 @@ module Scanners
45
50
  if state == :initial
46
51
 
47
52
  if scan(/ \s+ /x)
48
- kind = :space
53
+ tokens << [matched, :space]
54
+ next
49
55
 
50
56
  elsif scan(%r! \{ \$ [^}]* \}? | \(\* \$ (?: .*? \*\) | .* ) !mx)
51
- kind = :preprocessor
57
+ tokens << [matched, :preprocessor]
58
+ next
52
59
 
53
60
  elsif scan(%r! // [^\n]* | \{ [^}]* \}? | \(\* (?: .*? \*\) | .* ) !mx)
54
- kind = :comment
61
+ tokens << [matched, :comment]
62
+ next
55
63
 
56
- elsif scan(/ [-+*\/=<>:;,.@\^|\(\)\[\]]+ /x)
64
+ elsif match = scan(/ <[>=]? | >=? | :=? | [-+=*\/;,@\^|\(\)\[\]] | \.\. /x)
57
65
  kind = :operator
66
+
67
+ elsif match = scan(/\./)
68
+ kind = :operator
69
+ if last_token == 'end'
70
+ tokens << [match, kind]
71
+ next
72
+ end
58
73
 
59
74
  elsif match = scan(/ [A-Za-z_][A-Za-z_0-9]* /x)
60
- kind = IDENT_KIND[match]
75
+ kind = NAME_FOLLOWS[last_token] ? :ident : IDENT_KIND[match]
61
76
 
62
77
  elsif match = scan(/ ' ( [^\n']|'' ) (?:'|$) /x)
63
78
  tokens << [:open, :char]
@@ -101,6 +116,7 @@ module Scanners
101
116
  state = :initial
102
117
  next
103
118
  elsif scan(/\n/)
119
+ tokens << [:close, :string]
104
120
  kind = :error
105
121
  state = :initial
106
122
  else
@@ -119,6 +135,7 @@ module Scanners
119
135
  end
120
136
  raise_inspect 'Empty token', tokens unless match
121
137
 
138
+ last_token = match
122
139
  tokens << [match, kind]
123
140
 
124
141
  end
@@ -97,7 +97,7 @@ module Scanners
97
97
  state = :initial
98
98
  depth = 1
99
99
  tokens << [:open, :inline]
100
- tokens << [match + getch, :delimiter]
100
+ tokens << [match + getch, :inline_delimiter]
101
101
  when ?$, ?@
102
102
  tokens << [match, :escape]
103
103
  last_state = state # scan one token as normal code, then return here
@@ -189,7 +189,7 @@ module Scanners
189
189
  depth -= 1
190
190
  if depth == 0 # closing brace of inline block reached
191
191
  state, depth, heredocs = inline_block_stack.pop
192
- tokens << [match, :delimiter]
192
+ tokens << [match, :inline_delimiter]
193
193
  kind = :inline
194
194
  match = :close
195
195
  end
@@ -76,7 +76,7 @@ ol.CodeRay li { white-space: pre }
76
76
  .il { background: #eee }
77
77
  .il .il { background: #ddd }
78
78
  .il .il .il { background: #ccc }
79
- .il .dl { font-weight: bold ! important; color: #888 ! important }
79
+ .il .idl { font-weight: bold; color: #888 }
80
80
 
81
81
  .in { color:#B2B; font-weight:bold }
82
82
  .iv { color:#33B }
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.0
3
3
  specification_version: 1
4
4
  name: coderay
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.7.4.196
7
- date: 2006-10-18 00:00:00 +02:00
6
+ version: 0.7.4.215
7
+ date: 2006-10-20 00:00:00 +02:00
8
8
  summary: CodeRay is a fast syntax highlighter engine for many languages.
9
9
  require_paths:
10
10
  - lib
@@ -52,12 +52,13 @@ files:
52
52
  - ./lib/coderay/encoders/html/css.rb
53
53
  - ./lib/coderay/encoders/html/numerization.rb
54
54
  - ./lib/coderay/encoders/html/output.rb
55
- - ./lib/coderay/helpers/filetype.rb
55
+ - ./lib/coderay/helpers/file_type.rb
56
56
  - ./lib/coderay/helpers/gzip_simple.rb
57
57
  - ./lib/coderay/helpers/plugin.rb
58
58
  - ./lib/coderay/helpers/word_list.rb
59
59
  - ./lib/coderay/scanners/_map.rb
60
60
  - ./lib/coderay/scanners/c.rb
61
+ - ./lib/coderay/scanners/debug.rb
61
62
  - ./lib/coderay/scanners/delphi.rb
62
63
  - ./lib/coderay/scanners/html.rb
63
64
  - ./lib/coderay/scanners/nitro_xhtml.rb