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)


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

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

#current_lineObject

end



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

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

#getchObject



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

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

#linenoObject



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

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

#old_getchObject



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

alias :old_getch :getch

#old_scanObject



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

alias :old_scan :scan

#scan(re) ⇒ Object



69
70
71
72
73
# File 'lib/ruby_parser_extras.rb', line 69

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



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

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



47
48
49
50
# File 'lib/ruby_parser_extras.rb', line 47

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

#was_begin_of_lineObject

TODO: kill me



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

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