From d7f0a0011dd8f2629c4071b8d3cb0004bb9e2a99 Mon Sep 17 00:00:00 2001 From: murphy Date: Sat, 15 Apr 2006 03:48:36 +0000 Subject: 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. --- lib/coderay/encoders/html/css.rb | 5 +-- lib/coderay/scanners/ruby.rb | 66 +++++++++++++++++------------------ lib/coderay/scanners/ruby/patterns.rb | 10 ++++-- lib/coderay/styles/_map.rb | 7 ++++ 4 files changed, 48 insertions(+), 40 deletions(-) create mode 100644 lib/coderay/styles/_map.rb (limited to 'lib/coderay') 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 -- cgit v1.2.1