From f55034d35fa1460282b33a2da6330dee3fca4458 Mon Sep 17 00:00:00 2001 From: Yaohan Chen Date: Sun, 25 May 2008 01:25:32 -0400 Subject: [PATCH] put back ruby_source (although refactored) as it is refered by lib/treetop/bootstrap_gen_1_metagrammar.rb add tests for ruby_source_string and load_string --- lib/treetop/compiler/grammar_compiler.rb | 7 ++++++- spec/compiler/grammar_compiler_spec.rb | 9 +++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/lib/treetop/compiler/grammar_compiler.rb b/lib/treetop/compiler/grammar_compiler.rb index 7c5ae91..2683e6a 100755 --- a/lib/treetop/compiler/grammar_compiler.rb +++ b/lib/treetop/compiler/grammar_compiler.rb @@ -7,7 +7,12 @@ def compile(source_path, target_path = source_path.gsub(/\.(treetop|tt)\Z/, '.rb end end - # compile a string containing treetop source + # compile a treetop file into ruby + def ruby_source(source_path) + ruby_source_string(File.read(source_path)) + end + + # compile a string containing treetop source into ruby def ruby_source_string(s) parser = MetagrammarParser.new result = parser.parse(s) diff --git a/spec/compiler/grammar_compiler_spec.rb b/spec/compiler/grammar_compiler_spec.rb index b9b591f..10f5070 100755 --- a/spec/compiler/grammar_compiler_spec.rb +++ b/spec/compiler/grammar_compiler_spec.rb @@ -39,6 +39,15 @@ specify "compilation of a single file without writing it to an output file" do compiler.ruby_source(source_path_with_treetop_extension).should_not be_nil end + + specify "ruby_source_string compiles a grammar stored in string" do + compiler.ruby_source_string(File.read(source_path_with_treetop_extension)).should_not be_nil + end + + specify "Treetop.load_string compiles and evaluates a source grammar stored in string" do + Treetop.load_string File.read(source_path_with_treetop_extension) + Test::GrammarParser.new.parse('foo').should_not be_nil + end specify "Treetop.load compiles and evaluates a source grammar with a .treetop extension" do Treetop.load source_path_with_treetop_extension