From 3d8868dd0b9898d589ecdff5151ed5d47956f937 Mon Sep 17 00:00:00 2001 From: murphy Date: Sat, 1 Oct 2005 06:04:52 +0000 Subject: Demos updated, rewritten, enhanced, tested. Some code cleanups. Bugs fixed, scanner and encoder improved: count.rb: marked Streamable html_css.rb: style for inline numbers html.rb: changed options; :line_numbers_offset is now :line_number_start html_output.rb: offset for inline numbers fixed html.rb: token text no longer changed by gsub! while highlighting (this is even faster!) text.rb, plugin.rb: reindented ruby.rb: eleminated multiple assignments for speed tokens.rb: reindented, Tokens#to_s added, #<< returns self Plugin system: bugs fixed, error messages improved. --- demo/demo_scanner.rb | 34 +++++++++++++++++++++++++++++----- 1 file changed, 29 insertions(+), 5 deletions(-) (limited to 'demo/demo_scanner.rb') diff --git a/demo/demo_scanner.rb b/demo/demo_scanner.rb index a250f91..6a0245e 100644 --- a/demo/demo_scanner.rb +++ b/demo/demo_scanner.rb @@ -1,12 +1,36 @@ require 'coderay' -c_scanner = CodeRay::Scanners[:c].new "if (*p == '{') nest++;" + +c_code = "if (*p == '{') nest++;" +puts 'C Code: ' + c_code +puts + +c_scanner = CodeRay::Scanners[:c].new c_code + +puts '> print only operators:' for text, kind in c_scanner print text if kind == :operator end puts +puts '-' * 30 +puts -ruby_scanner = CodeRay::Scanners[:ruby].new %q +ruby_code = %q!ruby_code(:can, BE, %r[q[ui]te #{ /comple/x },] => $-s, &?\xee)! +puts 'Ruby Code: ' + ruby_code +puts + +ruby_scanner = CodeRay::Scanners[:ruby].new ruby_code + +puts '> has a string?' +puts ruby_scanner. + any? { |text, kind| kind == :string } +puts + +puts '> number of regexps?' +puts ruby_scanner. + select { |token| token == [:open, :regexp] }.size +puts -puts ruby_scanner.any? { |text, kind| kind == :string and text == :open} -puts ruby_scanner.find { |text, kind| kind == :regexp } -puts ruby_scanner.map { |text, kind| text if kind != :space }.compact.join(' ') +puts '> has a string?' +puts ruby_scanner. + reject { |text, kind| not text.is_a? String }. + map { |text, kind| %("#{text}" (#{kind})) }.join(', ') -- cgit v1.2.1