class Treetop::Compiler::RubyBuilder
def <<(ruby_line)
def <<(ruby_line) return if ruby_line.blank? ruby << ruby_line.tabto(level) << "\n" end
def accumulate(left, right)
def accumulate(left, right) self << "#{left} << #{right}" end
def assign(left, right)
def assign(left, right) if left.instance_of? Array self << "#{left.join(', ')} = #{right.join(', ')}" else self << "#{left} = #{right}" end end
def break
def break self << 'break' end
def class_declaration(name, &block)
def class_declaration(name, &block) self << "class #{name}" indented(&block) self << "end" end
def else_(&block)
def else_(&block) self << 'else' indented(&block) self << 'end' end
def extend(var, module_name)
def extend(var, module_name) self << "#{var}.extend(#{module_name})" end
def if_(condition, &block)
def if_(condition, &block) if__(condition, &block) self << 'end' end
def if__(condition, &block)
def if__(condition, &block) self << "if #{condition}" indented(&block) end
def in(depth = 2)
def in(depth = 2) @level += depth self end
def indent
def indent " " * level end
def indented(depth = 2)
def indented(depth = 2) self.in(depth) yield self.out(depth) end
def initialize
def initialize @level = 0 @address_space = LexicalAddressSpace.new @ruby = "" end
def loop(&block)
def loop(&block) self << 'loop do' indented(&block) self << 'end' end
def method_declaration(name, &block)
def method_declaration(name, &block) self << "def #{name}" indented(&block) self << "end" end
def module_declaration(name, &block)
def module_declaration(name, &block) self << "module #{name}" indented(&block) self << "end" end
def newline
def newline ruby << "\n" end
def next_address
def next_address address_space.next_address end
def out(depth = 2)
def out(depth = 2) @level -= depth self end
def reset_addresses
def reset_addresses address_space.reset_addresses end