— lib/ruby_lexer.rb 2008-04-27 01:07:24.000000000 +0200 +++ lib/ruby_lexer.rb 2008-04-27 01:07:03.000000000 +0200 @@ -45,7 +45,7 @@

raise "bad val: #{str.inspect}" unless String === str

self.file = file

+ self.lexer.src = RubyParser::StringIO.new(str)

@yydebug = ENV.has_key? 'DEBUG'

@@ -2604,104 +2604,106 @@

  end
end

-class StringIO # HACK: everything in here is a hack

+class RubyParser + class StringIO < StringIO # HACK: everything in here is a hack + attr_accessor :begin_of_line, :was_begin_of_line + alias :begin_of_line? :begin_of_line + alias :read_all :read

+ alias :old_initialize :initialize

+ def initialize(*args) + self.begin_of_line = true + self.was_begin_of_line = false + old_initialize(*args) + @original_string = self.string.dup + end

+ def rest + self.string + end

+ def current_line # HAHA fuck you + @original_string[/A.*__LINE__/m].split(/n/).size + end

+ def read + c = self.getc

+ if c == ?r then + d = self.getc + self.ungetc d if d and d != ?n + c = ?n + end

+ self.was_begin_of_line = self.begin_of_line + self.begin_of_line = c == ?n + if c and c != 0 then + c.chr + else + ::RubyLexer::EOF + end

end

+ def match_string term, indent=false # TODO: add case insensitivity, or just remove + buffer = []

+ if indent + while c = self.read do + if c !~ /s/ or c == “n” or c == “r” then + self.unread c + break + end + buffer << c

end
end

+ term.each_byte do |c2| + c = self.read + c = self.read if c and c == “r” + buffer << c + if c and c2 != c then + self.unread_many buffer.join # HACK omg + return false + end

end

+ + return true

end

+ def read_line + self.begin_of_line = true + self.was_begin_of_line = false + gets.sub(/rn?$/, “n”) # HACK + end

-

+ def peek expected = nil # FIX: barf + c = self.getc + return RubyLexer::EOF if c.nil? + self.ungetc c if c + c = c.chr if c + if expected then + c == expected + else + c + end

end

+ def unread© + return if c.nil? # UGH

+ # HACK: only depth is 2… who cares? really I want to remove all of this + self.begin_of_line = self.was_begin_of_line || true + self.was_begin_of_line = nil

+ c = c if String === c + self.ungetc c + end

+ def unread_many str + str.split(//).reverse.each do |c| + unread c + end

    end
  end
end