Skip to content

Commit

Permalink
rename load_string to load_from_string, ruby_source_string to ruby_so…
Browse files Browse the repository at this point in the history
…urce_from_string

per halorgium's suggestion
  • Loading branch information
hagabaka committed May 26, 2008
1 parent f55034d commit 1dc77b3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
10 changes: 5 additions & 5 deletions lib/treetop/compiler/grammar_compiler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ def compile(source_path, target_path = source_path.gsub(/\.(treetop|tt)\Z/, '.rb

# compile a treetop file into ruby
def ruby_source(source_path)
ruby_source_string(File.read(source_path))
ruby_source_from_string(File.read(source_path))
end

# compile a string containing treetop source into ruby
def ruby_source_string(s)
def ruby_source_from_string(s)
parser = MetagrammarParser.new
result = parser.parse(s)
unless result
Expand All @@ -28,13 +28,13 @@ def ruby_source_string(s)
def self.load(path)
adjusted_path = path =~ /\.(treetop|tt)\Z/ ? path : path + '.treetop'
File.open(adjusted_path) do |source_file|
load_string(source_file.read)
load_from_string(source_file.read)
end
end

# compile a treetop source string and load it
def self.load_string(s)
def self.load_from_string(s)
compiler = Treetop::Compiler::GrammarCompiler.new
Object.class_eval(compiler.ruby_source_string(s))
Object.class_eval(compiler.ruby_source_from_string(s))
end
end
8 changes: 4 additions & 4 deletions spec/compiler/grammar_compiler_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@
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
specify "ruby_source_from_string compiles a grammar stored in string" do
compiler.ruby_source_from_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)
specify "Treetop.load_from_string compiles and evaluates a source grammar stored in string" do
Treetop.load_from_string File.read(source_path_with_treetop_extension)
Test::GrammarParser.new.parse('foo').should_not be_nil
end

Expand Down

0 comments on commit 1dc77b3

Please sign in to comment.