File: rp_stringscanner.rb

package info (click to toggle)
ruby-ruby-parser 3.21.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 7,728 kB
  • sloc: ruby: 136,318; yacc: 6,245; makefile: 11
file content (33 lines) | stat: -rw-r--r-- 678 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
require "strscan"

class RPStringScanner < StringScanner
  if ENV["DEBUG"] || ENV["TALLY"] then
    def getch
      c = super
      where = caller.drop_while { |s| s =~ /(getch|nextc).$/ }.first
      where = where.split(/:/).first(2).join(":")
      if ENV["TALLY"] then
        d getch:where
      else
        d getch:[c, where]
      end
      c
    end

    def scan re
      s = super
      where = caller.drop_while { |x| x =~ /scan.$/ }.first
      where = where.split(/:/).first(2).join(":")
      if ENV["TALLY"] then
        d scan:[where]
      else
        d scan:[s, where] if s
      end
      s
    end

    def d o
      STDERR.puts o.inspect
    end
  end
end