Class: RPStringScanner

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

Instance Method Summary collapse

Instance Method Details

#begin_of_line?Boolean

Returns:

  • (Boolean)


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

def begin_of_line?
  pos == 0 or string[pos-1] == ?\n
end

#current_lineObject

end



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

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

#extra_lines_addedObject



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

def extra_lines_added
  @extra_lines_added ||= 0
end

#extra_lines_added=(val) ⇒ Object



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

def extra_lines_added= val
  @extra_lines_added = val
end

#getchObject



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

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

#linenoObject



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

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

#old_getchObject



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

alias :old_getch :getch

#old_scanObject



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

alias :old_scan :scan

#scan(re) ⇒ Object



79
80
81
82
83
# File 'lib/ruby_parser_extras.rb', line 79

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

#unread(c) ⇒ 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



50
51
52
53
54
# File 'lib/ruby_parser_extras.rb', line 50

def unread c # TODO: remove this entirely - we should not need it
  return if c.nil? # UGH
  warn({:unread => caller[0]}.inspect) if ENV['TALLY']
  string[pos, 0] = c
end

#unread_many(str) ⇒ Object

TODO: remove this entirely - we should not need it



56
57
58
59
60
# File 'lib/ruby_parser_extras.rb', line 56

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

#was_begin_of_lineObject

TODO: kill me



66
67
68
# File 'lib/ruby_parser_extras.rb', line 66

def was_begin_of_line # TODO: kill me
  pos <= 2 or string[pos-2] == ?\n
end