coderay 1.0.0.778.pre → 1.0.0.788.pre

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/bin/coderay CHANGED
@@ -1,99 +1,156 @@
1
1
  #!/usr/bin/env ruby
2
- # CodeRay Executable
3
- #
4
- # Version: 0.2
5
- # Author: murphy
2
+ require 'coderay'
6
3
 
7
- def err msg
8
- $stderr.puts msg
4
+ $options, args = ARGV.partition { |arg| arg[/^-[hv]$|--\w+/] }
5
+ subcommand = args.detect { |arg| arg[/^\w/] }
6
+ subcommand = nil if subcommand && File.exist?(subcommand)
7
+ args.delete subcommand
8
+
9
+ def option? *options
10
+ !($options & options).empty?
9
11
  end
10
12
 
11
- def read
12
- if file = ARGV[2]
13
- File.read file
14
- else
15
- $stdin.read
16
- end
13
+ def tty?
14
+ $stdout.tty? || option?('--tty')
17
15
  end
18
16
 
19
- begin
20
- require 'coderay'
17
+ def version
18
+ puts <<-USAGE
19
+ CodeRay #{CodeRay::VERSION}
20
+ USAGE
21
+ end
21
22
 
22
- if ARGV.empty?
23
- puts <<-USAGE
24
- CodeRay #{CodeRay::VERSION} (http://coderay.rubychan.de)
23
+ def help
24
+ puts <<-HELP
25
+ This is CodeRay #{CodeRay::VERSION}, a syntax highlighting tool for selected languages.
25
26
 
26
- Usage:
27
- coderay -<lang> [-<format>] < file > output
28
- coderay file [-<format>]
27
+ usage:
28
+ coderay [-language] [input] [-format] [output]
29
+
30
+ defaults:
31
+ language detect from input file name or shebang; fall back to plain text
32
+ input STDIN
33
+ format detect from output file name or use terminal; fall back to HTML page
34
+ output STDOUT
29
35
 
30
- Examples:
31
- coderay -ruby -statistic < foo.rb
32
- coderay -ruby < foo.rb # colorized output to terminal
33
- coderay -ruby -page foo.rb # HTML page output to terminal
34
- coderay -ruby -page foo.rb > foo.html # HTML page output to file
35
- coderay codegen.c # generates codegen.c.html
36
- USAGE
37
- end
36
+ common:
37
+ coderay file.rb # highlight file to terminal
38
+ coderay file.rb > file.html # highlight file to HTML page
39
+ coderay file.rb -div > file.html # highlight file to HTML snippet
40
+
41
+ configure output:
42
+ coderay file.py output.json # output tokens as JSON
43
+ coderay file.py -loc # count lines of code in Python file
44
+
45
+ configure input:
46
+ coderay -python file # specify the input language
47
+ coderay -ruby # take input from STDIN
38
48
 
39
- first, second = ARGV
49
+ more:
50
+ coderay stylesheet [style] # print CSS stylesheet
51
+ HELP
52
+ end
53
+
54
+ def commands
55
+ puts <<-COMMANDS
56
+ general:
57
+ highlight code highlighting (default command)
58
+ stylesheet print the CSS stylesheet with the given name
59
+
60
+ about:
61
+ list [of] list all available plugins (or just the scanners|encoders)
62
+ commands print this list
63
+ help show some help
64
+ version print CodeRay version
65
+ COMMANDS
66
+ end
67
+
68
+ if option? '-v', '--version'
69
+ version
70
+ end
71
+
72
+ if option? '-h', '--help'
73
+ help
74
+ end
40
75
 
41
- if first
42
- if first[/-(\w+)/] == first
43
- lang = $1
44
- input = read
45
- tokens = :scan
46
- elsif first == '-'
47
- lang = $1
48
- input = read
49
- tokens = :scan
76
+ case subcommand
77
+ when 'highlight', nil
78
+ if ARGV.empty?
79
+ version
80
+ help
81
+ else
82
+ signature = args.map { |arg| arg[/^-/] ? '-' : 'f' }.join
83
+ names = args.map { |arg| arg.sub(/^-/, '') }
84
+ case signature
85
+ when /^$/
86
+ exit
87
+ when /^ff?$/
88
+ input_file, output_file, = *names
89
+ when /^f-f?$/
90
+ input_file, output_filetype, output_file, = *names
91
+ when /^-ff?$/
92
+ input_filetype, input_file, output_file, = *names
93
+ when /^-f-f?$/
94
+ input_filetype, input_file, output_filetype, output_file, = *names
95
+ when /^--?f?$/
96
+ input_filetype, output_filetype, output_file, = *names
50
97
  else
51
- file = first
52
- tokens = CodeRay.scan_file file
53
- output_filename, output_ext = file, /#{Regexp.escape(File.extname(file))}$/
98
+ raise signature
54
99
  end
55
- else
56
- puts 'No lang/file given.'
57
- exit 1
58
- end
59
-
60
- if second
61
- if second[/-(\w+)/] == second
62
- format = $1
100
+
101
+ if input_file
102
+ input_filetype ||= CodeRay::FileType.fetch input_file, :text, true
103
+ end
104
+
105
+ if output_file
106
+ output_filetype ||= CodeRay::FileType[output_file]
63
107
  else
64
- raise 'invalid format (must be -xxx)'
108
+ output_filetype ||= tty? ? :term : :page
65
109
  end
66
- else
67
- if $stdout.tty?
68
- format = :term
110
+
111
+ if input_file
112
+ input = File.read input_file
69
113
  else
70
- $stderr.puts 'No format given; setting to default (HTML Page).'
71
- format = :page
114
+ input = $stdin.read
115
+ end
116
+
117
+ output = CodeRay.scan(input, input_filetype).encode(output_filetype)
118
+
119
+ if output_file
120
+ File.open output_file, 'w' do |file|
121
+ file.puts output
122
+ end
123
+ else
124
+ puts output
72
125
  end
73
126
  end
74
-
75
- if tokens == :scan
76
- output = CodeRay.encoder(format).encode(input, lang)
77
- else
78
- output = tokens.encode format
127
+ when 'list'
128
+ arg = args.first && args.first.downcase
129
+ if [nil, 's', 'sc', 'scanner', 'scanners'].include? arg
130
+ puts 'input languages (Scanners):'
131
+ scanners = CodeRay::Scanners.all_plugins.map do |plugin|
132
+ aliases = (plugin.aliases - [nil]).map { |key| "-#{key}" }.sort_by { |key| key.size }
133
+ " #{plugin.lang}: #{plugin.title}#{" (.#{plugin.file_extension}; #{aliases.join(', ')})" unless aliases.empty?}"
134
+ end
135
+ puts scanners.sort
136
+ puts
79
137
  end
80
- out = $stdout
81
- if output_filename
82
- output_filename += '.' + CodeRay::Encoders[format]::FILE_EXTENSION.to_s
83
- if File.exist? output_filename
84
- err 'File %s already exists.' % output_filename
85
- exit
86
- else
87
- out = File.open output_filename, 'w'
88
- puts "Writing to #{output_filename}..."
138
+
139
+ if [nil, 'e', 'en', 'enc', 'encoder', 'encoders'].include? arg
140
+ puts 'output formats (Encoders):'
141
+ encoders = CodeRay::Encoders.all_plugins.map do |plugin|
142
+ aliases = (plugin.aliases - [nil]).map { |key| "-#{key}" }.sort_by { |key| key.size }
143
+ " #{plugin.plugin_id}: #{plugin.title}#{" (.#{plugin.file_extension}; #{aliases.join(', ')})" unless aliases.empty?}"
89
144
  end
145
+ puts encoders.sort
90
146
  end
91
- out.puts output
92
-
93
- rescue => boom
94
- err "Error: #{boom.message}\n"
95
- err boom.backtrace
96
- err '-' * 50
97
- err ARGV
98
- exit 1
147
+ when 'stylesheet'
148
+ puts CodeRay::Encoders[:html]::CSS.new(args.first).stylesheet
149
+ when 'commands'
150
+ commands
151
+ when 'help'
152
+ help
153
+ else
154
+ puts "Unknown command: #{subcommand}"
155
+ help
99
156
  end
data/lib/coderay.rb CHANGED
@@ -134,6 +134,9 @@ module CodeRay
134
134
  # Revision: Subversion Revision number (generated on rake gem:make)
135
135
  VERSION = '1.0.0'
136
136
 
137
+ # helpers
138
+ autoload :FileType, 'coderay/helpers/file_type'
139
+
137
140
  # Tokens
138
141
  autoload :Tokens, 'coderay/tokens'
139
142
  autoload :TokenKinds, 'coderay/token_kinds'
@@ -178,7 +181,6 @@ module CodeRay
178
181
  def scan_file filename, lang = :auto, options = {}, &block
179
182
  file = IO.read filename
180
183
  if lang == :auto
181
- require 'coderay/helpers/file_type'
182
184
  lang = FileType.fetch filename, :text, true
183
185
  end
184
186
  scan file, lang, options = {}, &block
@@ -34,12 +34,17 @@ module CodeRay
34
34
  # downcase class name instead.
35
35
  def const_missing sym
36
36
  if sym == :FILE_EXTENSION
37
- plugin_id.to_s
37
+ (@plugin_id || name[/\w+$/].downcase).to_s
38
38
  else
39
39
  super
40
40
  end
41
41
  end
42
42
 
43
+ # The default file extension for output file of this encoder class.
44
+ def file_extension
45
+ self::FILE_EXTENSION
46
+ end
47
+
43
48
  end
44
49
 
45
50
  # Subclasses are to store their default options in this constant.
@@ -85,9 +90,9 @@ module CodeRay
85
90
  # more clear to you.
86
91
  alias highlight encode
87
92
 
88
- # Return the default file extension for outputs of this encoder.
93
+ # The default file extension for this encoder.
89
94
  def file_extension
90
- self.class::FILE_EXTENSION
95
+ self.class.file_extension
91
96
  end
92
97
 
93
98
  def << token
@@ -8,8 +8,7 @@ module Encoders
8
8
  :plain => :text,
9
9
  :plaintext => :text,
10
10
  :remove_comments => :comment_filter,
11
- :stats => :statistic,
12
- :tex => :latex
11
+ :stats => :statistic
13
12
 
14
13
  # No default because Tokens#nonsense would not raise NoMethodError.
15
14
 
@@ -96,16 +96,16 @@ module Encoders
96
96
  DEFAULT_OPTIONS = {
97
97
  :tab_width => 8,
98
98
 
99
- :css => :class,
99
+ :css => :class,
100
100
  :style => :alpha,
101
- :wrap => nil,
101
+ :wrap => nil,
102
102
  :title => 'CodeRay output',
103
103
 
104
- :line_numbers => nil,
104
+ :line_numbers => nil,
105
105
  :line_number_anchors => 'n',
106
- :line_number_start => 1,
107
- :bold_every => 10,
108
- :highlight_lines => nil,
106
+ :line_number_start => 1,
107
+ :bold_every => 10,
108
+ :highlight_lines => nil,
109
109
 
110
110
  :hint => false,
111
111
  }
@@ -1,6 +1,6 @@
1
1
  module CodeRay
2
2
  module Encoders
3
-
3
+
4
4
  load :html
5
5
 
6
6
  # Wraps the output into a HTML page, using CSS classes and
@@ -8,17 +8,17 @@ module Encoders
8
8
  #
9
9
  # See Encoders::HTML for available options.
10
10
  class Page < HTML
11
-
11
+
12
12
  FILE_EXTENSION = 'html'
13
-
13
+
14
14
  register_for :page
15
-
15
+
16
16
  DEFAULT_OPTIONS = HTML::DEFAULT_OPTIONS.merge \
17
17
  :css => :class,
18
18
  :wrap => :page,
19
19
  :line_numbers => :table
20
-
20
+
21
21
  end
22
-
22
+
23
23
  end
24
24
  end
@@ -45,7 +45,7 @@ module CodeRay
45
45
  if !opts[:lang] && RedCloth::VERSION.to_s >= '4.2.0'
46
46
  # simulating pre-4.2 behavior
47
47
  if opts[:text].sub!(/\A\[(\w+)\]/, '')
48
- if CodeRay::Scanners[$1].plugin_id == :text
48
+ if CodeRay::Scanners[$1].lang == :text
49
49
  opts[:text] = $& + opts[:text]
50
50
  else
51
51
  opts[:lang] = $1
@@ -152,11 +152,25 @@ module CodeRay
152
152
  plugin_hash.values.grep(Class)
153
153
  end
154
154
 
155
+ # Loads the map file (see map).
156
+ #
157
+ # This is done automatically when plugin_path is called.
158
+ def load_plugin_map
159
+ mapfile = path_to '_map'
160
+ @plugin_map_loaded = true
161
+ if File.exist? mapfile
162
+ require mapfile
163
+ true
164
+ else
165
+ false
166
+ end
167
+ end
168
+
155
169
  protected
156
170
 
157
171
  # Return a plugin hash that automatically loads plugins.
158
172
  def make_plugin_hash
159
- map_loaded = false
173
+ @plugin_map_loaded ||= false
160
174
  Hash.new do |h, plugin_id|
161
175
  id = validate_id(plugin_id)
162
176
  path = path_to id
@@ -164,15 +178,14 @@ module CodeRay
164
178
  raise LoadError, "#{path} not found" unless File.exist? path
165
179
  require path
166
180
  rescue LoadError => boom
167
- if map_loaded
181
+ if @plugin_map_loaded
168
182
  if h.has_key?(nil) # default plugin
169
183
  h[nil]
170
184
  else
171
185
  raise PluginNotFound, 'Could not load plugin %p: %s' % [id, boom]
172
186
  end
173
187
  else
174
- load_map
175
- map_loaded = true
188
+ load_plugin_map
176
189
  h[plugin_id]
177
190
  end
178
191
  else
@@ -186,14 +199,6 @@ module CodeRay
186
199
  end
187
200
  end
188
201
 
189
- # Loads the map file (see map).
190
- #
191
- # This is done automatically when plugin_path is called.
192
- def load_map
193
- mapfile = path_to '_map'
194
- require mapfile if File.exist? mapfile
195
- end
196
-
197
202
  # Returns the expected path to the plugin file for the given id.
198
203
  def path_to plugin_id
199
204
  File.join plugin_path, "#{plugin_id}.rb"
@@ -230,6 +235,8 @@ module CodeRay
230
235
  # See CodeRay::PluginHost for examples.
231
236
  module Plugin
232
237
 
238
+ attr_reader :plugin_id
239
+
233
240
  # Register this class for the given +id+.
234
241
  #
235
242
  # Example:
@@ -262,9 +269,12 @@ module CodeRay
262
269
  self::PLUGIN_HOST
263
270
  end
264
271
 
265
- # Returns the plugin id used by the engine.
266
- def plugin_id
267
- @plugin_id ||= name[/\w+$/].downcase
272
+ def aliases
273
+ plugin_host.load_plugin_map
274
+ plugin_host.plugin_hash.inject [] do |aliases, (key, value)|
275
+ aliases << key if plugin_host[key] == self
276
+ aliases
277
+ end
268
278
  end
269
279
 
270
280
  end
@@ -61,6 +61,8 @@ module CodeRay
61
61
 
62
62
  KINDS_NOT_LOC = [:comment, :doctype, :docstring]
63
63
 
64
+ attr_accessor :state
65
+
64
66
  class << self
65
67
 
66
68
  # Normalizes the given code into a string with UNIX newlines, in the
@@ -79,7 +81,7 @@ module CodeRay
79
81
  end
80
82
 
81
83
  # The typical filename suffix for this scanner's language.
82
- def file_extension extension = plugin_id
84
+ def file_extension extension = lang
83
85
  @file_extension ||= extension.to_s
84
86
  end
85
87
 
@@ -89,7 +91,9 @@ module CodeRay
89
91
  end
90
92
 
91
93
  # The lang of this Scanner class, which is equal to its Plugin ID.
92
- alias lang plugin_id
94
+ def lang
95
+ @plugin_id
96
+ end
93
97
 
94
98
  protected
95
99
 
@@ -190,7 +194,14 @@ module CodeRay
190
194
  else
191
195
  raise ArgumentError, 'expected String, Array, or nil'
192
196
  end
193
- scan_tokens @tokens, options
197
+
198
+ begin
199
+ scan_tokens @tokens, options
200
+ rescue => e
201
+ message = "Error in %s#scan_tokens, initial state was: %p" % [self.class, defined?(state) && state]
202
+ raise_inspect e.message, @tokens, message, 30, e.backtrace
203
+ end
204
+
194
205
  @cached_tokens = @tokens
195
206
  if source.is_a? Array
196
207
  @tokens.split_into_parts(*source.map { |part| part.size })
@@ -260,7 +271,7 @@ module CodeRay
260
271
  end
261
272
 
262
273
  # Scanner error with additional status information
263
- def raise_inspect msg, tokens, state = 'No state given!', ambit = 30
274
+ def raise_inspect msg, tokens, state = self.state || 'No state given!', ambit = 30, backtrace = caller
264
275
  raise ScanError, <<-EOE % [
265
276
 
266
277
 
@@ -288,7 +299,7 @@ surrounding code:
288
299
  matched, state, bol?, eos?,
289
300
  string[pos - ambit, ambit],
290
301
  string[pos, ambit],
291
- ]
302
+ ], backtrace
292
303
  end
293
304
 
294
305
  # Shorthand for scan_until(/\z/).
@@ -83,8 +83,8 @@ module CodeRay
83
83
  ] # :nodoc:
84
84
 
85
85
  IDENT_KIND = WordList.new(:ident).
86
- add(SPECIAL_FORMS, :reserved).
87
- add(CORE_FORMS, :reserved).
86
+ add(SPECIAL_FORMS, :keyword).
87
+ add(CORE_FORMS, :keyword).
88
88
  add(PREDEFINED_CONSTANTS, :predefined_constant)
89
89
 
90
90
  KEYWORD_NEXT_TOKEN_KIND = WordList.new(nil).
@@ -164,7 +164,7 @@ module CodeRay
164
164
  elsif match = scan(/#{IDENTIFIER}/o)
165
165
  kind = IDENT_KIND[match]
166
166
  encoder.text_token match, kind
167
- if rest? && kind == :reserved
167
+ if rest? && kind == :keyword
168
168
  if kind = KEYWORD_NEXT_TOKEN_KIND[match]
169
169
  encoder.text_token match, :space if match = scan(/\s+/o)
170
170
  encoder.text_token match, kind if match = scan(/#{IDENTIFIER}/o)
@@ -9,7 +9,7 @@ module Scanners
9
9
  register_for :delphi
10
10
  file_extension 'pas'
11
11
 
12
- RESERVED_WORDS = [
12
+ KEYWORDS = [
13
13
  'and', 'array', 'as', 'at', 'asm', 'at', 'begin', 'case', 'class',
14
14
  'const', 'constructor', 'destructor', 'dispinterface', 'div', 'do',
15
15
  'downto', 'else', 'end', 'except', 'exports', 'file', 'finalization',
@@ -34,7 +34,7 @@ module Scanners
34
34
  ] # :nodoc:
35
35
 
36
36
  IDENT_KIND = CaseIgnoringWordList.new(:ident).
37
- add(RESERVED_WORDS, :reserved).
37
+ add(KEYWORDS, :keyword).
38
38
  add(DIRECTIVES, :directive) # :nodoc:
39
39
 
40
40
  NAME_FOLLOWS = CaseIgnoringWordList.new(false).
@@ -11,7 +11,7 @@ module Scanners
11
11
 
12
12
  DEFAULT_OPTIONS = {
13
13
  :highlight_code => true,
14
- :inline_diff => true,
14
+ :inline_diff => true,
15
15
  }
16
16
 
17
17
  protected
@@ -73,7 +73,7 @@ module Scanners
73
73
  next unless match = scan(/.+/)
74
74
  encoder.text_token match, :plain
75
75
  elsif match = scan(/@@(?>[^@\n]*)@@/)
76
- content_scanner.instance_variable_set(:@state, :initial) unless match?(/\n\+/)
76
+ content_scanner.state = :initial unless match?(/\n\+/)
77
77
  content_scanner_entry_state = nil
78
78
  if check(/\n|$/)
79
79
  encoder.begin_line line_kind = :change
@@ -106,37 +106,39 @@ module Scanners
106
106
  encoder.begin_line line_kind = :delete
107
107
  encoder.text_token match, :delete
108
108
  if options[:inline_diff] && deleted_lines == 1 && check(/(?>.*)\n\+(?>.*)$(?!\n\+)/)
109
- if content_scanner.instance_variable_defined?(:@state)
110
- content_scanner_entry_state = content_scanner.instance_variable_get(:@state)
111
- end
109
+ content_scanner_entry_state = content_scanner.state
112
110
  skip(/(.*)\n\+(.*)$/)
113
111
  head, deletion, insertion, tail = diff self[1], self[2]
114
112
  pre, deleted, post = content_scanner.tokenize [head, deletion, tail], :tokens => Tokens.new
115
113
  encoder.tokens pre
116
- encoder.begin_group :eyecatcher
117
- encoder.tokens deleted
118
- encoder.end_group :eyecatcher
114
+ unless deleted.empty?
115
+ encoder.begin_group :eyecatcher
116
+ encoder.tokens deleted
117
+ encoder.end_group :eyecatcher
118
+ end
119
119
  encoder.tokens post
120
120
  encoder.end_line line_kind
121
121
  encoder.text_token "\n", :space
122
122
  encoder.begin_line line_kind = :insert
123
123
  encoder.text_token '+', :insert
124
- content_scanner.instance_variable_set(:@state, content_scanner_entry_state || :initial)
124
+ content_scanner.state = content_scanner_entry_state || :initial
125
125
  pre, inserted, post = content_scanner.tokenize [head, insertion, tail], :tokens => Tokens.new
126
126
  encoder.tokens pre
127
- encoder.begin_group :eyecatcher
128
- encoder.tokens inserted
129
- encoder.end_group :eyecatcher
127
+ unless inserted.empty?
128
+ encoder.begin_group :eyecatcher
129
+ encoder.tokens inserted
130
+ encoder.end_group :eyecatcher
131
+ end
130
132
  encoder.tokens post
131
133
  elsif match = scan(/.*/)
132
134
  if options[:highlight_code]
133
- if deleted_lines == 1 && content_scanner.instance_variable_defined?(:@state)
134
- content_scanner_entry_state = content_scanner.instance_variable_get(:@state)
135
+ if deleted_lines == 1
136
+ content_scanner_entry_state = content_scanner.state
135
137
  end
136
138
  content_scanner.tokenize match, :tokens => encoder unless match.empty?
137
139
  if !match?(/\n-/)
138
140
  if match?(/\n\+/)
139
- content_scanner.instance_variable_set(:@state, content_scanner_entry_state || :initial)
141
+ content_scanner.state = content_scanner_entry_state || :initial
140
142
  end
141
143
  content_scanner_entry_state = nil
142
144
  end
@@ -182,9 +182,9 @@ module Scanners
182
182
  ]
183
183
 
184
184
  IDENT_KIND = CaseIgnoringWordList.new(:ident).
185
- add(KEYWORDS, :reserved).
185
+ add(KEYWORDS, :keyword).
186
186
  add(TYPES, :predefined_type).
187
- add(LANGUAGE_CONSTRUCTS, :reserved).
187
+ add(LANGUAGE_CONSTRUCTS, :keyword).
188
188
  add(BUILTIN_FUNCTIONS, :predefined).
189
189
  add(CLASSES, :predefined_constant).
190
190
  add(EXCEPTIONS, :exception).
@@ -281,7 +281,7 @@ module Scanners
281
281
  label_expected = false
282
282
  if kind == :ident && match =~ /^[A-Z]/
283
283
  kind = :constant
284
- elsif kind == :reserved
284
+ elsif kind == :keyword
285
285
  case match
286
286
  when 'class'
287
287
  states << :class_expected
@@ -23,8 +23,9 @@ module Scanners
23
23
  end
24
24
 
25
25
  def scan_tokens encoder, options
26
+ state, heredocs = @state
27
+ heredocs = heredocs.dup if heredocs.is_a?(Array)
26
28
 
27
- state = @state
28
29
  if state && state.instance_of?(self.class::StringState)
29
30
  encoder.begin_group state.type
30
31
  end
@@ -34,10 +35,15 @@ module Scanners
34
35
  method_call_expected = false
35
36
  value_expected = true
36
37
 
37
- heredocs = nil
38
38
  inline_block_stack = nil
39
39
  inline_block_curly_depth = 0
40
40
 
41
+ if heredocs
42
+ state = heredocs.shift
43
+ encoder.begin_group state.type
44
+ heredocs = nil if heredocs.empty?
45
+ end
46
+
41
47
  # def_object_stack = nil
42
48
  # def_object_paren_depth = 0
43
49
 
@@ -90,7 +96,7 @@ module Scanners
90
96
  if match[/\A[A-Z]/] && !(match[/[!?]$/] || match?(/\(/))
91
97
  kind = :constant
92
98
  end
93
- elsif kind == :reserved
99
+ elsif kind == :keyword
94
100
  state = patterns::KEYWORD_NEW_STATE[match]
95
101
  value_expected = true if patterns::KEYWORDS_EXPECTING_VALUE[match]
96
102
  end
@@ -421,11 +427,14 @@ module Scanners
421
427
 
422
428
  # cleaning up
423
429
  if options[:keep_state]
424
- @state = state
430
+ heredocs = nil if heredocs && heredocs.empty?
431
+ @state = state, heredocs
425
432
  end
433
+
426
434
  if state.is_a? self.class::StringState
427
435
  encoder.end_group state.type
428
436
  end
437
+
429
438
  if inline_block_stack
430
439
  until inline_block_stack.empty?
431
440
  state, = *inline_block_stack.pop
@@ -4,7 +4,7 @@ module Scanners
4
4
 
5
5
  module Ruby::Patterns # :nodoc: all
6
6
 
7
- RESERVED_WORDS = %w[
7
+ KEYWORDS = %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
@@ -26,7 +26,7 @@ module Scanners
26
26
  ]
27
27
 
28
28
  IDENT_KIND = WordList.new(:ident).
29
- add(RESERVED_WORDS, :reserved).
29
+ add(KEYWORDS, :keyword).
30
30
  add(PREDEFINED_CONSTANTS, :predefined_constant)
31
31
 
32
32
  KEYWORD_NEW_STATE = WordList.new(:initial).
@@ -55,7 +55,7 @@ module Scanners
55
55
  def heredoc_pattern delim, interpreted, indented
56
56
  # delim = delim.dup # workaround for old Ruby
57
57
  delim_pattern = Regexp.escape(delim)
58
- delim_pattern = / \n #{ '(?>[ \t]*)' if indented } #{ Regexp.new delim_pattern } $ /x
58
+ delim_pattern = / (?:\A|\n) #{ '(?>[ \t]*)' if indented } #{ Regexp.new delim_pattern } $ /x
59
59
  if interpreted
60
60
  / (?= #{delim_pattern}() | \\ | \# [{$@] ) /mx # $1 set == end of heredoc
61
61
  else
@@ -19,7 +19,7 @@ module CodeRay
19
19
  ] # :nodoc:
20
20
 
21
21
  IDENT_KIND = CaseIgnoringWordList.new(:ident).
22
- add(CORE_FORMS, :reserved) # :nodoc:
22
+ add(CORE_FORMS, :keyword) # :nodoc:
23
23
 
24
24
  #IDENTIFIER_INITIAL = /[a-z!@\$%&\*\/\:<=>\?~_\^]/i
25
25
  #IDENTIFIER_SUBSEQUENT = /#{IDENTIFIER_INITIAL}|\d|\.|\+|-/
@@ -141,8 +141,8 @@ table.CodeRay td { padding: 2px 4px; vertical-align: top; }
141
141
  .head { color: #f8f; background: #505 }
142
142
  .head .filename { color: white; }
143
143
 
144
- .ins .eye { background-color: hsla(120,100%,50%,0.2) }
145
- .del .eye { background-color: hsla(0,100%,50%,0.2) }
144
+ .del .eye { background-color: hsla(0,100%,50%,0.2); border: 1px solid hsla(0,100%,45%,0.5); margin: -1px; border-bottom: none; border-top-left-radius: 5px; border-top-right-radius: 5px; }
145
+ .ins .eye { background-color: hsla(120,100%,50%,0.2); border: 1px solid hsla(120,100%,25%,0.5); margin: -1px; border-top: none; border-bottom-left-radius: 5px; border-bottom-right-radius: 5px; }
146
146
 
147
147
  .ins .ins { color: #080; background:transparent; font-weight:bold }
148
148
  .del .del { color: #800; background:transparent; font-weight:bold }
@@ -223,12 +223,15 @@ module CodeRay
223
223
  content_or_kind
224
224
  end
225
225
  end
226
- parts << part.concat(closing)
227
- part = Tokens.new
226
+ part.concat closing
227
+ begin
228
+ parts << part
229
+ part = Tokens.new
230
+ size = sizes[i += 1]
231
+ end until size.nil? || size > 0
228
232
  # ...and open them again.
229
233
  part.concat opened.flatten
230
234
  part_size = 0
231
- size = sizes[i += 1]
232
235
  redo unless content.empty?
233
236
  else
234
237
  part << content << item
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: coderay
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease: 10
5
- version: 1.0.0.778.pre
5
+ version: 1.0.0.788.pre
6
6
  platform: ruby
7
7
  authors:
8
8
  - murphy
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-06-12 00:00:00 Z
13
+ date: 2011-06-25 00:00:00 Z
14
14
  dependencies: []
15
15
 
16
16
  description: Fast and easy syntax highlighting for selected languages, written in Ruby. Comes with RedCloth integration and LOC counter.
@@ -18,7 +18,6 @@ email:
18
18
  - murphy@rubychan.de
19
19
  executables:
20
20
  - coderay
21
- - coderay_stylesheet
22
21
  extensions: []
23
22
 
24
23
  extra_rdoc_files:
@@ -97,7 +96,6 @@ files:
97
96
  - test/functional/for_redcloth.rb
98
97
  - test/functional/suite.rb
99
98
  - bin/coderay
100
- - bin/coderay_stylesheet
101
99
  - FOLDERS
102
100
  homepage: http://coderay.rubychan.de
103
101
  licenses: []
@@ -1,4 +0,0 @@
1
- #!/usr/bin/env ruby
2
- require 'coderay'
3
-
4
- puts CodeRay::Encoders[:html]::CSS.new.stylesheet