Class: RPStringScanner

Inherits:
StringScanner
  • Object
show all
Defined in:
lib/ruby_parser_extras.rb

Instance Method Summary collapse

Instance Method Details

#current_lineObject

HAHA fuck you (HACK)



60
61
62
# File 'lib/ruby_parser_extras.rb', line 60

def current_line # HAHA fuck you (HACK)
  string_to_pos[/\A.*__LINE__/m].split(/\n/).size
end

#d(o) ⇒ Object



105
106
107
# File 'lib/ruby_parser_extras.rb', line 105

def d o
  $stderr.puts o.inspect
end

#extra_lines_addedObject



64
65
66
# File 'lib/ruby_parser_extras.rb', line 64

def extra_lines_added
  @extra_lines_added ||= 0
end

#extra_lines_added=(val) ⇒ Object



68
69
70
# File 'lib/ruby_parser_extras.rb', line 68

def extra_lines_added= val
  @extra_lines_added = val
end

#getchObject



91
92
93
94
95
# File 'lib/ruby_parser_extras.rb', line 91

def getch
  c = self.old_getch
  p :getch => [c, caller.first]
  c
end

#linenoObject



72
73
74
# File 'lib/ruby_parser_extras.rb', line 72

def lineno
  string[0...charpos].count("\n") + 1 - extra_lines_added
end

#old_getchObject



90
# File 'lib/ruby_parser_extras.rb', line 90

alias :old_getch :getch

#old_scanObject



97
# File 'lib/ruby_parser_extras.rb', line 97

alias :old_scan :scan

#scan(re) ⇒ Object



98
99
100
101
102
# File 'lib/ruby_parser_extras.rb', line 98

def scan re
  s = old_scan re
  d :scan => [s, caller.first] if s
  s
end

#string_to_posObject



40
41
42
# File 'lib/ruby_parser_extras.rb', line 40

def string_to_pos
  string.byteslice(0, pos)
end

#unread_many(str) ⇒ Object

TODO: once we get rid of these, we can make things like TODO: current_line and lineno much more accurate and easy to do



79
80
81
82
83
84
85
86
87
# File 'lib/ruby_parser_extras.rb', line 79

def unread_many str # TODO: remove this entirely - we should not need it
  warn({:unread_many => caller[0]}.inspect) if ENV['TALLY']
  self.extra_lines_added += str.count("\n") - 1
  begin
    string[charpos, 0] = str
  rescue IndexError
    # HACK -- this is a bandaid on a dirty rag on an open festering wound
  end
end