treetop 1.6.3 → 1.6.4
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.
- checksums.yaml +4 -4
- data/README.md +2 -0
- data/lib/treetop/compiler/metagrammar.rb +150 -72
- data/lib/treetop/compiler/metagrammar.treetop +57 -3
- data/lib/treetop/compiler/node_classes/anything_symbol.rb +1 -1
- data/lib/treetop/compiler/node_classes/character_class.rb +1 -1
- data/lib/treetop/compiler/node_classes/choice.rb +5 -5
- data/lib/treetop/compiler/node_classes/nonterminal.rb +2 -2
- data/lib/treetop/compiler/node_classes/parsing_expression.rb +8 -2
- data/lib/treetop/compiler/node_classes/predicate.rb +1 -1
- data/lib/treetop/compiler/node_classes/repetition.rb +7 -7
- data/lib/treetop/compiler/node_classes/sequence.rb +1 -1
- data/lib/treetop/compiler/node_classes/terminal.rb +7 -1
- data/lib/treetop/runtime/syntax_node.rb +20 -13
- data/lib/treetop/version.rb +1 -1
- data/spec/compiler/choice_spec.rb +19 -10
- data/spec/compiler/grammar_compiler_spec.rb +1 -1
- data/spec/compiler/parenthesized_expression_spec.rb +12 -0
- data/spec/compiler/terminal_spec.rb +3 -3
- data/spec/compiler/tt_compiler_spec.rb +3 -3
- data/spec/compiler/zero_or_more_spec.rb +2 -0
- data/treetop.gemspec +3 -7
- metadata +2 -6
- data/examples/inner_outer.rb +0 -51
- data/examples/inner_outer.tt +0 -14
- data/examples/numerals.rb +0 -210
- data/examples/numerals.tt +0 -21
@@ -40,7 +40,7 @@ describe Compiler::GrammarCompiler do
|
|
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
|
43
|
+
File.exists?(alternate_target_path).should be_falsey
|
44
44
|
compiler.compile(source_path_with_treetop_extension, alternate_target_path)
|
45
45
|
File.exists?(alternate_target_path).should be_truthy
|
46
46
|
require alternate_target_path
|
@@ -19,4 +19,16 @@ 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
|
+
skip "Arbitrarily nested modules are not yet compiled"
|
28
|
+
result.should respond_to(:inner)
|
29
|
+
result.should respond_to(:outer)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
22
34
|
end
|
@@ -169,9 +169,9 @@ module TerminalSymbolSpec
|
|
169
169
|
#
|
170
170
|
# it "returns true upon parsing matching input prefixes at various indices" do
|
171
171
|
# pending "transient terminal expressions"
|
172
|
-
# parse("foo", :index => 0).should
|
173
|
-
# parse("-foo", :index => 1).should
|
174
|
-
# parse("---foo", :index => 3).should
|
172
|
+
# parse("foo", :index => 0).should be_truthy
|
173
|
+
# parse("-foo", :index => 1).should be_truthy
|
174
|
+
# parse("---foo", :index => 3).should be_truthy
|
175
175
|
# end
|
176
176
|
# end
|
177
177
|
end
|
@@ -72,7 +72,7 @@ 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
|
75
|
+
File.exists?("#{@test_base}.rb").should be_falsey
|
76
76
|
end
|
77
77
|
|
78
78
|
it 'can compile to a specified parser source file' do
|
@@ -216,8 +216,8 @@ describe "The 'tt' comand line compiler" do
|
|
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
|
220
|
-
File.exists?(pf).should
|
219
|
+
system("ruby -S tt -o #{pf} #{@test_bases.join(' ')} >/dev/null 2>&1").should be_falsey
|
220
|
+
File.exists?(pf).should be_falsey
|
221
221
|
end
|
222
222
|
end
|
223
223
|
|
@@ -5,6 +5,8 @@ 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>'
|
8
10
|
testing_expression '"foo"* <ZeroOrMoreSpec::Foo> { def a_method; end }'
|
9
11
|
|
10
12
|
it "successfully parses epsilon, returning an instance declared node class and recording a terminal failure" do
|
data/treetop.gemspec
CHANGED
@@ -2,16 +2,16 @@
|
|
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.6.
|
5
|
+
# stub: treetop 1.6.4 ruby lib
|
6
6
|
|
7
7
|
Gem::Specification.new do |s|
|
8
8
|
s.name = "treetop"
|
9
|
-
s.version = "1.6.
|
9
|
+
s.version = "1.6.4"
|
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.date = "
|
14
|
+
s.date = "2016-02-21"
|
15
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"]
|
@@ -36,8 +36,6 @@ Gem::Specification.new do |s|
|
|
36
36
|
"doc/using_in_ruby.markdown",
|
37
37
|
"examples/indented_blocks/indented_blocks.tt",
|
38
38
|
"examples/indented_blocks/indented_blocks_test.rb",
|
39
|
-
"examples/inner_outer.rb",
|
40
|
-
"examples/inner_outer.tt",
|
41
39
|
"examples/lambda_calculus/arithmetic.rb",
|
42
40
|
"examples/lambda_calculus/arithmetic.treetop",
|
43
41
|
"examples/lambda_calculus/arithmetic_node_classes.rb",
|
@@ -47,8 +45,6 @@ Gem::Specification.new do |s|
|
|
47
45
|
"examples/lambda_calculus/lambda_calculus_node_classes.rb",
|
48
46
|
"examples/lambda_calculus/lambda_calculus_test.rb",
|
49
47
|
"examples/lambda_calculus/test_helper.rb",
|
50
|
-
"examples/numerals.rb",
|
51
|
-
"examples/numerals.tt",
|
52
48
|
"lib/treetop.rb",
|
53
49
|
"lib/treetop/bootstrap_gen_1_metagrammar.rb",
|
54
50
|
"lib/treetop/compiler.rb",
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: treetop
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.6.
|
4
|
+
version: 1.6.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nathan Sobo
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2016-02-21 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: polyglot
|
@@ -134,8 +134,6 @@ files:
|
|
134
134
|
- doc/using_in_ruby.markdown
|
135
135
|
- examples/indented_blocks/indented_blocks.tt
|
136
136
|
- examples/indented_blocks/indented_blocks_test.rb
|
137
|
-
- examples/inner_outer.rb
|
138
|
-
- examples/inner_outer.tt
|
139
137
|
- examples/lambda_calculus/arithmetic.rb
|
140
138
|
- examples/lambda_calculus/arithmetic.treetop
|
141
139
|
- examples/lambda_calculus/arithmetic_node_classes.rb
|
@@ -145,8 +143,6 @@ files:
|
|
145
143
|
- examples/lambda_calculus/lambda_calculus_node_classes.rb
|
146
144
|
- examples/lambda_calculus/lambda_calculus_test.rb
|
147
145
|
- examples/lambda_calculus/test_helper.rb
|
148
|
-
- examples/numerals.rb
|
149
|
-
- examples/numerals.tt
|
150
146
|
- lib/treetop.rb
|
151
147
|
- lib/treetop/bootstrap_gen_1_metagrammar.rb
|
152
148
|
- lib/treetop/compiler.rb
|
data/examples/inner_outer.rb
DELETED
@@ -1,51 +0,0 @@
|
|
1
|
-
# Autogenerated from a Treetop grammar. Edits may be lost.
|
2
|
-
|
3
|
-
|
4
|
-
module InnerOuter
|
5
|
-
include Treetop::Runtime
|
6
|
-
|
7
|
-
def root
|
8
|
-
@root ||= :inner_outer
|
9
|
-
end
|
10
|
-
|
11
|
-
module InnerOuter0
|
12
|
-
def inner
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
module InnerOuter1
|
17
|
-
def outer
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
def _nt_inner_outer
|
22
|
-
start_index = index
|
23
|
-
if node_cache[:inner_outer].has_key?(index)
|
24
|
-
cached = node_cache[:inner_outer][index]
|
25
|
-
if cached
|
26
|
-
node_cache[:inner_outer][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
|
27
|
-
@index = cached.interval.end
|
28
|
-
end
|
29
|
-
return cached
|
30
|
-
end
|
31
|
-
|
32
|
-
if (match_len = has_terminal?("foo", false, index))
|
33
|
-
r0 = instantiate_node(SyntaxNode,input, index...(index + match_len))
|
34
|
-
r0.extend(InnerOuter0)
|
35
|
-
@index += match_len
|
36
|
-
else
|
37
|
-
terminal_parse_failure('"foo"')
|
38
|
-
r0 = nil
|
39
|
-
end
|
40
|
-
|
41
|
-
node_cache[:inner_outer][start_index] = r0
|
42
|
-
|
43
|
-
r0
|
44
|
-
end
|
45
|
-
|
46
|
-
end
|
47
|
-
|
48
|
-
class InnerOuterParser < Treetop::Runtime::CompiledParser
|
49
|
-
include InnerOuter
|
50
|
-
end
|
51
|
-
|
data/examples/inner_outer.tt
DELETED
data/examples/numerals.rb
DELETED
@@ -1,210 +0,0 @@
|
|
1
|
-
# Autogenerated from a Treetop grammar. Edits may be lost.
|
2
|
-
|
3
|
-
|
4
|
-
module Numerals
|
5
|
-
include Treetop::Runtime
|
6
|
-
|
7
|
-
def root
|
8
|
-
@root ||= :percentage
|
9
|
-
end
|
10
|
-
|
11
|
-
module Percentage0
|
12
|
-
def decimal
|
13
|
-
elements[0]
|
14
|
-
end
|
15
|
-
|
16
|
-
end
|
17
|
-
|
18
|
-
module Percentage1
|
19
|
-
def to_f
|
20
|
-
decimal.to_f / 100
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
def _nt_percentage
|
25
|
-
start_index = index
|
26
|
-
if node_cache[:percentage].has_key?(index)
|
27
|
-
cached = node_cache[:percentage][index]
|
28
|
-
if cached
|
29
|
-
node_cache[:percentage][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
|
30
|
-
@index = cached.interval.end
|
31
|
-
end
|
32
|
-
return cached
|
33
|
-
end
|
34
|
-
|
35
|
-
i0, s0 = index, []
|
36
|
-
r1 = _nt_decimal
|
37
|
-
s0 << r1
|
38
|
-
if r1
|
39
|
-
if (match_len = has_terminal?("%", false, index))
|
40
|
-
r2 = true
|
41
|
-
@index += match_len
|
42
|
-
else
|
43
|
-
terminal_parse_failure('"%"')
|
44
|
-
r2 = nil
|
45
|
-
end
|
46
|
-
s0 << r2
|
47
|
-
end
|
48
|
-
if s0.last
|
49
|
-
r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
|
50
|
-
r0.extend(Percentage0)
|
51
|
-
r0.extend(Percentage1)
|
52
|
-
else
|
53
|
-
@index = i0
|
54
|
-
r0 = nil
|
55
|
-
end
|
56
|
-
|
57
|
-
node_cache[:percentage][start_index] = r0
|
58
|
-
|
59
|
-
r0
|
60
|
-
end
|
61
|
-
|
62
|
-
module Decimal0
|
63
|
-
def sign
|
64
|
-
elements[0]
|
65
|
-
end
|
66
|
-
|
67
|
-
end
|
68
|
-
|
69
|
-
module Decimal1
|
70
|
-
def to_f
|
71
|
-
text_value.to_f
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
75
|
-
def _nt_decimal
|
76
|
-
start_index = index
|
77
|
-
if node_cache[:decimal].has_key?(index)
|
78
|
-
cached = node_cache[:decimal][index]
|
79
|
-
if cached
|
80
|
-
node_cache[:decimal][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
|
81
|
-
@index = cached.interval.end
|
82
|
-
end
|
83
|
-
return cached
|
84
|
-
end
|
85
|
-
|
86
|
-
i0, s0 = index, []
|
87
|
-
r1 = _nt_sign
|
88
|
-
s0 << r1
|
89
|
-
if r1
|
90
|
-
s2, i2 = [], index
|
91
|
-
loop do
|
92
|
-
if has_terminal?(@regexps[gr = '\A[0-9]'] ||= Regexp.new(gr), :regexp, index)
|
93
|
-
r3 = true
|
94
|
-
@index += 1
|
95
|
-
else
|
96
|
-
terminal_parse_failure('[0-9]')
|
97
|
-
r3 = nil
|
98
|
-
end
|
99
|
-
if r3
|
100
|
-
s2 << r3
|
101
|
-
else
|
102
|
-
break
|
103
|
-
end
|
104
|
-
end
|
105
|
-
if s2.empty?
|
106
|
-
@index = i2
|
107
|
-
r2 = nil
|
108
|
-
else
|
109
|
-
r2 = instantiate_node(SyntaxNode,input, i2...index, s2)
|
110
|
-
end
|
111
|
-
s0 << r2
|
112
|
-
if r2
|
113
|
-
if (match_len = has_terminal?('.', false, index))
|
114
|
-
r4 = true
|
115
|
-
@index += match_len
|
116
|
-
else
|
117
|
-
terminal_parse_failure('\'.\'')
|
118
|
-
r4 = nil
|
119
|
-
end
|
120
|
-
s0 << r4
|
121
|
-
if r4
|
122
|
-
s5, i5 = [], index
|
123
|
-
loop do
|
124
|
-
if has_terminal?(@regexps[gr = '\A[0-9]'] ||= Regexp.new(gr), :regexp, index)
|
125
|
-
r6 = true
|
126
|
-
@index += 1
|
127
|
-
else
|
128
|
-
terminal_parse_failure('[0-9]')
|
129
|
-
r6 = nil
|
130
|
-
end
|
131
|
-
if r6
|
132
|
-
s5 << r6
|
133
|
-
else
|
134
|
-
break
|
135
|
-
end
|
136
|
-
end
|
137
|
-
r5 = instantiate_node(SyntaxNode,input, i5...index, s5)
|
138
|
-
s0 << r5
|
139
|
-
end
|
140
|
-
end
|
141
|
-
end
|
142
|
-
if s0.last
|
143
|
-
r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
|
144
|
-
r0.extend(Decimal0)
|
145
|
-
r0.extend(Decimal1)
|
146
|
-
else
|
147
|
-
@index = i0
|
148
|
-
r0 = nil
|
149
|
-
end
|
150
|
-
|
151
|
-
node_cache[:decimal][start_index] = r0
|
152
|
-
|
153
|
-
r0
|
154
|
-
end
|
155
|
-
|
156
|
-
def _nt_sign
|
157
|
-
start_index = index
|
158
|
-
if node_cache[:sign].has_key?(index)
|
159
|
-
cached = node_cache[:sign][index]
|
160
|
-
if cached
|
161
|
-
node_cache[:sign][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
|
162
|
-
@index = cached.interval.end
|
163
|
-
end
|
164
|
-
return cached
|
165
|
-
end
|
166
|
-
|
167
|
-
i1 = index
|
168
|
-
if (match_len = has_terminal?('+', false, index))
|
169
|
-
r2 = true
|
170
|
-
@index += match_len
|
171
|
-
else
|
172
|
-
terminal_parse_failure('\'+\'')
|
173
|
-
r2 = nil
|
174
|
-
end
|
175
|
-
if r2
|
176
|
-
r2 = SyntaxNode.new(input, (index-1)...index) if r2 == true
|
177
|
-
r1 = r2
|
178
|
-
else
|
179
|
-
if (match_len = has_terminal?('-', false, index))
|
180
|
-
r3 = true
|
181
|
-
@index += match_len
|
182
|
-
else
|
183
|
-
terminal_parse_failure('\'-\'')
|
184
|
-
r3 = nil
|
185
|
-
end
|
186
|
-
if r3
|
187
|
-
r3 = SyntaxNode.new(input, (index-1)...index) if r3 == true
|
188
|
-
r1 = r3
|
189
|
-
else
|
190
|
-
@index = i1
|
191
|
-
r1 = nil
|
192
|
-
end
|
193
|
-
end
|
194
|
-
if r1
|
195
|
-
r0 = r1
|
196
|
-
else
|
197
|
-
r0 = instantiate_node(SyntaxNode,input, index...index)
|
198
|
-
end
|
199
|
-
|
200
|
-
node_cache[:sign][start_index] = r0
|
201
|
-
|
202
|
-
r0
|
203
|
-
end
|
204
|
-
|
205
|
-
end
|
206
|
-
|
207
|
-
class NumeralsParser < Treetop::Runtime::CompiledParser
|
208
|
-
include Numerals
|
209
|
-
end
|
210
|
-
|
data/examples/numerals.tt
DELETED
@@ -1,21 +0,0 @@
|
|
1
|
-
grammar Numerals
|
2
|
-
rule percentage
|
3
|
-
(decimal "%") {
|
4
|
-
def to_f
|
5
|
-
decimal.to_f / 100
|
6
|
-
end
|
7
|
-
}
|
8
|
-
end
|
9
|
-
|
10
|
-
rule decimal
|
11
|
-
sign [0-9]+ '.' [0-9]* {
|
12
|
-
def to_f
|
13
|
-
text_value.to_f
|
14
|
-
end
|
15
|
-
}
|
16
|
-
end
|
17
|
-
|
18
|
-
rule sign
|
19
|
-
('+'/'-')?
|
20
|
-
end
|
21
|
-
end
|