class Treetop::Compiler::GrammarCompiler

def compile(source_path, target_path = source_path.gsub(/\.(treetop|tt)\Z/, '.rb'))

def compile(source_path, target_path = source_path.gsub(/\.(treetop|tt)\Z/, '.rb'))
  File.open(target_path, 'w') do |target_file|
    target_file.write(ruby_source(source_path))
  end
end

def ruby_source(source_path)

compile a treetop file into ruby
def ruby_source(source_path)
  ruby_source_from_string(File.read(source_path))
end

def ruby_source_from_string(s)

compile a string containing treetop source into ruby
def ruby_source_from_string(s)
  parser = MetagrammarParser.new
  result = parser.parse(s)
  unless result
    raise RuntimeError.new(parser.failure_reason)
  end
  result.compile
end