Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Remove manage_gems. Tweak jgarbers patch. Require polyglot >= 0.2.5

  • Loading branch information...
commit ba9b7281bf1b48f20d7355dafdc35a8cb446b5e9 1 parent f3c79a4
@cjheath cjheath authored
View
1  Rakefile
@@ -4,7 +4,6 @@ require 'rake'
$LOAD_PATH.unshift(File.join(dir, 'vendor', 'rspec', 'lib'))
require 'spec/rake/spectask'
-Gem::manage_gems
require 'rake/gempackagetask'
task :default => :spec
View
2  lib/treetop/compiler/grammar_compiler.rb
@@ -29,7 +29,7 @@ def self.load(path)
adjusted_path = path =~ /\.(treetop|tt)\Z/ ? path : path + '.treetop'
File.open(adjusted_path) do |source_file|
source = source_file.read
- source.gsub!(/__FILE__/, %Q{"#{adjusted_path}"})
+ source.gsub!(/\b__FILE__\b/, %Q{"#{adjusted_path}"})
load_from_string(source)
end
end
View
117 lib/treetop/compiler/metagrammar.rb
@@ -9,6 +9,12 @@ def root
module TreetopFile0
def require_statement
+ elements[1]
+ end
+ end
+
+ module TreetopFile1
+ def requires
elements[0]
end
@@ -25,9 +31,9 @@ def suffix
end
end
- module TreetopFile1
+ module TreetopFile2
def compile
- require_statement.text_value + prefix.text_value + module_or_grammar.compile + suffix.text_value
+ requires.text_value + prefix.text_value + module_or_grammar.compile + suffix.text_value
end
end
@@ -42,7 +48,25 @@ def _nt_treetop_file
i0, s0 = index, []
s1, i1 = [], index
loop do
- r2 = _nt_require_statement
+ i2, s2 = index, []
+ r4 = _nt_space
+ if r4
+ r3 = r4
+ else
+ r3 = instantiate_node(SyntaxNode,input, index...index)
+ end
+ s2 << r3
+ if r3
+ r5 = _nt_require_statement
+ s2 << r5
+ end
+ if s2.last
+ r2 = instantiate_node(SyntaxNode,input, i2...index, s2)
+ r2.extend(TreetopFile0)
+ else
+ self.index = i2
+ r2 = nil
+ end
if r2
s1 << r2
else
@@ -52,43 +76,43 @@ def _nt_treetop_file
r1 = instantiate_node(SyntaxNode,input, i1...index, s1)
s0 << r1
if r1
- r4 = _nt_space
- if r4
- r3 = r4
+ r7 = _nt_space
+ if r7
+ r6 = r7
else
- r3 = instantiate_node(SyntaxNode,input, index...index)
+ r6 = instantiate_node(SyntaxNode,input, index...index)
end
- s0 << r3
- if r3
- i5 = index
- r6 = _nt_module_declaration
- if r6
- r5 = r6
+ s0 << r6
+ if r6
+ i8 = index
+ r9 = _nt_module_declaration
+ if r9
+ r8 = r9
else
- r7 = _nt_grammar
- if r7
- r5 = r7
+ r10 = _nt_grammar
+ if r10
+ r8 = r10
else
- self.index = i5
- r5 = nil
+ self.index = i8
+ r8 = nil
end
end
- s0 << r5
- if r5
- r9 = _nt_space
- if r9
- r8 = r9
+ s0 << r8
+ if r8
+ r12 = _nt_space
+ if r12
+ r11 = r12
else
- r8 = instantiate_node(SyntaxNode,input, index...index)
+ r11 = instantiate_node(SyntaxNode,input, index...index)
end
- s0 << r8
+ s0 << r11
end
end
end
if s0.last
r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
- r0.extend(TreetopFile0)
r0.extend(TreetopFile1)
+ r0.extend(TreetopFile2)
else
self.index = i0
r0 = nil
@@ -123,18 +147,18 @@ def _nt_require_statement
end
s0 << r1
if r1
- if input.index("require ", index) == index
- r3 = instantiate_node(SyntaxNode,input, index...(index + 8))
- @index += 8
+ if input.index("require", index) == index
+ r3 = instantiate_node(SyntaxNode,input, index...(index + 7))
+ @index += 7
else
- terminal_parse_failure("require ")
+ terminal_parse_failure("require")
r3 = nil
end
s0 << r3
if r3
s4, i4 = [], index
loop do
- if input.index(Regexp.new('[^\\n\\r]'), index) == index
+ if input.index(Regexp.new('[ \\t]'), index) == index
r5 = instantiate_node(SyntaxNode,input, index...(index + 1))
@index += 1
else
@@ -154,13 +178,36 @@ def _nt_require_statement
end
s0 << r4
if r4
- if input.index(Regexp.new('[\\n\\r]'), index) == index
- r6 = instantiate_node(SyntaxNode,input, index...(index + 1))
- @index += 1
- else
+ s6, i6 = [], index
+ loop do
+ if input.index(Regexp.new('[^\\n\\r]'), index) == index
+ r7 = instantiate_node(SyntaxNode,input, index...(index + 1))
+ @index += 1
+ else
+ r7 = nil
+ end
+ if r7
+ s6 << r7
+ else
+ break
+ end
+ end
+ if s6.empty?
+ self.index = i6
r6 = nil
+ else
+ r6 = instantiate_node(SyntaxNode,input, i6...index, s6)
end
s0 << r6
+ if r6
+ if input.index(Regexp.new('[\\n\\r]'), index) == index
+ r8 = instantiate_node(SyntaxNode,input, index...(index + 1))
+ @index += 1
+ else
+ r8 = nil
+ end
+ s0 << r8
+ end
end
end
end
View
6 lib/treetop/compiler/metagrammar.treetop
@@ -2,15 +2,15 @@ module Treetop
module Compiler
grammar Metagrammar
rule treetop_file
- require_statement:require_statement* prefix:space? module_or_grammar:(module_declaration / grammar) suffix:space? {
+ requires:(space? require_statement)* prefix:space? module_or_grammar:(module_declaration / grammar) suffix:space? {
def compile
- require_statement.text_value + prefix.text_value + module_or_grammar.compile + suffix.text_value
+ requires.text_value + prefix.text_value + module_or_grammar.compile + suffix.text_value
end
}
end
rule require_statement
- prefix:space? "require " [^\n\r]+ [\n\r]
+ prefix:space? "require" [ \t]+ [^\n\r]+ [\n\r]
end
rule module_declaration
View
2  lib/treetop/version.rb
@@ -2,7 +2,7 @@ module Treetop #:nodoc:
module VERSION #:nodoc:
MAJOR = 1
MINOR = 2
- TINY = 5
+ TINY = 6
STRING = [MAJOR, MINOR, TINY].join('.')
end
View
6 spec/composition/f.treetop
@@ -1,5 +1,7 @@
+
require "a"
-require File.dirname(__FILE__) + "/b"
+
+require File.dirname(__FILE__) + "/b"
require File.dirname(__FILE__) + "/subfolder/e_includes_c"
module Test
@@ -12,4 +14,4 @@ module Test
c e 'f'
end
end
-end
+end
View
2  spec/composition/subfolder/e_includes_c.treetop
@@ -12,4 +12,4 @@ module Test
'super'
end
end
-end
+end
View
2  treetop.gemspec
@@ -13,6 +13,6 @@ $gemspec = Gem::Specification.new do |s|
s.require_path = "lib"
s.autorequire = "treetop"
s.has_rdoc = false
- s.add_dependency "polyglot"
+ s.add_dependency "polyglot", ">= 0.2.5"
end
Please sign in to comment.
Something went wrong with that request. Please try again.