diff options
author | murphy <murphy@rubychan.de> | 2006-04-15 03:48:36 +0000 |
---|---|---|
committer | murphy <murphy@rubychan.de> | 2006-04-15 03:48:36 +0000 |
commit | d7f0a0011dd8f2629c4071b8d3cb0004bb9e2a99 (patch) | |
tree | c515d94bda7650c1d40dab9aefa541ef9f9d4c7a | |
parent | 5ee15661dbc2da70927f588e310315233aff6eea (diff) | |
download | coderay-d7f0a0011dd8f2629c4071b8d3cb0004bb9e2a99.tar.gz |
styles/_map.rb added. :cycnus is now default style. html/css.rb adjusted.
ROADMAP and TODO updated.
Ruby scanner:
Fixed a bug: Fancy strings don't allow \w delimiters.
They _do_ also allow whitespace delimiters, but adding this would cause
many scan errors. So I leave this bug unfixed.
-rw-r--r-- | ROADMAP | 4 | ||||
-rw-r--r-- | TODO | 4 | ||||
-rw-r--r-- | demo/demo_simple.out | 1 | ||||
-rw-r--r-- | lib/coderay/encoders/html/css.rb | 5 | ||||
-rw-r--r-- | lib/coderay/scanners/ruby.rb | 66 | ||||
-rw-r--r-- | lib/coderay/scanners/ruby/patterns.rb | 10 | ||||
-rw-r--r-- | lib/coderay/styles/_map.rb | 7 | ||||
-rw-r--r-- | test/ruby/strange.in.rb | 4 | ||||
-rw-r--r-- | test/ruby/strange.out.raydebug | 4 |
9 files changed, 60 insertions, 45 deletions
@@ -4,10 +4,10 @@ Plaintext, Ruby, C
0.8.0
-XML, HTML, CSS
+XML, CSS
1.2
-YAML, eRuby, irb, RHTML, SQL, Python
+YAML, eRuby, irb, SQL, Python
1.4
PHP, Perl (*schauder*), Pascal/Delphi, C++, Java
@@ -9,9 +9,9 @@ Project: Documentation:
3/4 0 2 ? Doc the interface
0 2 ? Cleanup/Read Doc
-3/4 0 1 Sa2 write examples
+3/4 0 1 write examples
- 1 2 Mi Code Cleanup: Indentation
+ 1 2 Code Cleanup: Indentation
L 2 2 Rewrite Tools:
coderay, bench.rb, highlight.rb
L 2 1 Cleanup Rakefile
diff --git a/demo/demo_simple.out b/demo/demo_simple.out index 4e41e3d..a033139 100644 --- a/demo/demo_simple.out +++ b/demo/demo_simple.out @@ -1,2 +1 @@ <span class="CodeRay">puts <span style="background-color:#fff0f0"><span style="color:#710">'</span><span style="color:#D20">Hello, world!</span><span style="color:#710">'</span></span></span>
-
diff --git a/lib/coderay/encoders/html/css.rb b/lib/coderay/encoders/html/css.rb index e938e07..ad055aa 100644 --- a/lib/coderay/encoders/html/css.rb +++ b/lib/coderay/encoders/html/css.rb @@ -3,12 +3,9 @@ module CodeRay module Encoders class HTML
class CSS
- DEFAULT_STYLESHEET_ID = :cycnus
-
attr :stylesheet
- def CSS.load_stylesheet style = :default
- style = DEFAULT_STYLESHEET_ID if style == :default
+ def CSS.load_stylesheet style = nil
CodeRay::Styles[style]
end
diff --git a/lib/coderay/scanners/ruby.rb b/lib/coderay/scanners/ruby.rb index 9a33bef..8127944 100644 --- a/lib/coderay/scanners/ruby.rb +++ b/lib/coderay/scanners/ruby.rb @@ -36,14 +36,14 @@ module CodeRay module Scanners depth = nil
states = []
- c = self.class
+ patterns = Patterns # avoid constant lookup
until eos?
type = :error
match = nil
kind = nil
- if state.instance_of? c::StringState
+ if state.instance_of? patterns::StringState
# {{{
match = scan_until(state.pattern) || scan_until(/\z/)
tokens << [match, :content] unless match.empty?
@@ -69,7 +69,7 @@ module CodeRay module Scanners end
tokens << [match, :delimiter]
if state.type == :regexp and not eos?
- modifiers = scan(/#{REGEXP_MODIFIERS}/ox)
+ modifiers = scan(/#{patterns::REGEXP_MODIFIERS}/ox)
tokens << [modifiers, :modifier] unless modifiers.empty?
if parse_regexp
extended = modifiers.index ?x
@@ -108,7 +108,7 @@ module CodeRay module Scanners when '\\'
if state.interpreted
- if esc = scan(/ #{ESCAPE} /ox)
+ if esc = scan(/ #{patterns::ESCAPE} /ox)
tokens << [match + esc, :char]
else
tokens << [match, :error]
@@ -143,7 +143,7 @@ module CodeRay module Scanners state.paren_depth += 1
tokens << [match, :nesting_delimiter]
- when /#{REGEXP_SYMBOLS}/ox
+ when /#{patterns::REGEXP_SYMBOLS}/ox
tokens << [match, :function]
else
@@ -155,7 +155,7 @@ module CodeRay module Scanners else
# {{{
if match = scan(/ [ \t\f]+ | \\? \n | \# .* /x) or
- ( bol? and match = scan(/#{RUBYDOC_OR_DATA}/o) )
+ ( bol? and match = scan(/#{patterns::RUBYDOC_OR_DATA}/o) )
fancy_allowed = true
case m = match[0]
when ?\s, ?\t, ?\f
@@ -188,23 +188,23 @@ module CodeRay module Scanners elsif state == :initial
# IDENTS #
- if match = scan(/#{METHOD_NAME}/o)
+ if match = scan(/#{patterns::METHOD_NAME}/o)
if last_token_dot
type = if match[/^[A-Z]/] and not match?(/\(/) then :constant else :ident end
else
- type = c::IDENT_KIND[match]
+ type = patterns::IDENT_KIND[match]
if type == :ident and match[/^[A-Z]/] and not match[/[!?]$/] and not match?(/\(/)
type = :constant
elsif type == :reserved
- state = c::DEF_NEW_STATE[match]
+ state = patterns::DEF_NEW_STATE[match]
end
end
## experimental!
- fancy_allowed = regexp_allowed = :set if c::REGEXP_ALLOWED[match] or check(/\s+(?:%\S|\/\S)/)
+ fancy_allowed = regexp_allowed = :set if patterns::REGEXP_ALLOWED[match] or check(/\s+(?:%\S|\/\S)/)
# OPERATORS #
elsif (not last_token_dot and match = scan(/ ==?=? | \.\.?\.? | [\(\)\[\]\{\}] | :: | , /x)) or
- (last_token_dot and match = scan(/#{METHOD_NAME_OPERATOR}/o))
+ (last_token_dot and match = scan(/#{patterns::METHOD_NAME_OPERATOR}/o))
if match !~ / [.\)\]\}] /x or match =~ /\.\.\.?/
regexp_allowed = fancy_allowed = :set
end
@@ -228,32 +228,32 @@ module CodeRay module Scanners elsif match = scan(/ ['"] /mx)
tokens << [:open, :string]
type = :delimiter
- state = c::StringState.new :string, match == '"', match # important for streaming
+ state = patterns::StringState.new :string, match == '"', match # important for streaming
- elsif match = scan(/#{INSTANCE_VARIABLE}/o)
+ elsif match = scan(/#{patterns::INSTANCE_VARIABLE}/o)
type = :instance_variable
elsif regexp_allowed and match = scan(/\//)
tokens << [:open, :regexp]
type = :delimiter
interpreted = true
- state = c::StringState.new :regexp, interpreted, match
+ state = patterns::StringState.new :regexp, interpreted, match
if parse_regexp
tokens = []
saved_tokens = tokens
end
- elsif match = scan(/#{NUMERIC}/o)
+ elsif match = scan(/#{patterns::NUMERIC}/o)
type = if self[1] then :float else :integer end
- elsif match = scan(/#{SYMBOL}/o)
+ elsif match = scan(/#{patterns::SYMBOL}/o)
case delim = match[1]
when ?', ?"
tokens << [:open, :symbol]
tokens << [':', :symbol]
match = delim.chr
type = :delimiter
- state = c::StringState.new :symbol, delim == ?", match
+ state = patterns::StringState.new :symbol, delim == ?", match
else
type = :symbol
end
@@ -262,27 +262,27 @@ module CodeRay module Scanners regexp_allowed = fancy_allowed = :set
type = :operator
- elsif fancy_allowed and match = scan(/#{HEREDOC_OPEN}/o)
+ elsif fancy_allowed and match = scan(/#{patterns::HEREDOC_OPEN}/o)
indented = self[1] == '-'
quote = self[3]
delim = self[quote ? 4 : 2]
- type = c::QUOTE_TO_TYPE[quote]
+ type = patterns::QUOTE_TO_TYPE[quote]
tokens << [:open, type]
tokens << [match, :delimiter]
match = :close
- heredoc = c::StringState.new type, quote != '\'', delim, (indented ? :indented : :linestart )
+ heredoc = patterns::StringState.new type, quote != '\'', delim, (indented ? :indented : :linestart )
heredocs ||= [] # create heredocs if empty
heredocs << heredoc
- elsif fancy_allowed and match = scan(/#{FANCY_START_SAVE}/o)
- type, interpreted = *FancyStringType.fetch(self[1]) do
+ elsif fancy_allowed and match = scan(/#{patterns::FANCY_START_SAVE}/o)
+ type, interpreted = *patterns::FancyStringType.fetch(self[1]) do
raise_inspect 'Unknown fancy string: %%%p' % k, tokens
end
tokens << [:open, type]
- state = c::StringState.new type, interpreted, self[2]
+ state = patterns::StringState.new type, interpreted, self[2]
type = :delimiter
- elsif fancy_allowed and match = scan(/#{CHARACTER}/o)
+ elsif fancy_allowed and match = scan(/#{patterns::CHARACTER}/o)
type = :integer
elsif match = scan(/ [\/%]=? | <(?:<|=>?)? | [?:;] /x)
@@ -295,13 +295,13 @@ module CodeRay module Scanners else
tokens << [:open, :shell]
type = :delimiter
- state = c::StringState.new :shell, true, match
+ state = patterns::StringState.new :shell, true, match
end
- elsif match = scan(/#{GLOBAL_VARIABLE}/o)
+ elsif match = scan(/#{patterns::GLOBAL_VARIABLE}/o)
type = :global_variable
- elsif match = scan(/#{CLASS_VARIABLE}/o)
+ elsif match = scan(/#{patterns::CLASS_VARIABLE}/o)
type = :class_variable
else
@@ -311,7 +311,7 @@ module CodeRay module Scanners elsif state == :def_expected
state = :initial
- if match = scan(/(?>#{METHOD_NAME_EX})(?!\.|::)/o)
+ if match = scan(/(?>#{patterns::METHOD_NAME_EX})(?!\.|::)/o)
type = :method
else
next
@@ -319,16 +319,16 @@ module CodeRay module Scanners elsif state == :undef_expected
state = :undef_comma_expected
- if match = scan(/#{METHOD_NAME_EX}/o)
+ if match = scan(/#{patterns::METHOD_NAME_EX}/o)
type = :method
- elsif match = scan(/#{SYMBOL}/o)
+ elsif match = scan(/#{patterns::SYMBOL}/o)
case delim = match[1]
when ?', ?"
tokens << [:open, :symbol]
tokens << [':', :symbol]
match = delim.chr
type = :delimiter
- state = c::StringState.new :symbol, delim == ?", match
+ state = patterns::StringState.new :symbol, delim == ?", match
state.next_state = :undef_comma_expected
else
type = :symbol
@@ -352,7 +352,7 @@ module CodeRay module Scanners type = :operator
else
state = :initial
- if match = scan(/ (?:#{IDENT}::)* #{IDENT} /ox)
+ if match = scan(/ (?:#{patterns::IDENT}::)* #{patterns::IDENT} /ox)
type = :class
else
next
@@ -379,7 +379,7 @@ module CodeRay module Scanners end
end
- states << state if state.is_a? c::StringState
+ states << state if state.is_a? patterns::StringState
until states.empty?
tokens << [:close, states.pop.type]
end
diff --git a/lib/coderay/scanners/ruby/patterns.rb b/lib/coderay/scanners/ruby/patterns.rb index 7bf9103..28439ec 100644 --- a/lib/coderay/scanners/ruby/patterns.rb +++ b/lib/coderay/scanners/ruby/patterns.rb @@ -1,6 +1,8 @@ module CodeRay module Scanners
- class Ruby
+class Ruby
+
+ module Patterns # :nodoc:
RESERVED_WORDS = %w[
and def end in or unless begin
@@ -132,8 +134,8 @@ module CodeRay module Scanners # FIXME: \s and = are only a workaround, they are still allowed
# as delimiters.
- FANCY_START_SAVE = / % ( [qQwWxsr] | (?![\w\s=]) ) (.) /mx
- FANCY_START_CORRECT = / % ( [qQwWxsr] | (?!\w) ) (.) /mx
+ FANCY_START_SAVE = / % ( [qQwWxsr] | (?![a-zA-Z0-9\s=]) ) ([^a-zA-Z0-9]) /mx
+ FANCY_START_CORRECT = / % ( [qQwWxsr] | (?![a-zA-Z0-9]) ) ([^a-zA-Z0-9]) /mx
FancyStringType = {
'q' => [:string, false],
@@ -211,4 +213,6 @@ module CodeRay module Scanners end
+end
+
end end
diff --git a/lib/coderay/styles/_map.rb b/lib/coderay/styles/_map.rb new file mode 100644 index 0000000..33c2327 --- /dev/null +++ b/lib/coderay/styles/_map.rb @@ -0,0 +1,7 @@ +module CodeRay
+ module Styles
+
+ default :cycnus
+
+ end
+end
diff --git a/test/ruby/strange.in.rb b/test/ruby/strange.in.rb index 03fec4b..8369aaa 100644 --- a/test/ruby/strange.in.rb +++ b/test/ruby/strange.in.rb @@ -47,6 +47,10 @@ puts 30.send(:/, 5) # prints 6 #%W[ but #@0illegal_values look strange.]
+%Quark dazu
+
+% abc # FIXME
+
%s#ruby allows strange#{constructs}
%s#ruby allows strange#$constructs
%s#ruby allows strange#@@constructs
diff --git a/test/ruby/strange.out.raydebug b/test/ruby/strange.out.raydebug index baa4955..bcf053d 100644 --- a/test/ruby/strange.out.raydebug +++ b/test/ruby/strange.out.raydebug @@ -47,6 +47,10 @@ shell<delimiter(%x')content(instance variables can be )escape(#)instance_variabl comment(#%W[ but #@0illegal_values look strange.])
+operator(%)constant(Quark) ident(dazu)
+
+operator(%) ident(abc) comment(# FIXME)
+
symbol<delimiter(%s#)content(ruby allows strange)delimiter(#)>operator({)ident(constructs)operator(})
symbol<delimiter(%s#)content(ruby allows strange)delimiter(#)>global_variable($constructs)
symbol<delimiter(%s#)content(ruby allows strange)delimiter(#)>class_variable(@@constructs)
|