pejuko / coderay_bash

Simple bash scanner for highlighting with coderay.
coderay_bash
MIT License
9 stars 5 forks source link

Use instance variables for state and quote #1

Closed codez closed 13 years ago

codez commented 13 years ago

When using instance instead of local variables for state and quote, it would be possible to re-use this scanner inside others (e.g. RHTML/ERB scanner with bash instead of html templates). If ERB is used within Bash quoted strings, the bash scanner continues in state :initial now after the ERB snippet instead of :quote.

pejuko commented 13 years ago

good idea. can you provide example bash file?

codez commented 13 years ago

A very simple test bash file with ERB would be

echo "Parsed at <%= Time.now %>"
echo "Executed at `Date`"

The ERB Bash scanner (based on Coderay RHTML and your Bash scanner) would then be very simple:

module CodeRay
  module Scanners
    class ErbBash < RHTML
      register_for :erb_bash

      protected
      def setup
        super
        # Scan Bash instead of HTML template
        @html_scanner = CodeRay.scanner :bash, :tokens => @tokens, :keep_tokens => true
      end
    end
  end
end
pejuko commented 13 years ago

I've added your ErbBash scanner to the git, made state and quote instance variables and add test for :erb_bash. I released it as v0.2.0 gem.

thx!

codez commented 13 years ago

Great, we are using it already in our application.