Class: Treetop::Compiler::GrammarCompiler
- Inherits:
-
Object
- Object
- Treetop::Compiler::GrammarCompiler
- Defined in:
- lib/treetop/compiler/grammar_compiler.rb
Instance Method Summary collapse
- #compile(source_path, target_path = source_path.gsub(/\.(treetop|tt)\Z/, '.rb')) ⇒ Object
- #ruby_source(source_path) ⇒ Object
Instance Method Details
#compile(source_path, target_path = source_path.gsub(/\.(treetop|tt)\Z/, '.rb')) ⇒ Object
4 5 6 7 8 |
# File 'lib/treetop/compiler/grammar_compiler.rb', line 4 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 |
#ruby_source(source_path) ⇒ Object
10 11 12 13 14 15 16 17 18 19 |
# File 'lib/treetop/compiler/grammar_compiler.rb', line 10 def ruby_source(source_path) File.open(source_path) do |source_file| parser = MetagrammarParser.new result = parser.parse(source_file.read) unless result raise RuntimeError.new(parser.failure_reason) end result.compile end end |