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)


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

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

#current_lineObject

end



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

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

#getchObject



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

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

#linenoObject



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

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

#old_getchObject



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

alias :old_getch :getch

#old_scanObject



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

alias :old_scan :scan

#scan(re) ⇒ Object



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

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



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

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



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

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



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

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