diff options
-rw-r--r-- | lib/coderay/rule_based_scanner.rb | 4 | ||||
-rw-r--r-- | lib/coderay/scanners/c2.rb | 42 | ||||
-rw-r--r-- | lib/coderay/scanners/css2.rb | 42 | ||||
-rw-r--r-- | lib/coderay/scanners/java_script5.rb | 48 | ||||
-rw-r--r-- | lib/coderay/scanners/json5.rb | 38 | ||||
-rw-r--r-- | lib/coderay/scanners/lua2.rb | 18 |
6 files changed, 46 insertions, 146 deletions
diff --git a/lib/coderay/rule_based_scanner.rb b/lib/coderay/rule_based_scanner.rb index 3022ec9..56edcfc 100644 --- a/lib/coderay/rule_based_scanner.rb +++ b/lib/coderay/rule_based_scanner.rb @@ -369,6 +369,10 @@ module CodeRay @state = :initial end + def close_groups encoder, states + # TODO + end + end end end
\ No newline at end of file diff --git a/lib/coderay/scanners/c2.rb b/lib/coderay/scanners/c2.rb index 7ae382a..3103e54 100644 --- a/lib/coderay/scanners/c2.rb +++ b/lib/coderay/scanners/c2.rb @@ -87,40 +87,24 @@ module Scanners on %r//, pop_state # TODO: add otherwise method for this end - scan_tokens_code = <<-"RUBY" - def scan_tokens encoder, options#{ def_line = __LINE__; nil } - state = @state - label_expected = true - case_expected = false - label_expected_before_preproc_line = nil - in_preproc_line = false - - states = [state] - - until eos? - # last_pos = pos - case state -#{ @code.chomp.gsub(/^/, ' ') } - else - raise_inspect 'Unknown state: %p' % [state], encoder - end - - # raise_inspect 'nothing was consumed! states = %p' % [states], encoder if pos == last_pos - end + protected + + def setup + super - if state == :string + @label_expected = true + @case_expected = false + @label_expected_before_preproc_line = nil + @in_preproc_line = false + end + + def close_groups encoder, states + if states.last == :string encoder.end_group :string end - - encoder end - RUBY - if ENV['PUTS'] - puts CodeRay.scan(scan_tokens_code, :ruby).terminal - puts "callbacks: #{callbacks.size}" - end - class_eval scan_tokens_code, __FILE__, def_line end + end end diff --git a/lib/coderay/scanners/css2.rb b/lib/coderay/scanners/css2.rb index 4b20b79..0c0d4a0 100644 --- a/lib/coderay/scanners/css2.rb +++ b/lib/coderay/scanners/css2.rb @@ -45,14 +45,6 @@ module Scanners AttributeSelector = /(\[)([^\]]+)?(\])?/ end - protected - - def setup - @state = :initial - @value_expected = false - @block = false - end - state :initial do on %r/\s+/, :space @@ -83,36 +75,14 @@ module Scanners on %r/ [+>~,.=()\/] /x, :operator end - scan_tokens_code = <<-"RUBY" - def scan_tokens encoder, options#{ def_line = __LINE__; nil } - states = Array(options[:state] || @state).dup - value_expected = @value_expected - block = @block - state = states.last - - until eos? - case state -#{ @code.chomp.gsub(/^/, ' ') } - else - raise_inspect 'Unknown state: %p' % [state], encoder - end - end - - if options[:keep_state] - @state = states - @value_expected = value_expected - @block = block - end - - encoder - end - RUBY + protected - if ENV['PUTS'] - puts CodeRay.scan(scan_tokens_code, :ruby).terminal - puts "callbacks: #{callbacks.size}" + def setup + super + + @value_expected = false + @block = false end - class_eval scan_tokens_code, __FILE__, def_line end diff --git a/lib/coderay/scanners/java_script5.rb b/lib/coderay/scanners/java_script5.rb index bee1b26..9839d23 100644 --- a/lib/coderay/scanners/java_script5.rb +++ b/lib/coderay/scanners/java_script5.rb @@ -130,48 +130,22 @@ module Scanners # # encoder.text_token match, :comment if match # end - protected + protected - scan_tokens_code = <<-"RUBY" - def scan_tokens encoder, options#{ def_line = __LINE__; nil } - state, string_delimiter = options[:state] || @state - if string_delimiter - encoder.begin_group state - end - - value_expected = true - key_expected = false - function_expected = false - - states = [state] - - until eos? - case state -#{ @code.chomp.gsub(/^/, ' ') } - else - raise_inspect 'Unknown state: %p' % [state], encoder - end - end - - if options[:keep_state] - @state = state, string_delimiter - end - - if [:string, :regexp].include? state - encoder.end_group state - end + def setup + super - encoder + @string_delimiter = nil + @value_expected = true + @key_expected = false + @function_expected = false end - RUBY - if ENV['PUTS'] - puts CodeRay.scan(scan_tokens_code, :ruby).terminal - puts "callbacks: #{callbacks.size}" + def close_groups encoder, states + if [:string, :key, :regexp].include? states.last + encoder.end_group states.last + end end - class_eval scan_tokens_code, __FILE__, def_line - - protected def reset_instance super diff --git a/lib/coderay/scanners/json5.rb b/lib/coderay/scanners/json5.rb index dcfdd3f..8b0a8bd 100644 --- a/lib/coderay/scanners/json5.rb +++ b/lib/coderay/scanners/json5.rb @@ -41,43 +41,11 @@ module Scanners on %r/ \\ /x, :error, pop end - protected - - scan_tokens_code = <<-"RUBY" - def scan_tokens encoder, options#{ def_line = __LINE__; nil } - state = options[:state] || @state - - if [:string, :key].include? state - encoder.begin_group state - end - - states = [state] - - until eos? - case state -#{ @code.chomp.gsub(/^/, ' ') } - else - raise_inspect 'Unknown state: %p' % [state], encoder - end - end - - if options[:keep_state] - @state = state - end - - if [:string, :key].include? state - encoder.end_group state + def close_groups encoder, states + if [:string, :key].include? states.last + encoder.end_group states.last end - - encoder - end - RUBY - - if ENV['PUTS'] - puts CodeRay.scan(scan_tokens_code, :ruby).terminal - puts "callbacks: #{callbacks.size}" end - class_eval scan_tokens_code, __FILE__, def_line end diff --git a/lib/coderay/scanners/lua2.rb b/lib/coderay/scanners/lua2.rb index f48627d..fa20e9b 100644 --- a/lib/coderay/scanners/lua2.rb +++ b/lib/coderay/scanners/lua2.rb @@ -48,15 +48,6 @@ module Scanners add(PREDEFINED_CONSTANTS, :predefined_constant). add(PREDEFINED_EXPRESSIONS, :predefined) - protected - - # Scanner initialization. - def setup - super - @brace_depth = 0 - @num_equals = nil - end - state :initial, :map do on %r/\-\-\[\=*\[/, push(:long_comment, :comment), :delimiter, #--[[ long (possibly multiline) comment ]] set(:num_equals, -> (match) { match.count('=') }) # Number must match for comment end @@ -139,6 +130,15 @@ module Scanners # encoder.text_token("\\n\n", :error) # Visually appealing error indicator--otherwise users may wonder whether the highlighter cannot highlight multine strings end + protected + + def setup + super + + @brace_depth = 0 + @num_equals = nil + end + def close_groups encoder, states states.reverse_each do |state| case state |