Permalink
Browse files

Rely on load path. Allow direct treetop/runtime require.

  • Loading branch information...
1 parent 89baa8a commit 471b670471d72eab34fbffa96d35a70bb0a13049 @jeremy jeremy committed Mar 7, 2010
View
@@ -1,16 +1,10 @@
-require 'rubygems'
-
module Treetop
VALID_GRAMMAR_EXT = ['treetop', 'tt']
VALID_GRAMMAR_EXT_REGEXP = /\.(#{VALID_GRAMMAR_EXT.join('|')})\Z/o
end
-dir = File.dirname(__FILE__)
-
-TREETOP_ROOT = File.join(dir, 'treetop')
-require File.join(TREETOP_ROOT, "ruby_extensions")
-require File.join(TREETOP_ROOT, "runtime")
-require File.join(TREETOP_ROOT, "compiler")
+require 'treetop/runtime'
+require 'treetop/compiler'
require 'polyglot'
Polyglot.register(Treetop::VALID_GRAMMAR_EXT, Treetop)
@@ -2,28 +2,25 @@
# into the environment by compiling the current metagrammar.treetop using a trusted version of Treetop.
require 'rubygems'
-dir = File.dirname(__FILE__)
TREETOP_VERSION_REQUIRED_TO_BOOTSTRAP = '>= 1.1.5'
# Loading trusted version of Treetop to compile the compiler
gem_spec = Gem.source_index.find_name('treetop', TREETOP_VERSION_REQUIRED_TO_BOOTSTRAP).last
raise "Install a Treetop Gem version #{TREETOP_VERSION_REQUIRED_TO_BOOTSTRAP} to bootstrap." unless gem_spec
-trusted_treetop_path = gem_spec.full_gem_path
-require File.join(trusted_treetop_path, 'lib', 'treetop')
+require "#{gem_spec.full_gem_path}/lib/treetop"
# Relocating trusted version of Treetop to Trusted::Treetop
Trusted = Module.new
Trusted::Treetop = Treetop
Object.send(:remove_const, :Treetop)
-Object.send(:remove_const, :TREETOP_ROOT)
# Requiring version of Treetop that is under test
$exclude_metagrammar = true
-require File.expand_path(File.join(dir, '..', 'treetop'))
+require File.expand_path('../treetop')
# Compile and evaluate freshly generated metagrammar source
-METAGRAMMAR_PATH = File.join(TREETOP_ROOT, 'compiler', 'metagrammar.treetop')
+METAGRAMMAR_PATH = File.expand_path('../compiler/metagrammar.treetop', __FILE__)
compiled_metagrammar_source = Trusted::Treetop::Compiler::GrammarCompiler.new.ruby_source(METAGRAMMAR_PATH)
Object.class_eval(compiled_metagrammar_source)
@@ -42,4 +39,4 @@
# include Trusted::Treetop::Runtime
# end
-$bootstrapped_gen_1_metagrammar = true
+$bootstrapped_gen_1_metagrammar = true
View
@@ -1,6 +1,7 @@
-dir = File.dirname(__FILE__)
-require File.join(dir, *%w[compiler lexical_address_space])
-require File.join(dir, *%w[compiler ruby_builder])
-require File.join(dir, *%w[compiler node_classes])
-require File.join(dir, *%w[compiler metagrammar]) unless defined?($exclude_metagrammar)
-require File.join(dir, *%w[compiler grammar_compiler])
+require 'treetop/ruby_extensions'
+
+require 'treetop/compiler/lexical_address_space'
+require 'treetop/compiler/ruby_builder'
+require 'treetop/compiler/node_classes'
+require 'treetop/compiler/metagrammar' unless defined?($exclude_metagrammar)
+require 'treetop/compiler/grammar_compiler'
@@ -1,20 +1,19 @@
-dir = File.dirname(__FILE__)
-require File.join(dir, *%w[node_classes parsing_expression])
-require File.join(dir, *%w[node_classes atomic_expression])
-require File.join(dir, *%w[node_classes inline_module])
-require File.join(dir, *%w[node_classes predicate_block])
-require File.join(dir, *%w[node_classes treetop_file])
-require File.join(dir, *%w[node_classes grammar])
-require File.join(dir, *%w[node_classes declaration_sequence])
-require File.join(dir, *%w[node_classes parsing_rule])
-require File.join(dir, *%w[node_classes parenthesized_expression])
-require File.join(dir, *%w[node_classes nonterminal])
-require File.join(dir, *%w[node_classes terminal])
-require File.join(dir, *%w[node_classes anything_symbol])
-require File.join(dir, *%w[node_classes character_class])
-require File.join(dir, *%w[node_classes sequence])
-require File.join(dir, *%w[node_classes choice])
-require File.join(dir, *%w[node_classes repetition])
-require File.join(dir, *%w[node_classes optional])
-require File.join(dir, *%w[node_classes predicate])
-require File.join(dir, *%w[node_classes transient_prefix])
+require 'treetop/compiler/node_classes/parsing_expression'
+require 'treetop/compiler/node_classes/atomic_expression'
+require 'treetop/compiler/node_classes/inline_module'
+require 'treetop/compiler/node_classes/predicate_block'
+require 'treetop/compiler/node_classes/treetop_file'
+require 'treetop/compiler/node_classes/grammar'
+require 'treetop/compiler/node_classes/declaration_sequence'
+require 'treetop/compiler/node_classes/parsing_rule'
+require 'treetop/compiler/node_classes/parenthesized_expression'
+require 'treetop/compiler/node_classes/nonterminal'
+require 'treetop/compiler/node_classes/terminal'
+require 'treetop/compiler/node_classes/anything_symbol'
+require 'treetop/compiler/node_classes/character_class'
+require 'treetop/compiler/node_classes/sequence'
+require 'treetop/compiler/node_classes/choice'
+require 'treetop/compiler/node_classes/repetition'
+require 'treetop/compiler/node_classes/optional'
+require 'treetop/compiler/node_classes/predicate'
+require 'treetop/compiler/node_classes/transient_prefix'
@@ -1,2 +1 @@
-dir = File.dirname(__FILE__)
-require "#{dir}/ruby_extensions/string"
+require 'treetop/ruby_extensions/string'
View
@@ -1,5 +1,6 @@
-dir = File.dirname(__FILE__)
-require "#{dir}/runtime/compiled_parser"
-require "#{dir}/runtime/syntax_node"
-require "#{dir}/runtime/terminal_parse_failure"
-require "#{dir}/runtime/interval_skip_list"
+require 'treetop/ruby_extensions'
+
+require 'treetop/runtime/compiled_parser'
+require 'treetop/runtime/syntax_node'
+require 'treetop/runtime/terminal_parse_failure'
+require 'treetop/runtime/interval_skip_list'
@@ -1,4 +1,3 @@
-dir = File.dirname(__FILE__)
-require "#{dir}/interval_skip_list/interval_skip_list.rb"
-require "#{dir}/interval_skip_list/head_node.rb"
-require "#{dir}/interval_skip_list/node.rb"
+require 'treetop/runtime/interval_skip_list/interval_skip_list'
+require 'treetop/runtime/interval_skip_list/head_node'
+require 'treetop/runtime/interval_skip_list/node'
@@ -1,14 +1,13 @@
#!/usr/bin/env ruby
require 'rubygems'
-dir = File.dirname(__FILE__)
-require File.join(dir, '..', 'lib', 'treetop', 'bootstrap_gen_1_metagrammar')
+require File.expand_path('../../lib/treetop/bootstrap_gen_1_metagrammar', __FILE__)
-GENERATED_METAGRAMMAR_PATH = File.join(TREETOP_ROOT, 'compiler', 'metagrammar.rb')
+GENERATED_METAGRAMMAR_PATH = File.expand_path('../../lib/treetop/compiler/metagrammar.rb')
File.open(METAGRAMMAR_PATH) do |source_file|
File.open(GENERATED_METAGRAMMAR_PATH, 'w') do |target_file|
generated_source = Treetop::Compiler::MetagrammarParser.new.parse(source_file.read).compile
target_file.write(generated_source)
end
-end
+end
@@ -1,6 +1,6 @@
require File.expand_path("#{File.dirname(__FILE__)}/../spec_helper")
BENCHMARK = false
-METAGRAMMAR_PATH = File.join(TREETOP_ROOT, 'compiler', 'metagrammar.treetop')
+METAGRAMMAR_PATH = File.expand_path('../../../lib/treetop/compiler/metagrammar.treetop', __FILE__)
module CircularCompilationSpec
describe "a parser for the metagrammar" do

0 comments on commit 471b670

Please sign in to comment.