C
Chiyuan Zhang
Hi!
I'm wondering if Treetop can provide (or is it already have?) a
mechanize like this:
module MyModule
Treetop.load("my")
end
so that I'll get a MyModule::MyParser instead of a top-level MyParser.
Or something like:
Treetop.load_into("my", MyModule)
which might be implemented like the original `load':
# def self.load(path)
def self.load_into(path, module)
adjusted_path = path =~ /\.(treetop|tt)\Z/ ? path : path + '.treetop'
compiler = Treetop::Compiler::GrammarCompiler.new
# Object.class_eval(compiler.ruby_source(adjusted_path))
module.class_eval(compiler.ruby_source(adjusted_path))
end
Any idea? Thanks!
I'm wondering if Treetop can provide (or is it already have?) a
mechanize like this:
module MyModule
Treetop.load("my")
end
so that I'll get a MyModule::MyParser instead of a top-level MyParser.
Or something like:
Treetop.load_into("my", MyModule)
which might be implemented like the original `load':
# def self.load(path)
def self.load_into(path, module)
adjusted_path = path =~ /\.(treetop|tt)\Z/ ? path : path + '.treetop'
compiler = Treetop::Compiler::GrammarCompiler.new
# Object.class_eval(compiler.ruby_source(adjusted_path))
module.class_eval(compiler.ruby_source(adjusted_path))
end
Any idea? Thanks!