diff --git a/Rakefile b/Rakefile index cae2e3c..efbb7cc 100644 --- a/Rakefile +++ b/Rakefile @@ -15,7 +15,7 @@ end gemspec = Gem::Specification.new do |s| s.name = "treetop" - s.version = "1.2.3" + s.version = "1.2.4" s.author = "Nathan Sobo" s.email = "nathansobo@gmail.com" s.homepage = "http://functionalform.blogspot.com" diff --git a/lib/treetop/compiler/metagrammar.rb b/lib/treetop/compiler/metagrammar.rb index 9b97de6..abb96bd 100644 --- a/lib/treetop/compiler/metagrammar.rb +++ b/lib/treetop/compiler/metagrammar.rb @@ -141,7 +141,7 @@ def _nt_module_declaration r3 = _nt_space s1 << r3 if r3 - if input.index(/[A-Z]/, index) == index + if input.index(Regexp.new('[A-Z]'), index) == index r4 = (SyntaxNode).new(input, index...(index + 1)) @index += 1 else @@ -324,7 +324,7 @@ def _nt_grammar_name end i0, s0 = index, [] - if input.index(/[A-Z]/, index) == index + if input.index(Regexp.new('[A-Z]'), index) == index r1 = (SyntaxNode).new(input, index...(index + 1)) @index += 1 else @@ -523,7 +523,7 @@ def _nt_include_declaration r2 = _nt_space s0 << r2 if r2 - if input.index(/[A-Z]/, index) == index + if input.index(Regexp.new('[A-Z]'), index) == index r3 = (SyntaxNode).new(input, index...(index + 1)) @index += 1 else @@ -2508,7 +2508,7 @@ def _nt_inline_module else i5, s5 = index, [] i6 = index - if input.index(/[{}]/, index) == index + if input.index(Regexp.new('[{}]'), index) == index r7 = (SyntaxNode).new(input, index...(index + 1)) @index += 1 else @@ -2691,7 +2691,7 @@ def _nt_alpha_char return cached end - if input.index(/[A-Za-z_]/, index) == index + if input.index(Regexp.new('[A-Za-z_]'), index) == index r0 = (SyntaxNode).new(input, index...(index + 1)) @index += 1 else @@ -2716,7 +2716,7 @@ def _nt_alphanumeric_char if r1 r0 = r1 else - if input.index(/[0-9]/, index) == index + if input.index(Regexp.new('[0-9]'), index) == index r2 = (SyntaxNode).new(input, index...(index + 1)) @index += 1 else @@ -2841,12 +2841,7 @@ def _nt_comment_to_eol break end end - if s2.empty? - self.index = i2 - r2 = nil - else - r2 = SyntaxNode.new(input, i2...index, s2) - end + r2 = SyntaxNode.new(input, i2...index, s2) s0 << r2 end if s0.last @@ -2870,7 +2865,7 @@ def _nt_white return cached end - if input.index(/[ \t\n\r]/, index) == index + if input.index(Regexp.new('[ \\t\\n\\r]'), index) == index r0 = (SyntaxNode).new(input, index...(index + 1)) @index += 1 else diff --git a/lib/treetop/compiler/metagrammar.treetop b/lib/treetop/compiler/metagrammar.treetop index 563dd67..0ed44b9 100644 --- a/lib/treetop/compiler/metagrammar.treetop +++ b/lib/treetop/compiler/metagrammar.treetop @@ -393,7 +393,7 @@ module Treetop end rule comment_to_eol - '#' (!"\n" .)+ + '#' (!"\n" .)* end rule white diff --git a/spec/compiler/grammar_spec.rb b/spec/compiler/grammar_spec.rb index 6fe01f8..47d355e 100644 --- a/spec/compiler/grammar_spec.rb +++ b/spec/compiler/grammar_spec.rb @@ -7,7 +7,8 @@ module Bar describe "a grammar" do testing_grammar %{ grammar Foo - # This comment should not cause a syntax error. + # This comment should not cause a syntax error, nor should the following empty one + # include GrammarSpec::Bar rule foo