public
Description: A Ruby-based parsing DSL based on parsing expression grammars.
Homepage: http://treetop.rubyforge.org
Clone URL: git://github.com/nathansobo/treetop.git
Search Repo:
Add Treetop.load_string which loads a grammar description stored in 
string.
Refactor Treetop.load and replace ruby_source with ruby_source_string 
which compiles
a source stored in string.
hagabaka (author)
Sat May 24 21:09:40 -0700 2008
commit  06ee20f48e71ee6c4d95fce6b498005f4d838dce
tree    d3bb906ffd8d3fb43ba0c24d5a5b982ffda12293
parent  436225cce095d47e8c1bcffce59a6b409e6493bf
...
6
7
8
9
10
11
12
13
14
15
16
17
 
 
 
 
 
 
 
18
 
19
20
21
22
 
23
24
 
 
 
 
 
 
 
25
26
 
27
28
...
6
7
8
 
 
 
 
 
 
 
 
 
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
 
33
34
35
0
@@ -6,23 +6,30 @@ module Treetop
0
           target_file.write(ruby_source(source_path))
0
         end
0
       end
0
-
0
- def ruby_source(source_path)
0
- File.open(source_path) do |source_file|
0
- parser = MetagrammarParser.new
0
- result = parser.parse(source_file.read)
0
- unless result
0
- raise RuntimeError.new(parser.failure_reason)
0
- end
0
- result.compile
0
+
0
+ # compile a string containing treetop source
0
+ def ruby_source_string(s)
0
+ parser = MetagrammarParser.new
0
+ result = parser.parse(s)
0
+ unless result
0
+ raise RuntimeError.new(parser.failure_reason)
0
         end
0
+ result.compile
0
       end
0
     end
0
   end
0
 
0
+ # compile a treetop source file and load it
0
   def self.load(path)
0
     adjusted_path = path =~ /\.(treetop|tt)\Z/ ? path : path + '.treetop'
0
+ File.open(adjusted_path) do |source_file|
0
+ load_string(source_file.read)
0
+ end
0
+ end
0
+
0
+ # compile a treetop source string and load it
0
+ def self.load_string(s)
0
     compiler = Treetop::Compiler::GrammarCompiler.new
0
- Object.class_eval(compiler.ruby_source(adjusted_path))
0
+ Object.class_eval(compiler.ruby_source_string(s))
0
   end
0
 end

Comments

    No one has commented yet.