diff options
author | Kornelius Kalnbach <murphy@rubychan.de> | 2013-03-10 22:46:35 +0100 |
---|---|---|
committer | Kornelius Kalnbach <murphy@rubychan.de> | 2013-03-10 22:46:35 +0100 |
commit | 34e823d709ce19a480dbd78e72e63ada0d3425fb (patch) | |
tree | ec9ae8d35543c2b9834479ab7229333495e28c1b /lib/coderay/scanners/ruby.rb | |
parent | 0392439f9aaa5dde7734743ab5a88193257ec722 (diff) | |
parent | fc16be24d48f8a729ac987149f98f19725943e0d (diff) | |
download | coderay-34e823d709ce19a480dbd78e72e63ada0d3425fb.tar.gz |
Merge branch 'master' into lua-scanner
Diffstat (limited to 'lib/coderay/scanners/ruby.rb')
-rw-r--r-- | lib/coderay/scanners/ruby.rb | 33 |
1 files changed, 21 insertions, 12 deletions
diff --git a/lib/coderay/scanners/ruby.rb b/lib/coderay/scanners/ruby.rb index 2be98a6..c5cf1e2 100644 --- a/lib/coderay/scanners/ruby.rb +++ b/lib/coderay/scanners/ruby.rb @@ -94,18 +94,27 @@ module Scanners if !method_call_expected && match = scan(unicode ? /#{patterns::METHOD_NAME}/uo : /#{patterns::METHOD_NAME}/o) - value_expected = false + kind = patterns::IDENT_KIND[match] - if kind == :ident - if match[/\A[A-Z]/] && !(match[/[!?]$/] || match?(/\(/)) - kind = :constant + if kind == :ident && value_expected != :colon_expected && scan(/:(?!:)/) + value_expected = true + encoder.text_token match, :key + encoder.text_token ':', :operator + else + value_expected = false + if kind == :ident + if match[/\A[A-Z]/] && !(match[/[!?]$/] || match?(/\(/)) + kind = :constant + end + elsif kind == :keyword + state = patterns::KEYWORD_NEW_STATE[match] + if patterns::KEYWORDS_EXPECTING_VALUE[match] + value_expected = match == 'when' ? :colon_expected : true + end end - elsif kind == :keyword - state = patterns::KEYWORD_NEW_STATE[match] - value_expected = true if patterns::KEYWORDS_EXPECTING_VALUE[match] + value_expected = true if !value_expected && check(/#{patterns::VALUE_FOLLOWS}/o) + encoder.text_token match, kind end - value_expected = true if !value_expected && check(/#{patterns::VALUE_FOLLOWS}/o) - encoder.text_token match, kind elsif method_call_expected && match = scan(unicode ? /#{patterns::METHOD_AFTER_DOT}/uo : @@ -119,9 +128,9 @@ module Scanners value_expected = check(/#{patterns::VALUE_FOLLOWS}/o) # OPERATORS # - elsif !method_call_expected && match = scan(/ (\.(?!\.)|::) | (?: \.\.\.? | ==?=? | [,\(\[\{] )() | [\)\]\}] /x) + elsif !method_call_expected && match = scan(/ (\.(?!\.)|::) | ( \.\.\.? | ==?=? | [,\(\[\{] ) | [\)\]\}] /x) method_call_expected = self[1] - value_expected = !method_call_expected && self[2] + value_expected = !method_call_expected && !!self[2] if inline_block_stack case match when '{' @@ -213,7 +222,7 @@ module Scanners encoder.text_token match, :integer elsif match = scan(/ %=? | <(?:<|=>?)? | \? /x) - value_expected = true + value_expected = match == '?' ? :colon_expected : true encoder.text_token match, :operator elsif match = scan(/`/) |