diff options
author | Kornelius Kalnbach <murphy@rubychan.de> | 2016-02-14 15:11:18 +0100 |
---|---|---|
committer | Kornelius Kalnbach <murphy@rubychan.de> | 2016-02-14 15:11:18 +0100 |
commit | 9526bd86b6420e868bee1da167e40afc11ed1c0b (patch) | |
tree | cb7478701a2ca66bfa5241868bfb8e2248d99f06 /lib/coderay/scanners | |
parent | dcf73a6b5bae19a6592f4be17105005474cec2d3 (diff) | |
download | coderay-9526bd86b6420e868bee1da167e40afc11ed1c0b.tar.gz |
generate scanner code automatically
Diffstat (limited to 'lib/coderay/scanners')
-rw-r--r-- | lib/coderay/scanners/lua2.rb | 36 |
1 files changed, 8 insertions, 28 deletions
diff --git a/lib/coderay/scanners/lua2.rb b/lib/coderay/scanners/lua2.rb index 1aba769..f48627d 100644 --- a/lib/coderay/scanners/lua2.rb +++ b/lib/coderay/scanners/lua2.rb @@ -139,38 +139,18 @@ module Scanners # encoder.text_token("\\n\n", :error) # Visually appealing error indicator--otherwise users may wonder whether the highlighter cannot highlight multine strings end - scan_tokens_code = <<-"RUBY" - def scan_tokens encoder, options#{ def_line = __LINE__; nil } - state = options[:state] || @state - brace_depth = @brace_depth - num_equals = nil - - states = [state] - - until eos? + def close_groups encoder, states + states.reverse_each do |state| case state -#{ @code.chomp.gsub(/^/, ' ') } - else - raise_inspect 'Unknown state: %p' % [state], encoder + when :long_string, :single_quoted_string, :double_quoted_string + encoder.end_group :string + when :long_comment + encoder.end_group :long_comment + when :map + encoder.end_group :map end end - - if options[:keep_state] - @state = state - end - - encoder.end_group :string if [:string, :single_quoted_string, :double_quoted_string].include? state - brace_depth.times { encoder.end_group :map } - - 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 |