Skip to content

Commit

Permalink
put back ruby_source (although refactored) as it is refered by lib/tr…
Browse files Browse the repository at this point in the history
…eetop/bootstrap_gen_1_metagrammar.rb

add tests for ruby_source_string and load_string
  • Loading branch information
hagabaka committed May 25, 2008
1 parent 06ee20f commit f55034d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/treetop/compiler/grammar_compiler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
9 changes: 9 additions & 0 deletions spec/compiler/grammar_compiler_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit f55034d

Please sign in to comment.