From 591b2823d986bc877697e3bd485ffa9c9adff3ed Mon Sep 17 00:00:00 2001 From: murphy Date: Tue, 18 May 2010 06:24:16 +0000 Subject: Ruby scanner handles :keep_state option. --- Changes.textile | 1 + lib/coderay/scanners/ruby.rb | 13 ++++++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/Changes.textile b/Changes.textile index dc9752e..aa0d640 100644 --- a/Changes.textile +++ b/Changes.textile @@ -164,6 +164,7 @@ h3. @Scanners::Ruby@ * *NEW*: Highlight buggy floats (like .5) as @:error@. * *CLEANUP* of documentation, names of constants and variables, state handling. * *NEW*: Complicated rule for recognition of @foo=@ style method names. +* *NEW*: Handles @:keep_state@ option (a bit; experimental). Actually, Ruby checks if there is @[~>=]@, but not @=>@ following the name. diff --git a/lib/coderay/scanners/ruby.rb b/lib/coderay/scanners/ruby.rb index a2e5fed..923d681 100644 --- a/lib/coderay/scanners/ruby.rb +++ b/lib/coderay/scanners/ruby.rb @@ -28,11 +28,19 @@ module Scanners protected + def setup + @state = :initial + end + def scan_tokens encoder, options patterns = Patterns # avoid constant lookup - state = :initial + state = @state + if state.instance_of? patterns::StringState + encoder.begin_group state.type + end + last_state = nil method_call_expected = false @@ -414,6 +422,9 @@ module Scanners end # cleaning up + if options[:keep_state] + @state = state + end if state.is_a? patterns::StringState encoder.end_group state.type end -- cgit v1.2.1