To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.

Statistics Download as Zip
| Branch: | Tag: | Revision:

root / .svn / pristine / 76 / 7653b9d7574c0a4c89892ba03eb88b9209dbb271.svn-base @ 1297:0a574315af3e

History | View | Annotate | Download (1.57 KB)

1
module CodeRay
2
module Scanners
3

    
4
  # = Debug Scanner
5
  # 
6
  # Parses the output of the Encoders::Debug encoder.
7
  class Raydebug < Scanner
8

    
9
    register_for :raydebug
10
    file_extension 'raydebug'
11
    title 'CodeRay Token Dump'
12
    
13
  protected
14
    
15
    def scan_tokens encoder, options
16

    
17
      opened_tokens = []
18

    
19
      until eos?
20

    
21
        if match = scan(/\s+/)
22
          encoder.text_token match, :space
23
          
24
        elsif match = scan(/ (\w+) \( ( [^\)\\]* ( \\. [^\)\\]* )* ) /x)
25
          kind = self[1]
26
          encoder.text_token kind, :class
27
          encoder.text_token '(', :operator
28
          match = self[2]
29
          encoder.text_token match, kind.to_sym
30
          encoder.text_token match, :operator if match = scan(/\)/)
31
          
32
        elsif match = scan(/ (\w+) ([<\[]) /x)
33
          kind = self[1]
34
          case self[2]
35
          when '<'
36
            encoder.text_token kind, :class
37
          when '['
38
            encoder.text_token kind, :class
39
          else
40
            raise 'CodeRay bug: This case should not be reached.'
41
          end
42
          kind = kind.to_sym
43
          opened_tokens << kind
44
          encoder.begin_group kind
45
          encoder.text_token self[2], :operator
46
          
47
        elsif !opened_tokens.empty? && match = scan(/ [>\]] /x)
48
          encoder.text_token match, :operator
49
          encoder.end_group opened_tokens.pop
50
          
51
        else
52
          encoder.text_token getch, :space
53
          
54
        end
55
        
56
      end
57
      
58
      encoder.end_group opened_tokens.pop until opened_tokens.empty?
59
      
60
      encoder
61
    end
62

    
63
  end
64

    
65
end
66
end