summaryrefslogtreecommitdiff
path: root/ext/ripper/lib/ripper/filter.rb
diff options
context:
space:
mode:
authoraamine <aamine@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2004-09-22 05:22:50 +0000
committeraamine <aamine@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2004-09-22 05:22:50 +0000
commit2c179216717d75837de7a6ff092fd773670f4d11 (patch)
tree6a275ae9914fc4157c21a36402ce9d87a250fa8a /ext/ripper/lib/ripper/filter.rb
parent61d1dce5a226d3bf8393fd10777db09b046f68e6 (diff)
* parse.y [ripper]: on__scan event removed.
* parse.y [ripper]: event name is changed: on__XXX -> on_XXX. * ext/ripper/eventids2.c: ditto. * ext/ripper/ripper.rb.in: ditto. * ext/ripper/lib/ripper.rb: sync with ripper.rb.in. * ext/ripper/lib/ripper/tokenizer: ditto. * ext/ripper/lib/ripper/filter: new file. * sample/ripper/colorize.rb: new file. * sample/ripper/strip-comment.rb: new file. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6952 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/ripper/lib/ripper/filter.rb')
-rw-r--r--ext/ripper/lib/ripper/filter.rb55
1 files changed, 55 insertions, 0 deletions
diff --git a/ext/ripper/lib/ripper/filter.rb b/ext/ripper/lib/ripper/filter.rb
new file mode 100644
index 0000000000..399c4c64bc
--- /dev/null
+++ b/ext/ripper/lib/ripper/filter.rb
@@ -0,0 +1,55 @@
+#
+# ripper/filter.rb
+#
+# Copyright (C) 2004 Minero Aoki
+#
+# This program is free software.
+# You can distribute and/or modify this program under the Ruby License.
+# For details of Ruby License, see ruby/COPYING.
+#
+
+require 'ripper'
+
+class Ripper
+
+ class Filter
+
+ def initialize(src, filename = '-', lineno = 1)
+ @__parser = Tokenizer.new(src, filename, lineno)
+ @__line = nil
+ @__col = nil
+ end
+
+ def filename
+ @__parser.filename
+ end
+
+ def lineno
+ @__line
+ end
+
+ def column
+ @__col
+ end
+
+ def parse(init)
+ data = init
+ @__parser.parse.each do |pos, event, tok|
+ @__line, @__col = *pos
+ data = if respond_to?(event, true)
+ then __send__(event, tok, data)
+ else on_default(event, tok, data)
+ end
+ end
+ data
+ end
+
+ private
+
+ def on_default(event, tok, data)
+ data
+ end
+
+ end
+
+end