diff options
author | murphy <murphy@rubychan.de> | 2008-01-21 03:32:26 +0000 |
---|---|---|
committer | murphy <murphy@rubychan.de> | 2008-01-21 03:32:26 +0000 |
commit | 13d7eac0b77f3ca280e12422104753d7651ab047 (patch) | |
tree | 60f179f8bb2c1b0e273d96797394f65d5c49a1d1 /lib/coderay/scanners/ruby.rb | |
parent | c545052548086962c61bb6ef79d16b5959aae936 (diff) | |
download | coderay-13d7eac0b77f3ca280e12422104753d7651ab047.tar.gz |
Improved Ruby scanner to use +/- signs only when appropriate (tests adjusted.)
Ignore test/scanners/*/*.expected.html
Diffstat (limited to 'lib/coderay/scanners/ruby.rb')
-rw-r--r-- | lib/coderay/scanners/ruby.rb | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/lib/coderay/scanners/ruby.rb b/lib/coderay/scanners/ruby.rb index f8f27b7..1bbfe07 100644 --- a/lib/coderay/scanners/ruby.rb +++ b/lib/coderay/scanners/ruby.rb @@ -124,7 +124,8 @@ module Scanners # {{{ if match = scan(/[ \t\f]+/) kind = :space - match << scan(/\s*/) unless eos? or heredocs + match << scan(/\s*/) unless eos? || heredocs + value_expected = true if match.index(?\n) # FIXME not quite true tokens << [match, kind] next @@ -175,6 +176,7 @@ module Scanners value_expected = :set if check(/#{patterns::VALUE_FOLLOWS}/o) # OPERATORS # + # TODO: match (), [], {} as one single operator elsif not last_token_dot and match = scan(/ \.\.\.? | (?:\.|::)() | [,\(\)\[\]\{\}] | ==?=? /x) if match !~ / [.\)\]\}] /x or match =~ /\.\.\.?/ value_expected = :set @@ -210,8 +212,9 @@ module Scanners interpreted = true state = patterns::StringState.new :regexp, interpreted, match - elsif match = scan(/#{patterns::NUMERIC}/o) - kind = if self[1] then :float else :integer end + # elsif match = scan(/[-+]?#{patterns::NUMERIC}/o) + elsif match = value_expected ? scan(/[-+]?#{patterns::NUMERIC}/o) : scan(/#{patterns::NUMERIC}/o) + kind = self[1] ? :float : :integer elsif match = scan(/#{patterns::SYMBOL}/o) case delim = match[1] @@ -338,9 +341,11 @@ module Scanners end # }}} - - value_expected = value_expected == :set - last_token_dot = last_token_dot == :set + + unless kind == :error + value_expected = value_expected == :set + last_token_dot = last_token_dot == :set + end if $DEBUG and not kind raise_inspect 'Error token %p in line %d' % |