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 / b9 / b982f3bb626cbc93a53ddb7f7ab16811202b4d33.svn-base @ 1297:0a574315af3e

History | View | Annotate | Download (1.04 KB)

1
module CodeRay
2
module Encoders
3
  
4
  # A Filter encoder has another Tokens instance as output.
5
  # It can be subclass to select, remove, or modify tokens in the stream.
6
  # 
7
  # Subclasses of Filter are called "Filters" and can be chained.
8
  # 
9
  # == Options
10
  # 
11
  # === :tokens
12
  # 
13
  # The Tokens object which will receive the output.
14
  # 
15
  # Default: Tokens.new
16
  # 
17
  # See also: TokenKindFilter
18
  class Filter < Encoder
19
    
20
    register_for :filter
21
    
22
  protected
23
    def setup options
24
      super
25
      
26
      @tokens = options[:tokens] || Tokens.new
27
    end
28
    
29
    def finish options
30
      output @tokens
31
    end
32
    
33
  public
34
    
35
    def text_token text, kind  # :nodoc:
36
      @tokens.text_token text, kind
37
    end
38
    
39
    def begin_group kind  # :nodoc:
40
      @tokens.begin_group kind
41
    end
42
    
43
    def begin_line kind  # :nodoc:
44
      @tokens.begin_line kind
45
    end
46
    
47
    def end_group kind  # :nodoc:
48
      @tokens.end_group kind
49
    end
50
    
51
    def end_line kind  # :nodoc:
52
      @tokens.end_line kind
53
    end
54
    
55
  end
56
  
57
end
58
end