treetop 1.6.2 → 1.6.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -9,7 +9,7 @@ module Treetop
9
9
  builder.if__ "#{accumulator_var}.last" do
10
10
  assign_result "instantiate_node(#{node_class_name},input, #{start_index_var}...index, #{accumulator_var})"
11
11
  extend_result sequence_element_accessor_module_name if sequence_element_accessor_module_name
12
- extend_result_with_inline_module parent_expression
12
+ extend_result_with_inline_module
13
13
  end
14
14
  builder.else_ do
15
15
  reset_index
@@ -25,13 +25,7 @@ module Treetop
25
25
  builder.if__ "(match_len = has_terminal?(#{str}, #{mode}, index))" do
26
26
  if address == 0 || decorated? || mode != 'false' || string_length > 1
27
27
  assign_result "instantiate_node(#{node_class_name},input, index...(index + match_len))"
28
- # debugger if parent_expression and parent_expression.inline_modules.size > 0
29
- # extend_result_with_inline_module parent_expression
30
- if parent_expression
31
- parent_expression.inline_modules.each do |inline|
32
- extend_result inline.module_name
33
- end
34
- end
28
+ extend_result_with_inline_module
35
29
  else
36
30
  assign_lazily_instantiated_node
37
31
  end
@@ -60,7 +60,7 @@ module Treetop
60
60
  end
61
61
  end
62
62
 
63
- def inspect_self(indent="")
63
+ def inspect(indent="")
64
64
  em = extension_modules
65
65
  interesting_methods = methods-[em.last ? em.last.methods : nil]-self.class.instance_methods
66
66
  im = interesting_methods.size > 0 ? " (#{interesting_methods.join(",")})" : ""
@@ -72,25 +72,18 @@ module Treetop
72
72
  em.map{|m| "+"+m.to_s.sub(/.*:/,'')}*"" +
73
73
  " offset=#{interval.first}" +
74
74
  ", #{tv.inspect}" +
75
- im
76
- end
77
-
78
- def inspect_children(indent="")
79
- return '' unless elements && elements.size > 0
80
- ":" +
81
- elements.map do |e|
82
- begin
83
- "\n"+e.inspect(indent+" ")
84
- rescue # Defend against inspect not taking a parameter
85
- "\n"+indent+" "+e.inspect
86
- end
87
- end.
88
- join("")
89
- end
90
-
91
- def inspect(indent="")
92
- inspect_self(indent) +
93
- inspect_children(indent)
75
+ im +
76
+ (elements && elements.size > 0 ?
77
+ ":" +
78
+ (elements||[]).map{|e|
79
+ begin
80
+ "\n"+e.inspect(indent+" ")
81
+ rescue # Defend against inspect not taking a parameter
82
+ "\n"+indent+" "+e.inspect
83
+ end
84
+ }.join("") :
85
+ ""
86
+ )
94
87
  end
95
88
 
96
89
  @@dot_id_counter = 0
@@ -2,7 +2,7 @@ module Treetop #:nodoc:
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 1
4
4
  MINOR = 6
5
- TINY = 2
5
+ TINY = 3
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
  end
@@ -2,31 +2,22 @@ require 'spec_helper'
2
2
 
3
3
  module ChoiceSpec
4
4
  describe "A choice between terminal symbols" do
5
- testing_expression '("foo" { def foo_method; end } / "bar" { def bar_method; end } / "baz" { def baz_method; end }) {def bat_method; end}'
5
+ testing_expression '"foo" { def foo_method; end } / "bar" { def bar_method; end } / "baz" { def baz_method; end }'
6
6
 
7
7
  it "successfully parses input matching any of the alternatives, returning a node that responds to methods defined in its respective inline module" do
8
8
  result = parse('foo')
9
9
  result.should_not be_nil
10
10
  result.should respond_to(:foo_method)
11
- result.should_not respond_to(:bar_method)
12
- result.should_not respond_to(:baz_method)
13
- result.should respond_to(:bat_method)
14
-
11
+
15
12
  result = parse('bar')
16
13
  result.should_not be_nil
17
- result.should_not respond_to(:foo_method)
18
14
  result.should respond_to(:bar_method)
19
- result.should_not respond_to(:baz_method)
20
- result.should respond_to(:bat_method)
21
-
15
+
22
16
  result = parse('baz')
23
17
  result.should_not be_nil
24
- result.should_not respond_to(:foo_method)
25
- result.should_not respond_to(:bar_method)
26
18
  result.should respond_to(:baz_method)
27
- result.should respond_to(:bat_method)
28
19
  end
29
-
20
+
30
21
  it "upon parsing a string matching the second alternative, records the failure of the first terminal" do
31
22
  result = parse('bar')
32
23
  terminal_failures = parser.terminal_failures
@@ -35,18 +26,18 @@ module ChoiceSpec
35
26
  failure.expected_string.should == '"foo"'
36
27
  failure.index.should == 0
37
28
  end
38
-
29
+
39
30
  it "upon parsing a string matching the third alternative, records the failure of the first two terminals" do
40
31
  result = parse('baz')
41
-
32
+
42
33
  terminal_failures = parser.terminal_failures
43
-
34
+
44
35
  terminal_failures.size.should == 2
45
36
 
46
37
  failure_1 = terminal_failures[0]
47
38
  failure_1.expected_string == 'foo'
48
39
  failure_1.index.should == 0
49
-
40
+
50
41
  failure_2 = terminal_failures[1]
51
42
  failure_2.expected_string == 'bar'
52
43
  failure_2.index.should == 0
@@ -62,7 +53,7 @@ module ChoiceSpec
62
53
  end
63
54
  end
64
55
 
65
- describe "A choice between terminals followed by a block" do
56
+ describe "A choice between terminals followed by a block" do
66
57
  testing_expression "('a'/ 'bb' / [c]) { def a_method; end }"
67
58
 
68
59
  it "extends a match of any of its subexpressions with a module created from the block" do
@@ -77,7 +68,7 @@ module ChoiceSpec
77
68
  end
78
69
  end
79
70
 
80
- describe "a choice followed by a declared module" do
71
+ describe "a choice followed by a declared module" do
81
72
  testing_expression "('a'/ 'bb' / [c]) <ChoiceSpec::TestModule>"
82
73
 
83
74
  it "extends a match of any of its subexpressions with a module created from the block" do
@@ -32,17 +32,17 @@ describe Compiler::GrammarCompiler do
32
32
  specify "compilation of a single file to a default file name" do
33
33
  src_copy = "#{@tmpdir}/test_grammar.treetop"
34
34
  File.open(source_path_with_treetop_extension) { |f| File.open(src_copy,'w'){|o|o.write(f.read)} }
35
- File.exists?(target_path).should be_false
35
+ File.exists?(target_path).should be_falsey
36
36
  compiler.compile(src_copy)
37
- File.exists?(target_path).should be_true
37
+ File.exists?(target_path).should be_truthy
38
38
  require target_path
39
39
  Test::GrammarParser.new.parse('foo').should_not be_nil
40
40
  end
41
41
 
42
42
  specify "compilation of a single file to an explicit file name" do
43
- File.exists?(alternate_target_path).should be_false
43
+ File.exists?(alternate_target_path).should be_falsy
44
44
  compiler.compile(source_path_with_treetop_extension, alternate_target_path)
45
- File.exists?(alternate_target_path).should be_true
45
+ File.exists?(alternate_target_path).should be_truthy
46
46
  require alternate_target_path
47
47
  Test::GrammarParser.new.parse('foo').should_not be_nil
48
48
  end
@@ -19,15 +19,4 @@ module ParenthesizedExpressionSpec
19
19
  end
20
20
  end
21
21
  end
22
-
23
- describe "An expression with code both inside and outside parentheses" do
24
- testing_expression '("foo" { def inner; end } ) { def outer; end} '
25
- it "should extend both code modules " do
26
- parse('foo') do |result|
27
- result.should respond_to(:inner)
28
- result.should respond_to(:outer)
29
- end
30
- end
31
- end
32
-
33
22
  end
@@ -34,36 +34,36 @@ describe "The 'tt' comand line compiler" do
34
34
 
35
35
  it 'can compile a grammar file' do
36
36
  # puts %q{emulate 'tt dumb.tt'}
37
- system("ruby -S tt #{@test_grammar}").should be_true
37
+ system("ruby -S tt #{@test_grammar}").should be_truthy
38
38
 
39
- File.exists?(@test_ruby).should be_true
40
- File.zero?(@test_ruby).should_not be_true
39
+ File.exists?(@test_ruby).should be_truthy
40
+ File.zero?(@test_ruby).should_not be_truthy
41
41
  end
42
42
 
43
43
  it 'can compile a relative pathed grammar file' do
44
44
  dir = File.basename(File.expand_path(File.dirname(@test_grammar)))
45
45
 
46
46
  # puts %q{emulate 'tt "../<current_dir>/dumb.tt"'}
47
- system("cd #{@tmpdir}/..; ruby -S tt \"./#{dir}/#{@test_base}.tt\"").should be_true
47
+ system("cd #{@tmpdir}/..; ruby -S tt \"./#{dir}/#{@test_base}.tt\"").should be_truthy
48
48
 
49
- File.exists?(@test_ruby).should be_true
50
- File.zero?(@test_ruby).should_not be_true
49
+ File.exists?(@test_ruby).should be_truthy
50
+ File.zero?(@test_ruby).should_not be_truthy
51
51
  end
52
52
 
53
53
  it 'can compile an absolute pathed grammar file' do
54
54
  # puts %q{emulate 'tt "/path/to/dumb.tt"'}
55
- system("ruby -S tt \"#{File.expand_path(@test_grammar)}\"").should be_true
55
+ system("ruby -S tt \"#{File.expand_path(@test_grammar)}\"").should be_truthy
56
56
 
57
- File.exists?(@test_ruby).should be_true
58
- File.zero?(@test_ruby).should_not be_true
57
+ File.exists?(@test_ruby).should be_truthy
58
+ File.zero?(@test_ruby).should_not be_truthy
59
59
  end
60
60
 
61
61
  it 'can compile without explicit file extensions' do
62
62
  # puts %q{emulate 'tt dumb'}
63
- system("ruby -S tt #{@test_path}").should be_true
63
+ system("ruby -S tt #{@test_path}").should be_truthy
64
64
 
65
- File.exists?(@test_ruby).should be_true
66
- File.zero?(@test_ruby).should_not be_true
65
+ File.exists?(@test_ruby).should be_truthy
66
+ File.zero?(@test_ruby).should_not be_truthy
67
67
  end
68
68
 
69
69
  it 'skips nonexistent grammar file without failing or creating bogus output' do
@@ -72,17 +72,17 @@ describe "The 'tt' comand line compiler" do
72
72
  (io.read =~ /ERROR.*?not exist.*?continuing/).should_not be_nil
73
73
  end
74
74
 
75
- File.exists?("#{@test_base}.rb").should be_false
75
+ File.exists?("#{@test_base}.rb").should be_falsy
76
76
  end
77
77
 
78
78
  it 'can compile to a specified parser source file' do
79
79
  # puts %q{emulate 'tt -o my_dumb_test_parser.rb dumb'}
80
80
  pf = "#{@tmpdir}/my_dumb_test_parser.rb"
81
81
  begin
82
- system("ruby -S tt -o #{pf} #{@test_path}").should be_true
82
+ system("ruby -S tt -o #{pf} #{@test_path}").should be_truthy
83
83
 
84
- File.exists?(pf).should be_true
85
- File.zero?(pf).should_not be_true
84
+ File.exists?(pf).should be_truthy
85
+ File.zero?(pf).should_not be_truthy
86
86
  ensure
87
87
  File.delete(pf) if File.exists?(pf)
88
88
  end
@@ -92,10 +92,10 @@ describe "The 'tt' comand line compiler" do
92
92
  # puts %q{emulate 'tt -o must_save_parser.rb dumb'}
93
93
  pf = "#{@tmpdir}/must_save_parser.rb"
94
94
  begin
95
- system("ruby -S tt -o #{pf} #{@test_path}").should be_true
95
+ system("ruby -S tt -o #{pf} #{@test_path}").should be_truthy
96
96
 
97
- File.exists?(pf).should be_true
98
- File.zero?(pf).should_not be_true
97
+ File.exists?(pf).should be_truthy
98
+ File.zero?(pf).should_not be_truthy
99
99
 
100
100
  # Check that the magic comment is preserved:
101
101
  written = File.open(pf, "r") { |f| s = f.read }
@@ -121,16 +121,16 @@ describe "The 'tt' comand line compiler" do
121
121
  # puts %q{emulate 'tt -o must_save_parser.rb dumb'}
122
122
  pf = "#{@tmpdir}/must_save_parser.rb"
123
123
  begin
124
- system("ruby -S tt -o #{pf} #{@test_path}").should be_true
124
+ system("ruby -S tt -o #{pf} #{@test_path}").should be_truthy
125
125
 
126
- File.exists?(pf).should be_true
127
- File.zero?(pf).should_not be_true
126
+ File.exists?(pf).should be_truthy
127
+ File.zero?(pf).should_not be_truthy
128
128
  orig_file_hash = Digest::SHA1.hexdigest(File.read(pf))
129
129
 
130
130
  # Modify the file and make sure it gets reverted:
131
131
  File.open(pf, "r+") { |f| f.gets; f.write("#") }
132
132
 
133
- system("ruby -S tt -o #{pf} #{@test_path}").should be_true
133
+ system("ruby -S tt -o #{pf} #{@test_path}").should be_truthy
134
134
  Digest::SHA1.hexdigest(File.read(pf)).should == orig_file_hash
135
135
  ensure
136
136
  File.delete(pf) if File.exists?(pf)
@@ -139,13 +139,13 @@ describe "The 'tt' comand line compiler" do
139
139
 
140
140
  it 'can be forced to overwrite existing file #{@test_path}' do
141
141
  pf = "#{@test_path}.rb"
142
- system("echo some junk >#{pf}").should be_true
142
+ system("echo some junk >#{pf}").should be_truthy
143
143
 
144
- File.exists?(pf).should be_true
145
- File.zero?(pf).should_not be_true
144
+ File.exists?(pf).should be_truthy
145
+ File.zero?(pf).should_not be_truthy
146
146
  orig_file_hash = Digest::SHA1.hexdigest(File.read(pf))
147
147
 
148
- system("ruby -S tt -f #{@test_path}").should be_true
148
+ system("ruby -S tt -f #{@test_path}").should be_truthy
149
149
  Digest::SHA1.hexdigest(File.read(pf)).should_not == orig_file_hash
150
150
  end
151
151
 
@@ -179,45 +179,45 @@ describe "The 'tt' comand line compiler" do
179
179
 
180
180
  it 'can compile them in one invocation' do
181
181
  # puts %q{emulate 'tt dumb1.tt dumb2.tt'}
182
- system("ruby -S tt #{@test_grammars.join(' ')}").should be_true
182
+ system("ruby -S tt #{@test_grammars.join(' ')}").should be_truthy
183
183
 
184
184
  @test_bases.each do |f|
185
185
  pf = "#{f}.rb"
186
- File.exists?(pf).should be_true
187
- File.zero?(pf).should_not be_true
186
+ File.exists?(pf).should be_truthy
187
+ File.zero?(pf).should_not be_truthy
188
188
  end
189
189
  end
190
190
 
191
191
  it 'can compile them without explicit file extenstions' do
192
192
  # puts %q{emulate 'tt dumb1 dumb2'}
193
- system("ruby -S tt #{@test_bases.join(' ')}").should be_true
193
+ system("ruby -S tt #{@test_bases.join(' ')}").should be_truthy
194
194
 
195
195
  @test_bases.each do |f|
196
196
  pf = "#{f}.rb"
197
- File.exists?(pf).should be_true
198
- File.zero?(pf).should_not be_true
197
+ File.exists?(pf).should be_truthy
198
+ File.zero?(pf).should_not be_truthy
199
199
  end
200
200
  end
201
201
 
202
202
  it 'can skip nonexistent and invalid extension named grammar files' do
203
203
  # puts %q{emulate 'tt not_here bad_ext.ttg dumb1 dumb2'}
204
- system("ruby -S tt not_here bad_ext.ttg #{@test_bases.join(' ')} >/dev/null 2>&1").should be_true
204
+ system("ruby -S tt not_here bad_ext.ttg #{@test_bases.join(' ')} >/dev/null 2>&1").should be_truthy
205
205
 
206
- File.exists?('not_here.rb').should_not be_true
207
- File.exists?('bad_ext.rb').should_not be_true
206
+ File.exists?('not_here.rb').should_not be_truthy
207
+ File.exists?('bad_ext.rb').should_not be_truthy
208
208
 
209
209
  @test_bases.each do |f|
210
210
  pf = "#{f}.rb"
211
- File.exists?(pf).should be_true
212
- File.zero?(pf).should_not be_true
211
+ File.exists?(pf).should be_truthy
212
+ File.zero?(pf).should_not be_truthy
213
213
  end
214
214
  end
215
215
 
216
216
  it 'can not specify an output file' do
217
217
  # puts %q{emulate 'tt -o my_bogus_test_parser.rb dumb1 dumb2'}
218
218
  pf = 'my_bogus_test_parser.rb'
219
- system("ruby -S tt -o #{pf} #{@test_bases.join(' ')} >/dev/null 2>&1").should be_false
220
- File.exists?(pf).should be_false
219
+ system("ruby -S tt -o #{pf} #{@test_bases.join(' ')} >/dev/null 2>&1").should be_falsy
220
+ File.exists?(pf).should be_falsy
221
221
  end
222
222
  end
223
223
 
@@ -5,8 +5,6 @@ module ZeroOrMoreSpec
5
5
  end
6
6
 
7
7
  describe "zero or more of a terminal symbol followed by a node class declaration and a block" do
8
- # testing_expression '("foo" { def b_method; end } )* <ZeroOrMoreSpec::Foo> { def a_method; end }'
9
- # testing_expression '("foo" { def a_method; end } )* <ZeroOrMoreSpec::Foo>'
10
8
  testing_expression '"foo"* <ZeroOrMoreSpec::Foo> { def a_method; end }'
11
9
 
12
10
  it "successfully parses epsilon, returning an instance declared node class and recording a terminal failure" do
@@ -63,7 +63,7 @@ module Treetop
63
63
  def parse_multibyte(input, options = {})
64
64
  require 'active_support/all'
65
65
 
66
- if RUBY_VERSION !~ /^(1\.9|2\.0)/ && 'NONE' == $KCODE then $KCODE = 'UTF8' end
66
+ if RUBY_VERSION !~ /^(1\.9|2\.)/ && 'NONE' == $KCODE then $KCODE = 'UTF8' end
67
67
  # rspec 1.3 used to do something similar (set it to 'u') that we need
68
68
  # for activerecord multibyte wrapper to kick in (1.8 only? @todo)
69
69
 
@@ -2,17 +2,17 @@
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
3
  # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
- # stub: treetop 1.5.3 ruby lib
5
+ # stub: treetop 1.6.3 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "treetop"
9
- s.version = "1.5.3"
9
+ s.version = "1.6.3"
10
10
 
11
11
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
12
12
  s.require_paths = ["lib"]
13
13
  s.authors = ["Nathan Sobo", "Clifford Heath"]
14
- s.autorequire = "treetop"
15
- s.date = "2014-03-21"
14
+ s.date = "2015-06-30"
15
+ s.description = "A Parsing Expression Grammar (PEG) Parser generator DSL for Ruby"
16
16
  s.email = "cliffordheath@gmail.com"
17
17
  s.executables = ["tt"]
18
18
  s.extra_rdoc_files = [
@@ -34,16 +34,21 @@ Gem::Specification.new do |s|
34
34
  "doc/syntactic_recognition.markdown",
35
35
  "doc/tt.1",
36
36
  "doc/using_in_ruby.markdown",
37
+ "examples/indented_blocks/indented_blocks.tt",
38
+ "examples/indented_blocks/indented_blocks_test.rb",
39
+ "examples/inner_outer.rb",
40
+ "examples/inner_outer.tt",
37
41
  "examples/lambda_calculus/arithmetic.rb",
38
42
  "examples/lambda_calculus/arithmetic.treetop",
39
43
  "examples/lambda_calculus/arithmetic_node_classes.rb",
40
44
  "examples/lambda_calculus/arithmetic_test.rb",
41
- "examples/lambda_calculus/lambda_calculus",
42
45
  "examples/lambda_calculus/lambda_calculus.rb",
43
46
  "examples/lambda_calculus/lambda_calculus.treetop",
44
47
  "examples/lambda_calculus/lambda_calculus_node_classes.rb",
45
48
  "examples/lambda_calculus/lambda_calculus_test.rb",
46
49
  "examples/lambda_calculus/test_helper.rb",
50
+ "examples/numerals.rb",
51
+ "examples/numerals.tt",
47
52
  "lib/treetop.rb",
48
53
  "lib/treetop/bootstrap_gen_1_metagrammar.rb",
49
54
  "lib/treetop/compiler.rb",
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: treetop
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.6.2
4
+ version: 1.6.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nathan Sobo
8
8
  - Clifford Heath
9
- autorequire: treetop
9
+ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-12-09 00:00:00.000000000 Z
12
+ date: 2015-06-30 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: polyglot
@@ -99,17 +99,17 @@ dependencies:
99
99
  name: rake
100
100
  requirement: !ruby/object:Gem::Requirement
101
101
  requirements:
102
- - - ">="
102
+ - - "~>"
103
103
  - !ruby/object:Gem::Version
104
- version: '0'
104
+ version: '10'
105
105
  type: :development
106
106
  prerelease: false
107
107
  version_requirements: !ruby/object:Gem::Requirement
108
108
  requirements:
109
- - - ">="
109
+ - - "~>"
110
110
  - !ruby/object:Gem::Version
111
- version: '0'
112
- description:
111
+ version: '10'
112
+ description: A Parsing Expression Grammar (PEG) Parser generator DSL for Ruby
113
113
  email: cliffordheath@gmail.com
114
114
  executables:
115
115
  - tt
@@ -132,6 +132,10 @@ files:
132
132
  - doc/syntactic_recognition.markdown
133
133
  - doc/tt.1
134
134
  - doc/using_in_ruby.markdown
135
+ - examples/indented_blocks/indented_blocks.tt
136
+ - examples/indented_blocks/indented_blocks_test.rb
137
+ - examples/inner_outer.rb
138
+ - examples/inner_outer.tt
135
139
  - examples/lambda_calculus/arithmetic.rb
136
140
  - examples/lambda_calculus/arithmetic.treetop
137
141
  - examples/lambda_calculus/arithmetic_node_classes.rb
@@ -141,6 +145,8 @@ files:
141
145
  - examples/lambda_calculus/lambda_calculus_node_classes.rb
142
146
  - examples/lambda_calculus/lambda_calculus_test.rb
143
147
  - examples/lambda_calculus/test_helper.rb
148
+ - examples/numerals.rb
149
+ - examples/numerals.tt
144
150
  - lib/treetop.rb
145
151
  - lib/treetop/bootstrap_gen_1_metagrammar.rb
146
152
  - lib/treetop/compiler.rb