Class: CodeRay::Scanners::HAML

### Home Classes Methods

### In Files

- lib/coderay/scanners/haml.rb

### Parent

CodeRay::Scanners::Scanner

### Methods

- #scan_tokens
- #setup

### Class/Module Index

Quicksearch

- CodeRay
- CodeRay::Duo
- CodeRay::Encoders
- CodeRay::Encoders::CommentFilter
- CodeRay::Encoders::Count
- CodeRay::Encoders::Debug
- CodeRay::Encoders::DebugLint
- CodeRay::Encoders::Div
- CodeRay::Encoders::Encoder
- CodeRay::Encoders::Filter
- CodeRay::Encoders::HTML
- CodeRay::Encoders::HTML::Output
- CodeRay::Encoders::JSON
- CodeRay::Encoders::LinesOfCode
- CodeRay::Encoders::Lint
- CodeRay::Encoders::Null
- CodeRay::Encoders::Page
- CodeRay::Encoders::Span
- CodeRay::Encoders::Statistic
- CodeRay::Encoders::Terminal
- CodeRay::Encoders::Text
- CodeRay::Encoders::TokenKindFilter
- CodeRay::Encoders::XML
- CodeRay::Encoders::YAML
- CodeRay::FileType
- CodeRay::ForRedCloth
- CodeRay::Plugin
- CodeRay::PluginHost
- CodeRay::Scanners
- CodeRay::Scanners::C
- CodeRay::Scanners::CPlusPlus
- CodeRay::Scanners::CSS
- CodeRay::Scanners::Clojure
- CodeRay::Scanners::Debug
- CodeRay::Scanners::Delphi
- CodeRay::Scanners::Diff
- CodeRay::Scanners::ERB
- CodeRay::Scanners::Go
- CodeRay::Scanners::Groovy
- CodeRay::Scanners::HAML
- CodeRay::Scanners::HTML
- CodeRay::Scanners::JSON
- CodeRay::Scanners::Java
- CodeRay::Scanners::JavaScript
- CodeRay::Scanners::Python
- CodeRay::Scanners::Raydebug
- CodeRay::Scanners::Ruby
- CodeRay::Scanners::SQL
- CodeRay::Scanners::Sass
- CodeRay::Scanners::Scanner
- CodeRay::Scanners::Taskpaper
- CodeRay::Scanners::Text
- CodeRay::Scanners::XML
- CodeRay::Scanners::YAML
- CodeRay::Styles
- CodeRay::Styles::Alpha
- CodeRay::Styles::Style
- CodeRay::Tokens
- CodeRay::TokensProxy
- CodeRay::WordList
- CodeRay::WordList::CaseIgnoring

No matching classes.

# CodeRay::Scanners::HAML

### Constants

KINDS_NOT_LOC

### Protected Instance Methods

scan_tokens(encoder, options) click to toggle source

    # File lib/coderay/scanners/haml.rb, line 24
    def scan_tokens encoder, options

      match = nil
      code = ''

      until eos?

        if bol?
          if match = scan(/!!!.*/)
            encoder.text_token match, :doctype
            next
          end

          if match = scan(/(?>( *)(\/(?!\[if)|-\#|:javascript|:ruby|:\w+) *)(?=\n)/)
            encoder.text_token match, :comment

            code = self[2]
            if match = scan(/(?:\n+#{self[1]} .*)+/)
              case code
              when '/', '-#'
                encoder.text_token match, :comment
              when ':javascript'
                # TODO: recognize #{...} snippets inside JavaScript
                @java_script_scanner ||= CodeRay.scanner :java_script, :tokens => @tokens, :keep_tokens => true
                @java_script_scanner.tokenize match, :tokens => encoder
              when ':ruby'
                @ruby_scanner.tokenize match, :tokens => encoder
              when /:\w+/
                encoder.text_token match, :comment
              else
                raise 'else-case reached: %p' % [code]
              end
            end
          end

          if match = scan(/ +/)
            encoder.text_token match, :space
          end

          if match = scan(/\/.*/)
            encoder.text_token match, :comment
            next
          end

          if match = scan(/\\/)
            encoder.text_token match, :plain
            if match = scan(/.+/)
              @html_scanner.tokenize match, :tokens => encoder
            end
            next
          end

          tag = false

          if match = scan(/%[\w:]+\/?/)
            encoder.text_token match, :tag
            # if match = scan(/( +)(.+)/)
            #   encoder.text_token self[1], :space
            #   @embedded_ruby_scanner.tokenize self[2], :tokens => encoder
            # end
            tag = true
          end

          while match = scan(/([.#])[-\w]*\w/)
            encoder.text_token match, self[1] == '#' ? :constant : :class
            tag = true
          end

          if tag && match = scan(/(\()([^)]+)?(\))?/)
            # TODO: recognize title=@title, class="widget_#{@widget.number}"
            encoder.text_token self[1], :plain
            @html_scanner.tokenize self[2], :tokens => encoder, :state => :attribute if self[2]
            encoder.text_token self[3], :plain if self[3]
          end

          if tag && match = scan(/\{/)
            encoder.text_token match, :plain

            code = ''
            level = 1
            while true
              code << scan(/([^\{\},\n]|, *\n?)*/)
              case match = getch
              when '{'
                level += 1
                code << match
              when '}'
                level -= 1
                if level > 0
                  code << match
                else
                  break
                end
              when "\n", ",", nil
                break
              end
            end
            @ruby_scanner.tokenize code, :tokens => encoder unless code.empty?

            encoder.text_token match, :plain if match
          end

          if tag && match = scan(/(\[)([^\]\n]+)?(\])?/)
            encoder.text_token self[1], :plain
            @ruby_scanner.tokenize self[2], :tokens => encoder if self[2]
            encoder.text_token self[3], :plain if self[3]
          end

          if tag && match = scan(/\//)
            encoder.text_token match, :tag
          end

          if scan(/(>?<?[-=]|[&!]=|(& |!)|~)( *)([^,\n\|]+(?:(, *|\|(?=.|\n.*\|$))\n?[^,\n\|]*)*)?/)
            encoder.text_token self[1] + self[3], :plain
            if self[4]
              if self[2]
                @embedded_ruby_scanner.tokenize self[4], :tokens => encoder
              else
                @ruby_scanner.tokenize self[4], :tokens => encoder
              end
            end
          elsif match = scan(/((?:<|><?)(?![!?\/\w]))?(.+)?/)
            encoder.text_token self[1], :plain if self[1]
            # TODO: recognize #{...} snippets
            @html_scanner.tokenize self[2], :tokens => encoder if self[2]
          end

        elsif match = scan(/.+/)
          @html_scanner.tokenize match, :tokens => encoder

        end

        if match = scan(/\n/)
          encoder.text_token match, :space
        end
      end

      encoder

    end

setup() click to toggle source

    # File lib/coderay/scanners/haml.rb, line 17
    def setup
      super
      @ruby_scanner          = CodeRay.scanner :ruby, :tokens => @tokens, :keep_tokens => true
      @embedded_ruby_scanner = CodeRay.scanner :ruby, :tokens => @tokens, :keep_tokens => true, :state => @ruby_scanner.interpreted_string_state
      @html_scanner          = CodeRay.scanner :html, :tokens => @tokens, :keep_tokens => true
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.