diff options
author | murphy <murphy@rubychan.de> | 2006-09-28 15:49:53 +0000 |
---|---|---|
committer | murphy <murphy@rubychan.de> | 2006-09-28 15:49:53 +0000 |
commit | a3af20bd6c3aef3976d18d49f407613ff7693baf (patch) | |
tree | 105f09ec27e217a09bf1b7c678a4cf484cf2182f | |
parent | 6ecba0d804f995d377495997e5edd014486acf65 (diff) | |
download | coderay-a3af20bd6c3aef3976d18d49f407613ff7693baf.tar.gz |
Ruby scanner: deleted regexp highlighting (didn't work anyway)
HTML highlighter: unknown token classes now yield a CSS class with that name instead of :error
A new Ruby test
-rw-r--r-- | lib/coderay/encoders/html/classes.rb | 7 | ||||
-rw-r--r-- | lib/coderay/scanners/ruby.rb | 40 | ||||
-rw-r--r-- | test/coderay_suite.rb | 2 | ||||
-rw-r--r-- | test/ruby/diffed.in.rb | 30 | ||||
-rw-r--r-- | test/ruby/diffed.out.raydebug | 30 |
5 files changed, 66 insertions, 43 deletions
diff --git a/lib/coderay/encoders/html/classes.rb b/lib/coderay/encoders/html/classes.rb index ea15ca0..c8f70d9 100644 --- a/lib/coderay/encoders/html/classes.rb +++ b/lib/coderay/encoders/html/classes.rb @@ -3,7 +3,10 @@ module Encoders class HTML - ClassOfKind = { + ClassOfKind = Hash.new do |h, k| + h[k] = k.to_s + end + ClassOfKind.update with = { :attribute_name => 'an', :attribute_name_fat => 'af', :attribute_value => 'av', @@ -65,7 +68,7 @@ module Encoders ClassOfKind[:open] = ClassOfKind[:close] = ClassOfKind[:delimiter] ClassOfKind[:nesting_delimiter] = ClassOfKind[:delimiter] ClassOfKind[:escape] = ClassOfKind[:delimiter] - ClassOfKind.default = ClassOfKind[:error] or raise 'no class found for :error!' + #ClassOfKind.default = ClassOfKind[:error] or raise 'no class found for :error!' end diff --git a/lib/coderay/scanners/ruby.rb b/lib/coderay/scanners/ruby.rb index 76c87ca..77fe664 100644 --- a/lib/coderay/scanners/ruby.rb +++ b/lib/coderay/scanners/ruby.rb @@ -21,14 +21,8 @@ module Scanners helper :patterns - DEFAULT_OPTIONS = { - :parse_regexps => true, - } - private def scan_tokens tokens, options - parse_regexp = false # options[:parse_regexps] - first_bake = saved_tokens = nil last_token_dot = false fancy_allowed = regexp_allowed = true heredocs = nil @@ -72,36 +66,6 @@ module Scanners if state.type == :regexp and not eos? modifiers = scan(/#{patterns::REGEXP_MODIFIERS}/ox) tokens << [modifiers, :modifier] unless modifiers.empty? - if parse_regexp - extended = modifiers.index ?x - tokens = saved_tokens - regexp = tokens - for text, kind in regexp - if text.is_a? ::String - case kind - when :content - text.scan(/([^#]+)|(#.*)/) do |plain, comment| - if plain - tokens << [plain, :content] - else - tokens << [comment, :comment] - end - end - when :character - if text[/\\(?:[swdSWDAzZbB]|\d+)/] - tokens << [text, :modifier] - else - tokens << [text, kind] - end - else - tokens << [text, kind] - end - else - tokens << [text, kind] - end - end - first_bake = saved_tokens = nil - end end tokens << [:close, state.type] fancy_allowed = regexp_allowed = false @@ -241,10 +205,6 @@ module Scanners kind = :delimiter interpreted = true state = patterns::StringState.new :regexp, interpreted, match - if parse_regexp - tokens = [] - saved_tokens = tokens - end elsif match = scan(/#{patterns::NUMERIC}/o) kind = if self[1] then :float else :integer end diff --git a/test/coderay_suite.rb b/test/coderay_suite.rb index 7829a54..d44d8e9 100644 --- a/test/coderay_suite.rb +++ b/test/coderay_suite.rb @@ -84,7 +84,7 @@ module CodeRay File.open(computed, 'wb') { |f| f.write result } print `gvimdiff #{output} #{computed}` if ENV['diff'] end - assert(ok, "Scan error: #{computed} != #{output}") unless ENV['diff'] + assert(ok, "Scan error: #{computed} != #{output}") unless ENV['diff'] or ENV['noassert'] else File.open(output, 'wb') do |f| f.write result end puts "New test: #{output}" diff --git a/test/ruby/diffed.in.rb b/test/ruby/diffed.in.rb new file mode 100644 index 0000000..a1deb0f --- /dev/null +++ b/test/ruby/diffed.in.rb @@ -0,0 +1,30 @@ +## example diff [diff]
+Index: /Users/jgoebel/rails/pastie/app/controllers/pastes_controller.rb
+===================================================================
+--- /Users/jgoebel/rails/pastie/app/controllers/pastes_controller.rb (revision 1431)
++++ /Users/jgoebel/rails/pastie/app/controllers/pastes_controller.rb (revision 1437)
+@@ -1,6 +1,10 @@
++require 'login_system'
+ require 'coderay'
+
+ class PastesController < ApplicationController
++ include LoginSystem
++
++ before_filter :attempt_cookie_login
+
+ # caches_action :recent
+
+@@ -10,11 +14,7 @@
+
+ def show
+ @paste = Paste.find(params[:id])
+- if params[:key] and params[:key]==User.new(@paste.nick).magic_mojo
+- session[:login]=@paste.nick
+- return redirect_to(:action => 'show', :id => @paste.id)
+- end
+-
++ attempt_key_login if not logged_in?
+ unless @paste.asset or not @paste.body.blank?
+ render :action => "edit"
+ end
+
diff --git a/test/ruby/diffed.out.raydebug b/test/ruby/diffed.out.raydebug new file mode 100644 index 0000000..8881649 --- /dev/null +++ b/test/ruby/diffed.out.raydebug @@ -0,0 +1,30 @@ +comment(## example diff [diff]) +constant(Index)operator(:) regexp<delimiter(/)content(Users)delimiter(/)>ident(jgoebel)operator(/)ident(rails)operator(/)ident(pastie)operator(/)ident(app)operator(/)ident(controllers)operator(/)ident(pastes_controller)operator(.)ident(rb) +operator(===)operator(===)operator(===)operator(===)operator(===)operator(===)operator(===)operator(===)operator(===)operator(===)operator(===)operator(===)operator(===)operator(===)operator(===)operator(===)operator(===)operator(===)operator(===)operator(===)operator(===)operator(===)operator(=) +operator(-)operator(-)operator(-) regexp<delimiter(/)content(Users)delimiter(/)>ident(jgoebel)operator(/)ident(rails)operator(/)ident(pastie)operator(/)ident(app)operator(/)ident(controllers)operator(/)ident(pastes_controller)operator(.)ident(rb) operator(()ident(revision) integer(1431)operator(\)) +operator(+)operator(+)operator(+) regexp<delimiter(/)content(Users)delimiter(/)>ident(jgoebel)operator(/)ident(rails)operator(/)ident(pastie)operator(/)ident(app)operator(/)ident(controllers)operator(/)ident(pastes_controller)operator(.)ident(rb) operator(()ident(revision) integer(1437)operator(\)) +error(@)error(@) integer(-1)operator(,)integer(6) integer(+1)operator(,)integer(10) error(@)error(@) +operator(+)ident(require) string<delimiter(')content(login_system)delimiter(')> + ident(require) string<delimiter(')content(coderay)delimiter(')> + + reserved(class) class(PastesController) operator(<) constant(ApplicationController) +operator(+) ident(include) constant(LoginSystem) +operator(+) +operator(+) ident(before_filter) symbol(:attempt_cookie_login) + + comment(# caches_action :recent) + +error(@)error(@) integer(-10)operator(,)integer(11) integer(+14)operator(,)integer(7) error(@)error(@) + + reserved(def) method(show) + instance_variable(@paste) operator(=) constant(Paste)operator(.)ident(find)operator(()ident(params)operator([)symbol(:id)operator(])operator(\)) +operator(-) reserved(if) ident(params)operator([)symbol(:key)operator(]) reserved(and) ident(params)operator([)symbol(:key)operator(])operator(==)constant(User)operator(.)ident(new)operator(()instance_variable(@paste)operator(.)ident(nick)operator(\))operator(.)ident(magic_mojo) +operator(-) ident(session)operator([)symbol(:login)operator(])operator(=)instance_variable(@paste)operator(.)ident(nick) +operator(-) reserved(return) ident(redirect_to)operator(()symbol(:action) operator(=)operator(>) string<delimiter(')content(show)delimiter(')>operator(,) symbol(:id) operator(=)operator(>) instance_variable(@paste)operator(.)ident(id)operator(\)) +operator(-) reserved(end) +operator(-) +operator(+) ident(attempt_key_login) reserved(if) reserved(not) ident(logged_in?) + reserved(unless) instance_variable(@paste)operator(.)ident(asset) reserved(or) reserved(not) instance_variable(@paste)operator(.)ident(body)operator(.)ident(blank?) + ident(render) symbol(:action) operator(=)operator(>) string<delimiter(")content(edit)delimiter(")> + reserved(end) + |