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:
Nicer support for loading grammars using Polyglot's require, grammars may 
use .tt extension
* Treetop.load is now an alias for Object.load_grammar
cjheath (author)
Tue Dec 11 15:02:40 -0800 2007
commit  c8c6d1b35be7431069cd197be07c8850d4e425e2
tree    0521f128d12f6a70e8a72fbd9af35b39d63b34f9
parent  1299219912bb57b4abc6e2f11b0c145307efddf6
...
28
29
30
 
31
32
33
34
35
36
 
...
28
29
30
31
32
33
34
35
 
36
37
0
@@ -28,8 +28,9 @@ gemspec = Gem::Specification.new do |s|
0
   s.autorequire = "treetop"
0
   s.has_rdoc = false
0
   s.add_dependency "facets", ">=2.0.2"
0
+ s.add_dependency "polyglot"
0
 end
0
 
0
 Rake::GemPackageTask.new(gemspec) do |pkg|
0
   pkg.need_tar = true
0
-end
0
\ No newline at end of file
0
+end
...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
...
18
19
20
 
 
 
...
1
 
 
 
 
 
 
 
 
 
 
2
3
4
...
8
9
10
11
12
13
0
@@ -1,14 +1,4 @@
0
 require 'rubygems'
0
-
0
-if require 'polyglot'
0
- Polyglot.register("treetop",
0
- Class.new do
0
- def self.load(file)
0
- Treetop.load_grammar file
0
- end
0
- end
0
- )
0
-end
0
 require 'facets/string/tabs'
0
 require 'facets/stylize'
0
 
0
@@ -18,3 +8,6 @@ TREETOP_ROOT = File.join(dir, 'treetop')
0
 require File.join(TREETOP_ROOT, "ruby_extensions")
0
 require File.join(TREETOP_ROOT, "runtime")
0
 require File.join(TREETOP_ROOT, "compiler")
0
+
0
+require 'polyglot'
0
+Polyglot.register(["treetop", "tt"], Treetop)
...
19
20
21
22
23
 
 
 
 
 
...
19
20
21
 
22
23
24
25
26
27
0
@@ -19,4 +19,8 @@ module Treetop
0
       end
0
     end
0
   end
0
-end
0
\ No newline at end of file
0
+
0
+ def self.load(file)
0
+ load_grammar file
0
+ end
0
+end
...
1
2
3
 
4
5
6
7
8
 
...
1
2
 
3
4
5
6
 
7
8
0
@@ -1,7 +1,7 @@
0
 class Object
0
   def load_grammar(path)
0
- adjusted_path = path =~ /\.treetop\Z/ ? path : path + '.treetop'
0
+ adjusted_path = path =~ /\.(treetop|tt)\Z/ ? path : path + '.treetop'
0
     compiler = Treetop::Compiler::GrammarCompiler.new
0
     Object.class_eval(compiler.ruby_source(adjusted_path))
0
   end
0
-end
0
\ No newline at end of file
0
+end
...
8
9
10
11
 
12
13
14
15
16
17
18
 
19
20
21
...
23
24
25
26
 
27
28
29
...
31
32
33
34
 
35
36
37
38
39
 
40
41
42
...
46
47
48
49
50
 
 
 
 
 
 
 
51
52
53
54
55
 
56
57
...
8
9
10
 
11
12
13
14
15
16
17
 
18
19
20
21
...
23
24
25
 
26
27
28
29
...
31
32
33
 
34
35
36
37
38
 
39
40
41
42
...
46
47
48
 
 
49
50
51
52
53
54
55
56
57
58
59
 
60
61
62
0
@@ -8,14 +8,14 @@ describe Compiler::GrammarCompiler do
0
     @alternate_target_path = File.join(File.dirname(__FILE__), 'test_grammar_alt.rb')
0
     delete_target_files
0
   end
0
-
0
+
0
   after do
0
     delete_target_files
0
     Object.class_eval do
0
       remove_const(:Test) if const_defined?(:Test)
0
     end
0
   end
0
-
0
+
0
   specify "compilation of a single file to a default file name" do
0
     File.exists?(@target_path).should be_false
0
     @compiler.compile(@source_path)
0
@@ -23,7 +23,7 @@ describe Compiler::GrammarCompiler do
0
     require @target_path
0
     Test::GrammarParser.new.parse('foo').should_not be_nil
0
   end
0
-
0
+
0
   specify "compilation of a single file to an explicit file name" do
0
     File.exists?(@alternate_target_path).should be_false
0
     @compiler.compile(@source_path, @alternate_target_path)
0
@@ -31,12 +31,12 @@ describe Compiler::GrammarCompiler do
0
     require @alternate_target_path
0
     Test::GrammarParser.new.parse('foo').should_not be_nil
0
   end
0
-
0
+
0
   specify "compilation of a single file without writing it to an output file" do
0
     @compiler.ruby_source(@source_path).should_not be_nil
0
   end
0
 
0
- specify "load_grammar compiles and evaluates source grammar with extension" do
0
+ specify "load_grammar compiles and evaluates source grammar with extension" do
0
     load_grammar @source_path
0
     Test::GrammarParser.new.parse('foo').should_not be_nil
0
   end
0
@@ -46,12 +46,17 @@ describe Compiler::GrammarCompiler do
0
     load_grammar path_without_extension
0
     Test::GrammarParser.new.parse('foo').should_not be_nil
0
   end
0
-
0
-
0
+
0
+ specify "load_grammar compiles and evaluates source grammar with .tt extension" do
0
+ path_without_extension = @source_path.gsub(/\.treetop\Z/, '.tt')
0
+ load_grammar path_without_extension
0
+ Test::GrammarParser.new.parse('foo').should_not be_nil
0
+ end
0
+
0
   def delete_target_files
0
     File.delete(@target_path) if File.exists?(@target_path)
0
     File.delete(@alternate_target_path) if File.exists?(@alternate_target_path)
0
   end
0
-
0
+
0
 end
0
 
...
8
9
10
11
 
 
 
12
13
14
...
8
9
10
 
11
12
13
14
15
16
0
@@ -8,7 +8,9 @@ module GrammarCompositionSpec
0
       load_grammar File.join(dir, 'a')
0
       load_grammar File.join(dir, 'b')
0
       load_grammar File.join(dir, 'c')
0
- load_grammar File.join(dir, 'd')
0
+ # Check that polyglot finds d.treetop and loads it:
0
+ $: << dir
0
+ require 'd'
0
   
0
       @c = ::Test::CParser.new
0
       @d = ::Test::DParser.new

Comments

    No one has commented yet.