summaryrefslogtreecommitdiff
path: root/lib/coderay/scanners/ruby.rb
diff options
context:
space:
mode:
authormurphy <murphy@rubychan.de>2009-10-19 17:05:19 +0000
committermurphy <murphy@rubychan.de>2009-10-19 17:05:19 +0000
commit3a23d30cfd1ce226572c05cbf4e8f8043545b512 (patch)
tree9cba4147f7dc6d7cfd8859663dc1a6384cc88e1c /lib/coderay/scanners/ruby.rb
parent95d8e4299ee5c4f7227b367415eb301313f6cb83 (diff)
downloadcoderay-3a23d30cfd1ce226572c05cbf4e8f8043545b512.tar.gz
Updated Ruby scanner:
* cleanup (FIXMEs, dead code, comments) * improved value_expected detection using VALUE_EXPECTING_KEYWORDS * support for self.method style definitions
Diffstat (limited to 'lib/coderay/scanners/ruby.rb')
-rw-r--r--lib/coderay/scanners/ruby.rb13
1 files changed, 8 insertions, 5 deletions
diff --git a/lib/coderay/scanners/ruby.rb b/lib/coderay/scanners/ruby.rb
index b8cba97..cb9637b 100644
--- a/lib/coderay/scanners/ruby.rb
+++ b/lib/coderay/scanners/ruby.rb
@@ -130,14 +130,14 @@ module Scanners
if match = scan(/[ \t\f]+/)
kind = :space
match << scan(/\s*/) unless eos? || heredocs
- value_expected = true if match.index(?\n) # FIXME not quite true
+ value_expected = true if match.index(?\n)
tokens << [match, kind]
next
elsif match = scan(/\\?\n/)
kind = :space
if match == "\n"
- value_expected = true # FIXME not quite true
+ value_expected = true
state = :initial if state == :undef_comma_expected
end
if heredocs
@@ -159,7 +159,6 @@ module Scanners
elsif match = scan(/\#.*/) or
( bol? and match = scan(/#{patterns::RUBYDOC_OR_DATA}/o) )
kind = :comment
- value_expected = true
tokens << [match, kind]
next
@@ -176,9 +175,9 @@ module Scanners
kind = :constant
elsif kind == :reserved
state = patterns::DEF_NEW_STATE[match]
+ value_expected = :set if patterns::VALUE_EXPECTING_KEYWORDS[match]
end
end
- ## experimental!
value_expected = :set if check(/#{patterns::VALUE_FOLLOWS}/o)
elsif last_token_dot and match = scan(/#{patterns::METHOD_NAME_OPERATOR}|\(/o)
@@ -186,7 +185,6 @@ 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
@@ -289,6 +287,7 @@ module Scanners
kind = :error
match = (scan(/./mu) rescue nil) || getch
if !unicode && match.size > 1
+ # warn 'Switchig to unicode mode: %p' % ['รค'[/#{patterns::METHOD_NAME}/uo]]
unicode = true
unscan
next
@@ -298,6 +297,10 @@ module Scanners
elsif state == :def_expected
state = :initial
+ if scan(/self\./)
+ tokens << ['self', :pre_constant]
+ tokens << ['.', :operator]
+ end
if match = scan(unicode ? /(?>#{patterns::METHOD_NAME_EX})(?!\.|::)/uo :
/(?>#{patterns::METHOD_NAME_EX})(?!\.|::)/o)
kind = :method