2 # $Id: filter.rb 11708 2007-02-12 23:01:19Z shyouhei $
4 # Copyright (c) 2004,2005 Minero Aoki
6 # This program is free software.
7 # You can distribute and/or modify this program under the Ruby License.
8 # For details of Ruby License, see ruby/COPYING.
11 require 'ripper/lexer'
15 # This class handles only scanner events,
16 # and they are dispatched in the `right' order (same with input).
19 def initialize(src, filename = '-', lineno = 1)
20 @__lexer = Lexer.new(src, filename, lineno)
25 # The file name of the input.
30 # The line number of the current token.
31 # This value starts from 1.
32 # This method is valid only in event handlers.
37 # The column number of the current token.
38 # This value starts from 0.
39 # This method is valid only in event handlers.
44 # Starts parsing. _init_ is a data accumulator.
45 # It is passed to the next event handler (as of Enumerable#inject).
48 @__lexer.lex.each do |pos, event, tok|
49 @__line, @__col = *pos
50 data = if respond_to?(event, true)
51 then __send__(event, tok, data)
52 else on_default(event, tok, data)
60 # This method is called when some event handler have not defined.
61 # _event_ is :on_XXX, _token_ is scanned token, _data_ is a data
62 # accumulator. The return value of this method is passed to the
63 # next event handler (as of Enumerable#inject).
64 def on_default(event, token, data)