Class: RPStringScanner

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

Instance Method Summary collapse

Instance Method Details

#current_lineObject

end



33
34
35
# File 'lib/ruby_parser/ruby_parser_extras.rb', line 33

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

#extra_lines_addedObject



37
38
39
# File 'lib/ruby_parser/ruby_parser_extras.rb', line 37

def extra_lines_added
  @extra_lines_added ||= 0
end

#extra_lines_added=(val) ⇒ Object



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

def extra_lines_added= val
  @extra_lines_added = val
end

#getchObject



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

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

#linenoObject



45
46
47
# File 'lib/ruby_parser/ruby_parser_extras.rb', line 45

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

#old_getchObject



59
# File 'lib/ruby_parser/ruby_parser_extras.rb', line 59

alias :old_getch :getch

#old_scanObject



66
# File 'lib/ruby_parser/ruby_parser_extras.rb', line 66

alias :old_scan :scan

#scan(re) ⇒ Object



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

def scan re
  s = old_scan re
  p :scan => [s, caller.first] if s
  s
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



52
53
54
55
56
# File 'lib/ruby_parser/ruby_parser_extras.rb', line 52

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")
  string[pos, 0] = str
end