Sha256: 791f94f2236e6f4686c31fb7e90f4f4cf1e855959f1f9d0b3ab34112e6170529

Contents?: true

Size: 1.25 KB

Versions: 11

Compression:

Stored size: 1.25 KB

Contents

module CodeRay
module Scanners

  # = Debug Scanner
  class Debug < Scanner

    include Streamable
    register_for :debug
    file_extension 'raydebug'
    title 'CodeRay Token Dump'

  protected
    def scan_tokens tokens, options

      opened_tokens = []

      until eos?

        kind = nil
        match = nil

          if scan(/\s+/)
            tokens << [matched, :space]
            next
            
          elsif scan(/ (\w+) \( ( [^\)\\]* ( \\. [^\)\\]* )* ) \) /x)
            kind = self[1].to_sym
            match = self[2].gsub(/\\(.)/, '\1')
            
          elsif scan(/ (\w+) < /x)
            kind = self[1].to_sym
            opened_tokens << kind
            match = :open
            
          elsif !opened_tokens.empty? && scan(/ > /x)
            kind = opened_tokens.pop || :error
            match = :close
            
          else
            kind = :error
            getch

          end
                  
        match ||= matched
        if $CODERAY_DEBUG and not kind
          raise_inspect 'Error token %p in line %d' %
            [[match, kind], line], tokens
        end
        raise_inspect 'Empty token', tokens unless match

        tokens << [match, kind]
        
      end
      
      tokens
    end

  end

end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
coderay-0.9.8 ./lib/coderay/scanners/debug.rb
coderay-0.9.8.pre ./lib/coderay/scanners/debug.rb
coderay-0.9.7 ./lib/coderay/scanners/debug.rb
coderay-0.9.7.pre ./lib/coderay/scanners/debug.rb
coderay-0.9.6 ./lib/coderay/scanners/debug.rb
coderay-0.9.6.pre2 ./lib/coderay/scanners/debug.rb
coderay-0.9.6.pre ./lib/coderay/scanners/debug.rb
coderay-0.9.5 ./lib/coderay/scanners/debug.rb
coderay-0.9.4 ./lib/coderay/scanners/debug.rb
coderay-0.9.3 ./lib/coderay/scanners/debug.rb
coderay-0.9.2 ./lib/coderay/scanners/debug.rb