class Treetop::Compiler::RubyBuilder
Attributes
Public Class Methods
Source
# File lib/treetop/compiler/ruby_builder.rb, line 9 def initialize @level = 0 @address_space = LexicalAddressSpace.new @ruby = String.new("") end
Public Instance Methods
Source
# File lib/treetop/compiler/ruby_builder.rb, line 15 def <<(ruby_line) return if ruby_line == '' ruby << ruby_line.tabto(level) << "\n" end
Source
# File lib/treetop/compiler/ruby_builder.rb, line 60 def accumulate(left, right) self << "#{left} << #{right}" end
Source
# File lib/treetop/compiler/ruby_builder.rb, line 48 def assign(left, right) if left.instance_of? Array self << "#{left.join(', ')} = #{right.join(', ')}" else self << "#{left} = #{right}" end end
Source
# File lib/treetop/compiler/ruby_builder.rb, line 30 def class_declaration(name, &block) self << "class #{name}" indented(&block) self << "end" end
Source
# File lib/treetop/compiler/ruby_builder.rb, line 74 def else_(&block) self << 'else' indented(&block) self << 'end' end
Source
# File lib/treetop/compiler/ruby_builder.rb, line 56 def extend(var, module_name) self << "#{var}.extend(#{module_name})" end
Source
# File lib/treetop/compiler/ruby_builder.rb, line 69 def if_(condition, &block) if__(condition, &block) self << 'end' end
Source
# File lib/treetop/compiler/ruby_builder.rb, line 64 def if__(condition, &block) self << "if #{condition}" indented(&block) end
Source
# File lib/treetop/compiler/ruby_builder.rb, line 90 def in(depth = 2) @level += depth self end
Source
# File lib/treetop/compiler/ruby_builder.rb, line 24 def indented(depth = 2) self.in(depth) yield self.out(depth) end
Source
# File lib/treetop/compiler/ruby_builder.rb, line 80 def loop(&block) self << 'loop do' indented(&block) self << 'end' end
Source
# File lib/treetop/compiler/ruby_builder.rb, line 42 def method_declaration(name, &block) self << "def #{name}" indented(&block) self << "end" end
Source
# File lib/treetop/compiler/ruby_builder.rb, line 36 def module_declaration(name, &block) self << "module #{name}" indented(&block) self << "end" end
Source
# File lib/treetop/compiler/ruby_builder.rb, line 100 def next_address address_space.next_address end
Source
# File lib/treetop/compiler/ruby_builder.rb, line 95 def out(depth = 2) @level -= depth self end
Source
# File lib/treetop/compiler/ruby_builder.rb, line 104 def reset_addresses address_space.reset_addresses end