Parent

Files

Class/Module Index [+]

Quicksearch

Treetop::Compiler::GrammarCompiler

Public Instance Methods

compile(source_path, target_path = source_path.gsub(/\.(treetop|tt)\Z/, '.rb')) click to toggle source
# File lib/treetop/compiler/grammar_compiler.rb, line 5
def compile(source_path, target_path = source_path.gsub(/\.(treetop|tt)\Z/, '.rb'))
  File.open(target_path, 'w') do |target_file|
    target_file.write(AUTOGENERATED+"\n\n")
    target_file.write(ruby_source(source_path))
  end
end
ruby_source(source_path) click to toggle source

compile a treetop file into ruby

# File lib/treetop/compiler/grammar_compiler.rb, line 13
def ruby_source(source_path)
  ruby_source_from_string(File.read(source_path))
end
ruby_source_from_string(s) click to toggle source

compile a string containing treetop source into ruby

# File lib/treetop/compiler/grammar_compiler.rb, line 18
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

[Validate]

Generated with the Darkfish Rdoc Generator 2.