summaryrefslogtreecommitdiff
path: root/lib/coderay/scanners/ruby.rb
diff options
context:
space:
mode:
authormurphy <murphy@rubychan.de>2005-10-01 06:04:52 +0000
committermurphy <murphy@rubychan.de>2005-10-01 06:04:52 +0000
commit3d8868dd0b9898d589ecdff5151ed5d47956f937 (patch)
tree19a1ed947e24145818d483b3c0211a44d10f557f /lib/coderay/scanners/ruby.rb
parentc194637b0d9af5ee756c5efa0942fe8cc09769e5 (diff)
downloadcoderay-3d8868dd0b9898d589ecdff5151ed5d47956f937.tar.gz
Demos updated, rewritten, enhanced, tested.
Some code cleanups. Bugs fixed, scanner and encoder improved: count.rb: marked Streamable html_css.rb: style for inline numbers html.rb: changed options; :line_numbers_offset is now :line_number_start html_output.rb: offset for inline numbers fixed html.rb: token text no longer changed by gsub! while highlighting (this is even faster!) text.rb, plugin.rb: reindented ruby.rb: eleminated multiple assignments for speed tokens.rb: reindented, Tokens#to_s added, #<< returns self Plugin system: bugs fixed, error messages improved.
Diffstat (limited to 'lib/coderay/scanners/ruby.rb')
-rw-r--r--lib/coderay/scanners/ruby.rb22
1 files changed, 13 insertions, 9 deletions
diff --git a/lib/coderay/scanners/ruby.rb b/lib/coderay/scanners/ruby.rb
index 433726b..72e59bd 100644
--- a/lib/coderay/scanners/ruby.rb
+++ b/lib/coderay/scanners/ruby.rb
@@ -72,7 +72,8 @@ module CodeRay module Scanners
tokens << [modifiers, :modifier] unless modifiers.empty?
if parse_regexp
extended = modifiers.index ?x
- tokens, regexp = saved_tokens, tokens
+ tokens = saved_tokens
+ regexp = tokens
for text, type in regexp
if text.is_a? String
case type
@@ -125,7 +126,8 @@ module CodeRay module Scanners
when ?{
states.push [state, depth, heredocs]
fancy_allowed = regexp_allowed = true
- state, depth = :initial, 1
+ state = :initial
+ depth = 1
tokens << [match + getch, :escape]
when ?$, ?@
tokens << [match, :escape]
@@ -192,7 +194,7 @@ module CodeRay module Scanners
when '}'
depth -= 1
if depth == 0
- state, depth, heredocs = *states.pop
+ state, depth, heredocs = states.pop
type = :escape
end
end
@@ -214,7 +216,7 @@ module CodeRay module Scanners
elsif match = scan(/ ['"] /mx)
tokens << [:open, :string]
type = :delimiter
- state = StringState.new :string, match != '\'', match.dup # important for streaming
+ state = StringState.new :string, match != '\'', match # important for streaming
elsif match = scan(/#{INSTANCE_VARIABLE}/o)
type = :instance_variable
@@ -223,13 +225,14 @@ module CodeRay module Scanners
tokens << [:open, :regexp]
type = :delimiter
interpreted = true
- state = StringState.new :regexp, interpreted, match.dup
+ state = StringState.new :regexp, interpreted, match
if parse_regexp
- tokens, saved_tokens = [], tokens
+ tokens = []
+ saved_tokens = tokens
end
elsif match = scan(/#{NUMERIC}/o)
- type = if match[/#{FLOAT}/o] then :float else :integer end
+ type = if match[/#{FLOAT}/o] then :float else :integer end
elsif fancy_allowed and match = scan(/#{SYMBOL}/o)
case match[1]
@@ -240,7 +243,8 @@ module CodeRay module Scanners
type = :symbol
elsif fancy_allowed and match = scan(/#{HEREDOC_OPEN}/o)
- indented, quote = self[1] == '-', self[3]
+ indented = self[1] == '-'
+ quote = self[3]
delim = self[quote ? 4 : 2]
type = QUOTE_TO_TYPE[quote]
tokens << [:open, type]
@@ -271,7 +275,7 @@ module CodeRay module Scanners
else
tokens << [:open, :shell]
type = :delimiter
- state = StringState.new :shell, true, '`'
+ state = StringState.new :shell, true, match
end
elsif match = scan(/#{GLOBAL_VARIABLE}/o)