configgy 0.6
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +2 -0
- data/Manifest +10 -0
- data/Rakefile +21 -0
- data/configgy.gemspec +30 -0
- data/lib/configgy.rb +13 -0
- data/lib/configgy/config_map.rb +141 -0
- data/lib/configgy/config_parser.rb +20 -0
- data/lib/treetop/configgy.rb +1617 -0
- data/lib/treetop/configgy.treetop +177 -0
- data/spec/config_map_spec.rb +161 -0
- data/spec/config_parser_spec.rb +283 -0
- metadata +75 -0
data/CHANGELOG
ADDED
data/Manifest
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
|
2
|
+
require 'rubygems'
|
3
|
+
gem 'treetop'
|
4
|
+
require 'echoe'
|
5
|
+
|
6
|
+
require 'spec/rake/spectask'
|
7
|
+
|
8
|
+
Echoe.new("configgy") do |p|
|
9
|
+
p.version = "0.6"
|
10
|
+
p.author = "Robey Pointer"
|
11
|
+
p.email = "robeypointer@gmail.com"
|
12
|
+
p.project = "configgy"
|
13
|
+
p.summary = "config file parser for ruby"
|
14
|
+
p.rdoc_pattern = /README|TODO|LICENSE|CHANGELOG|BENCH|COMPAT|exceptions|behaviors|rails.rb/
|
15
|
+
p.spec_pattern = "spec/*_spec.rb"
|
16
|
+
p.ignore_pattern = [ "configgyrb.tmproj" ]
|
17
|
+
end
|
18
|
+
|
19
|
+
task :treetop do
|
20
|
+
system("tt lib/treetop/configgy.treetop")
|
21
|
+
end
|
data/configgy.gemspec
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = %q{configgy}
|
5
|
+
s.version = "0.6"
|
6
|
+
|
7
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
8
|
+
s.authors = ["Robey Pointer"]
|
9
|
+
s.date = %q{2010-03-01}
|
10
|
+
s.description = %q{config file parser for ruby}
|
11
|
+
s.email = %q{robeypointer@gmail.com}
|
12
|
+
s.extra_rdoc_files = ["CHANGELOG"]
|
13
|
+
s.files = ["CHANGELOG", "Manifest", "Rakefile", "lib/configgy.rb", "lib/configgy/config_map.rb", "lib/configgy/config_parser.rb", "lib/treetop/configgy.rb", "lib/treetop/configgy.treetop", "spec/config_map_spec.rb", "spec/config_parser_spec.rb", "configgy.gemspec"]
|
14
|
+
s.homepage = %q{}
|
15
|
+
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Configgy"]
|
16
|
+
s.require_paths = ["lib"]
|
17
|
+
s.rubyforge_project = %q{configgy}
|
18
|
+
s.rubygems_version = %q{1.3.6}
|
19
|
+
s.summary = %q{config file parser for ruby}
|
20
|
+
|
21
|
+
if s.respond_to? :specification_version then
|
22
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
23
|
+
s.specification_version = 3
|
24
|
+
|
25
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
26
|
+
else
|
27
|
+
end
|
28
|
+
else
|
29
|
+
end
|
30
|
+
end
|
data/lib/configgy.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
require "rubygems"
|
2
|
+
require "treetop"
|
3
|
+
require "treetop/configgy"
|
4
|
+
require "configgy/config_map"
|
5
|
+
require "configgy/config_parser"
|
6
|
+
|
7
|
+
class ConfigException < RuntimeError; end
|
8
|
+
|
9
|
+
module Configgy
|
10
|
+
def self.load_file(filename)
|
11
|
+
Configgy::ConfigParser.new.load_file(filename)
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,141 @@
|
|
1
|
+
module Configgy
|
2
|
+
class ConfigMap
|
3
|
+
attr_reader :name, :cells
|
4
|
+
attr_accessor :root, :monitored, :inherit_from
|
5
|
+
|
6
|
+
def initialize(root, name)
|
7
|
+
@root = root
|
8
|
+
@name = name
|
9
|
+
@monitored = false
|
10
|
+
@inherit_from = nil
|
11
|
+
@cells = {}
|
12
|
+
end
|
13
|
+
|
14
|
+
def create_nested(key)
|
15
|
+
config_map = ConfigMap.new(@root, name == "" ? key : name + "." + key)
|
16
|
+
config_map.monitored = @monitored
|
17
|
+
@cells[key] = config_map
|
18
|
+
end
|
19
|
+
|
20
|
+
# find (ConfigMap, key) after following any dot-separated names
|
21
|
+
def recurse(key, &block)
|
22
|
+
left, right = key.split(".", 2)
|
23
|
+
if right
|
24
|
+
create_nested(left) unless @cells.has_key?(left)
|
25
|
+
raise ConfigException("illegal key #{key}") unless @cells[left].respond_to?(:recurse)
|
26
|
+
@cells[left].recurse(right, &block)
|
27
|
+
else
|
28
|
+
yield [ self, key ]
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def lookup_cell(key)
|
33
|
+
left, right = key.split(".", 2)
|
34
|
+
if @cells.has_key?(left)
|
35
|
+
if right
|
36
|
+
if @cells[left].respond_to?(:lookup_cell)
|
37
|
+
@cells[left].lookup_cell(right)
|
38
|
+
else
|
39
|
+
nil
|
40
|
+
end
|
41
|
+
else
|
42
|
+
@cells[left]
|
43
|
+
end
|
44
|
+
elsif @inherit_from
|
45
|
+
@inherit_from.lookup_cell(key)
|
46
|
+
else
|
47
|
+
nil
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def []=(key, value)
|
52
|
+
key = key.to_s
|
53
|
+
if @monitored
|
54
|
+
@root.deep_set(@name, key, value)
|
55
|
+
else
|
56
|
+
recurse(key) do |config_map, key|
|
57
|
+
config_map.cells[key] = value
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def [](key)
|
63
|
+
lookup_cell(key.to_s)
|
64
|
+
end
|
65
|
+
|
66
|
+
def delete(key)
|
67
|
+
key = key.to_s
|
68
|
+
if @monitored
|
69
|
+
@root.deep_delete(@name, key)
|
70
|
+
else
|
71
|
+
recurse(key) { |config_map, key| config_map.cells.delete(key) }
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
def has_key?(key)
|
76
|
+
!lookup_cell(key.to_s).nil?
|
77
|
+
end
|
78
|
+
|
79
|
+
def ==(other)
|
80
|
+
other.instance_of?(self.class) and @cells == other.cells
|
81
|
+
end
|
82
|
+
|
83
|
+
def to_map
|
84
|
+
rv = @cells.dup
|
85
|
+
rv.each do |k, v|
|
86
|
+
if v.instance_of?(ConfigMap)
|
87
|
+
rv[k] = v.to_map
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
def copy_to(map)
|
93
|
+
@inherit_from.copy_to(map) if @inherit_from
|
94
|
+
@cells.each do |k, v|
|
95
|
+
# assume everything that doesn't respond to dup is immutable.
|
96
|
+
map[k] = begin v.dup rescue v end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
def dup
|
101
|
+
map = ConfigMap.new(@root, @name)
|
102
|
+
copy_to(map)
|
103
|
+
map
|
104
|
+
end
|
105
|
+
|
106
|
+
def merge(map)
|
107
|
+
rv = dup
|
108
|
+
map.each { |k, v| rv[k] = v }
|
109
|
+
rv
|
110
|
+
end
|
111
|
+
|
112
|
+
def to_config_string
|
113
|
+
to_config_list.join("\n") + "\n"
|
114
|
+
end
|
115
|
+
|
116
|
+
def to_config_list
|
117
|
+
@cells.keys.sort.map do |k|
|
118
|
+
v = @cells[k]
|
119
|
+
if v.instance_of?(ConfigMap)
|
120
|
+
[ "#{k}" + (v.inherit_from ? " (inherit=\"#{v.inherit_from.name}\")" : "") + " {", v.to_config_list.map { |s| " " + s }, "}" ].flatten
|
121
|
+
else
|
122
|
+
"#{k} = #{v.inspect}"
|
123
|
+
end
|
124
|
+
end.flatten
|
125
|
+
end
|
126
|
+
|
127
|
+
def interpolate(s)
|
128
|
+
s.gsub(/(?!\\)\$\((\w[\w\d\._-]*)\)|\\\$/) do |m|
|
129
|
+
if m == "\\$"
|
130
|
+
"$"
|
131
|
+
else
|
132
|
+
([ self, @root, ENV ].find { |config_map| config_map[$1] } || {})[$1]
|
133
|
+
end
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
def inspect
|
138
|
+
"{#{@name}" + (@inherit_from ? " (inherit=#{@inherit_from.name})" : "") + ": " + @cells.keys.sort.map { |k| "#{k}=#{@cells[k].inspect}" }.join(" ") + "}"
|
139
|
+
end
|
140
|
+
end
|
141
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module Configgy
|
2
|
+
class ConfigParser < Treetop_ConfiggyParser
|
3
|
+
def import_file(filename)
|
4
|
+
File.open(filename, "r").read
|
5
|
+
end
|
6
|
+
|
7
|
+
def read(s, map=nil)
|
8
|
+
if !map
|
9
|
+
map = Configgy::ConfigMap.new(nil, "")
|
10
|
+
map.root = map
|
11
|
+
end
|
12
|
+
parse(s).apply(map, self)
|
13
|
+
map
|
14
|
+
end
|
15
|
+
|
16
|
+
def load_file(filename, map=nil)
|
17
|
+
read(import_file(filename), map)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,1617 @@
|
|
1
|
+
# Autogenerated from a Treetop grammar. Edits may be lost.
|
2
|
+
|
3
|
+
|
4
|
+
module Treetop_Configgy
|
5
|
+
include Treetop::Runtime
|
6
|
+
|
7
|
+
def root
|
8
|
+
@root || :root
|
9
|
+
end
|
10
|
+
|
11
|
+
module Root0
|
12
|
+
def d
|
13
|
+
elements[0]
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
|
18
|
+
module Root1
|
19
|
+
def apply(config_map, parser)
|
20
|
+
d.elements.each { |node| node.apply(config_map, parser) }
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def _nt_root
|
25
|
+
start_index = index
|
26
|
+
if node_cache[:root].has_key?(index)
|
27
|
+
cached = node_cache[:root][index]
|
28
|
+
@index = cached.interval.end if cached
|
29
|
+
return cached
|
30
|
+
end
|
31
|
+
|
32
|
+
i0, s0 = index, []
|
33
|
+
s1, i1 = [], index
|
34
|
+
loop do
|
35
|
+
r2 = _nt_declaration
|
36
|
+
if r2
|
37
|
+
s1 << r2
|
38
|
+
else
|
39
|
+
break
|
40
|
+
end
|
41
|
+
end
|
42
|
+
r1 = instantiate_node(SyntaxNode,input, i1...index, s1)
|
43
|
+
s0 << r1
|
44
|
+
if r1
|
45
|
+
s3, i3 = [], index
|
46
|
+
loop do
|
47
|
+
r4 = _nt_whitespace
|
48
|
+
if r4
|
49
|
+
s3 << r4
|
50
|
+
else
|
51
|
+
break
|
52
|
+
end
|
53
|
+
end
|
54
|
+
r3 = instantiate_node(SyntaxNode,input, i3...index, s3)
|
55
|
+
s0 << r3
|
56
|
+
end
|
57
|
+
if s0.last
|
58
|
+
r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
|
59
|
+
r0.extend(Root0)
|
60
|
+
r0.extend(Root1)
|
61
|
+
else
|
62
|
+
@index = i0
|
63
|
+
r0 = nil
|
64
|
+
end
|
65
|
+
|
66
|
+
node_cache[:root][start_index] = r0
|
67
|
+
|
68
|
+
r0
|
69
|
+
end
|
70
|
+
|
71
|
+
module Declaration0
|
72
|
+
def d
|
73
|
+
elements[1]
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
module Declaration1
|
78
|
+
def apply(config_map, parser)
|
79
|
+
d.apply(config_map, parser)
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
def _nt_declaration
|
84
|
+
start_index = index
|
85
|
+
if node_cache[:declaration].has_key?(index)
|
86
|
+
cached = node_cache[:declaration][index]
|
87
|
+
@index = cached.interval.end if cached
|
88
|
+
return cached
|
89
|
+
end
|
90
|
+
|
91
|
+
i0, s0 = index, []
|
92
|
+
s1, i1 = [], index
|
93
|
+
loop do
|
94
|
+
r2 = _nt_whitespace
|
95
|
+
if r2
|
96
|
+
s1 << r2
|
97
|
+
else
|
98
|
+
break
|
99
|
+
end
|
100
|
+
end
|
101
|
+
r1 = instantiate_node(SyntaxNode,input, i1...index, s1)
|
102
|
+
s0 << r1
|
103
|
+
if r1
|
104
|
+
i3 = index
|
105
|
+
r4 = _nt_include_file
|
106
|
+
if r4
|
107
|
+
r3 = r4
|
108
|
+
else
|
109
|
+
r5 = _nt_assignment
|
110
|
+
if r5
|
111
|
+
r3 = r5
|
112
|
+
else
|
113
|
+
r6 = _nt_toggle
|
114
|
+
if r6
|
115
|
+
r3 = r6
|
116
|
+
else
|
117
|
+
r7 = _nt_section
|
118
|
+
if r7
|
119
|
+
r3 = r7
|
120
|
+
else
|
121
|
+
@index = i3
|
122
|
+
r3 = nil
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
127
|
+
s0 << r3
|
128
|
+
end
|
129
|
+
if s0.last
|
130
|
+
r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
|
131
|
+
r0.extend(Declaration0)
|
132
|
+
r0.extend(Declaration1)
|
133
|
+
else
|
134
|
+
@index = i0
|
135
|
+
r0 = nil
|
136
|
+
end
|
137
|
+
|
138
|
+
node_cache[:declaration][start_index] = r0
|
139
|
+
|
140
|
+
r0
|
141
|
+
end
|
142
|
+
|
143
|
+
module Assignment0
|
144
|
+
def identifier
|
145
|
+
elements[0]
|
146
|
+
end
|
147
|
+
|
148
|
+
def op
|
149
|
+
elements[2]
|
150
|
+
end
|
151
|
+
|
152
|
+
def value
|
153
|
+
elements[4]
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
module Assignment1
|
158
|
+
def apply(config_map, parser)
|
159
|
+
key = identifier.text_value
|
160
|
+
if (op.text_value == "=") or !config_map.has_key?(key)
|
161
|
+
config_map[key] = value.to_value(config_map)
|
162
|
+
end
|
163
|
+
end
|
164
|
+
end
|
165
|
+
|
166
|
+
def _nt_assignment
|
167
|
+
start_index = index
|
168
|
+
if node_cache[:assignment].has_key?(index)
|
169
|
+
cached = node_cache[:assignment][index]
|
170
|
+
@index = cached.interval.end if cached
|
171
|
+
return cached
|
172
|
+
end
|
173
|
+
|
174
|
+
i0, s0 = index, []
|
175
|
+
r1 = _nt_identifier
|
176
|
+
s0 << r1
|
177
|
+
if r1
|
178
|
+
s2, i2 = [], index
|
179
|
+
loop do
|
180
|
+
r3 = _nt_whitespace
|
181
|
+
if r3
|
182
|
+
s2 << r3
|
183
|
+
else
|
184
|
+
break
|
185
|
+
end
|
186
|
+
end
|
187
|
+
r2 = instantiate_node(SyntaxNode,input, i2...index, s2)
|
188
|
+
s0 << r2
|
189
|
+
if r2
|
190
|
+
i4 = index
|
191
|
+
if has_terminal?("=", false, index)
|
192
|
+
r5 = instantiate_node(SyntaxNode,input, index...(index + 1))
|
193
|
+
@index += 1
|
194
|
+
else
|
195
|
+
terminal_parse_failure("=")
|
196
|
+
r5 = nil
|
197
|
+
end
|
198
|
+
if r5
|
199
|
+
r4 = r5
|
200
|
+
else
|
201
|
+
if has_terminal?("?=", false, index)
|
202
|
+
r6 = instantiate_node(SyntaxNode,input, index...(index + 2))
|
203
|
+
@index += 2
|
204
|
+
else
|
205
|
+
terminal_parse_failure("?=")
|
206
|
+
r6 = nil
|
207
|
+
end
|
208
|
+
if r6
|
209
|
+
r4 = r6
|
210
|
+
else
|
211
|
+
@index = i4
|
212
|
+
r4 = nil
|
213
|
+
end
|
214
|
+
end
|
215
|
+
s0 << r4
|
216
|
+
if r4
|
217
|
+
s7, i7 = [], index
|
218
|
+
loop do
|
219
|
+
r8 = _nt_whitespace
|
220
|
+
if r8
|
221
|
+
s7 << r8
|
222
|
+
else
|
223
|
+
break
|
224
|
+
end
|
225
|
+
end
|
226
|
+
r7 = instantiate_node(SyntaxNode,input, i7...index, s7)
|
227
|
+
s0 << r7
|
228
|
+
if r7
|
229
|
+
r9 = _nt_value
|
230
|
+
s0 << r9
|
231
|
+
end
|
232
|
+
end
|
233
|
+
end
|
234
|
+
end
|
235
|
+
if s0.last
|
236
|
+
r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
|
237
|
+
r0.extend(Assignment0)
|
238
|
+
r0.extend(Assignment1)
|
239
|
+
else
|
240
|
+
@index = i0
|
241
|
+
r0 = nil
|
242
|
+
end
|
243
|
+
|
244
|
+
node_cache[:assignment][start_index] = r0
|
245
|
+
|
246
|
+
r0
|
247
|
+
end
|
248
|
+
|
249
|
+
module Toggle0
|
250
|
+
def identifier
|
251
|
+
elements[0]
|
252
|
+
end
|
253
|
+
|
254
|
+
def true_false
|
255
|
+
elements[2]
|
256
|
+
end
|
257
|
+
end
|
258
|
+
|
259
|
+
module Toggle1
|
260
|
+
def apply(config_map, parser)
|
261
|
+
key = identifier.text_value
|
262
|
+
config_map[key] = true_false.to_value
|
263
|
+
end
|
264
|
+
end
|
265
|
+
|
266
|
+
def _nt_toggle
|
267
|
+
start_index = index
|
268
|
+
if node_cache[:toggle].has_key?(index)
|
269
|
+
cached = node_cache[:toggle][index]
|
270
|
+
@index = cached.interval.end if cached
|
271
|
+
return cached
|
272
|
+
end
|
273
|
+
|
274
|
+
i0, s0 = index, []
|
275
|
+
r1 = _nt_identifier
|
276
|
+
s0 << r1
|
277
|
+
if r1
|
278
|
+
s2, i2 = [], index
|
279
|
+
loop do
|
280
|
+
r3 = _nt_whitespace
|
281
|
+
if r3
|
282
|
+
s2 << r3
|
283
|
+
else
|
284
|
+
break
|
285
|
+
end
|
286
|
+
end
|
287
|
+
r2 = instantiate_node(SyntaxNode,input, i2...index, s2)
|
288
|
+
s0 << r2
|
289
|
+
if r2
|
290
|
+
r4 = _nt_true_false
|
291
|
+
s0 << r4
|
292
|
+
end
|
293
|
+
end
|
294
|
+
if s0.last
|
295
|
+
r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
|
296
|
+
r0.extend(Toggle0)
|
297
|
+
r0.extend(Toggle1)
|
298
|
+
else
|
299
|
+
@index = i0
|
300
|
+
r0 = nil
|
301
|
+
end
|
302
|
+
|
303
|
+
node_cache[:toggle][start_index] = r0
|
304
|
+
|
305
|
+
r0
|
306
|
+
end
|
307
|
+
|
308
|
+
def _nt_value
|
309
|
+
start_index = index
|
310
|
+
if node_cache[:value].has_key?(index)
|
311
|
+
cached = node_cache[:value][index]
|
312
|
+
@index = cached.interval.end if cached
|
313
|
+
return cached
|
314
|
+
end
|
315
|
+
|
316
|
+
i0 = index
|
317
|
+
r1 = _nt_number
|
318
|
+
if r1
|
319
|
+
r0 = r1
|
320
|
+
else
|
321
|
+
r2 = _nt_string
|
322
|
+
if r2
|
323
|
+
r0 = r2
|
324
|
+
else
|
325
|
+
r3 = _nt_true_false
|
326
|
+
if r3
|
327
|
+
r0 = r3
|
328
|
+
else
|
329
|
+
r4 = _nt_string_list
|
330
|
+
if r4
|
331
|
+
r0 = r4
|
332
|
+
else
|
333
|
+
@index = i0
|
334
|
+
r0 = nil
|
335
|
+
end
|
336
|
+
end
|
337
|
+
end
|
338
|
+
end
|
339
|
+
|
340
|
+
node_cache[:value][start_index] = r0
|
341
|
+
|
342
|
+
r0
|
343
|
+
end
|
344
|
+
|
345
|
+
module Whitespace0
|
346
|
+
end
|
347
|
+
|
348
|
+
def _nt_whitespace
|
349
|
+
start_index = index
|
350
|
+
if node_cache[:whitespace].has_key?(index)
|
351
|
+
cached = node_cache[:whitespace][index]
|
352
|
+
@index = cached.interval.end if cached
|
353
|
+
return cached
|
354
|
+
end
|
355
|
+
|
356
|
+
i0 = index
|
357
|
+
if has_terminal?(" ", false, index)
|
358
|
+
r1 = instantiate_node(SyntaxNode,input, index...(index + 1))
|
359
|
+
@index += 1
|
360
|
+
else
|
361
|
+
terminal_parse_failure(" ")
|
362
|
+
r1 = nil
|
363
|
+
end
|
364
|
+
if r1
|
365
|
+
r0 = r1
|
366
|
+
else
|
367
|
+
if has_terminal?("\t", false, index)
|
368
|
+
r2 = instantiate_node(SyntaxNode,input, index...(index + 1))
|
369
|
+
@index += 1
|
370
|
+
else
|
371
|
+
terminal_parse_failure("\t")
|
372
|
+
r2 = nil
|
373
|
+
end
|
374
|
+
if r2
|
375
|
+
r0 = r2
|
376
|
+
else
|
377
|
+
if has_terminal?("\n", false, index)
|
378
|
+
r3 = instantiate_node(SyntaxNode,input, index...(index + 1))
|
379
|
+
@index += 1
|
380
|
+
else
|
381
|
+
terminal_parse_failure("\n")
|
382
|
+
r3 = nil
|
383
|
+
end
|
384
|
+
if r3
|
385
|
+
r0 = r3
|
386
|
+
else
|
387
|
+
i4, s4 = index, []
|
388
|
+
if has_terminal?("#", false, index)
|
389
|
+
r5 = instantiate_node(SyntaxNode,input, index...(index + 1))
|
390
|
+
@index += 1
|
391
|
+
else
|
392
|
+
terminal_parse_failure("#")
|
393
|
+
r5 = nil
|
394
|
+
end
|
395
|
+
s4 << r5
|
396
|
+
if r5
|
397
|
+
s6, i6 = [], index
|
398
|
+
loop do
|
399
|
+
if has_terminal?('\G[^\\n]', true, index)
|
400
|
+
r7 = true
|
401
|
+
@index += 1
|
402
|
+
else
|
403
|
+
r7 = nil
|
404
|
+
end
|
405
|
+
if r7
|
406
|
+
s6 << r7
|
407
|
+
else
|
408
|
+
break
|
409
|
+
end
|
410
|
+
end
|
411
|
+
r6 = instantiate_node(SyntaxNode,input, i6...index, s6)
|
412
|
+
s4 << r6
|
413
|
+
if r6
|
414
|
+
if has_terminal?("\n", false, index)
|
415
|
+
r8 = instantiate_node(SyntaxNode,input, index...(index + 1))
|
416
|
+
@index += 1
|
417
|
+
else
|
418
|
+
terminal_parse_failure("\n")
|
419
|
+
r8 = nil
|
420
|
+
end
|
421
|
+
s4 << r8
|
422
|
+
end
|
423
|
+
end
|
424
|
+
if s4.last
|
425
|
+
r4 = instantiate_node(SyntaxNode,input, i4...index, s4)
|
426
|
+
r4.extend(Whitespace0)
|
427
|
+
else
|
428
|
+
@index = i4
|
429
|
+
r4 = nil
|
430
|
+
end
|
431
|
+
if r4
|
432
|
+
r0 = r4
|
433
|
+
else
|
434
|
+
@index = i0
|
435
|
+
r0 = nil
|
436
|
+
end
|
437
|
+
end
|
438
|
+
end
|
439
|
+
end
|
440
|
+
|
441
|
+
node_cache[:whitespace][start_index] = r0
|
442
|
+
|
443
|
+
r0
|
444
|
+
end
|
445
|
+
|
446
|
+
module Number0
|
447
|
+
end
|
448
|
+
|
449
|
+
module Number1
|
450
|
+
def decimal
|
451
|
+
elements[2]
|
452
|
+
end
|
453
|
+
end
|
454
|
+
|
455
|
+
module Number2
|
456
|
+
def to_value(config_map=nil)
|
457
|
+
decimal.text_value.empty? ? text_value.to_i : text_value.to_f
|
458
|
+
end
|
459
|
+
end
|
460
|
+
|
461
|
+
def _nt_number
|
462
|
+
start_index = index
|
463
|
+
if node_cache[:number].has_key?(index)
|
464
|
+
cached = node_cache[:number][index]
|
465
|
+
@index = cached.interval.end if cached
|
466
|
+
return cached
|
467
|
+
end
|
468
|
+
|
469
|
+
i0, s0 = index, []
|
470
|
+
if has_terminal?("-", false, index)
|
471
|
+
r2 = instantiate_node(SyntaxNode,input, index...(index + 1))
|
472
|
+
@index += 1
|
473
|
+
else
|
474
|
+
terminal_parse_failure("-")
|
475
|
+
r2 = nil
|
476
|
+
end
|
477
|
+
if r2
|
478
|
+
r1 = r2
|
479
|
+
else
|
480
|
+
r1 = instantiate_node(SyntaxNode,input, index...index)
|
481
|
+
end
|
482
|
+
s0 << r1
|
483
|
+
if r1
|
484
|
+
s3, i3 = [], index
|
485
|
+
loop do
|
486
|
+
if has_terminal?('\G[0-9]', true, index)
|
487
|
+
r4 = true
|
488
|
+
@index += 1
|
489
|
+
else
|
490
|
+
r4 = nil
|
491
|
+
end
|
492
|
+
if r4
|
493
|
+
s3 << r4
|
494
|
+
else
|
495
|
+
break
|
496
|
+
end
|
497
|
+
end
|
498
|
+
if s3.empty?
|
499
|
+
@index = i3
|
500
|
+
r3 = nil
|
501
|
+
else
|
502
|
+
r3 = instantiate_node(SyntaxNode,input, i3...index, s3)
|
503
|
+
end
|
504
|
+
s0 << r3
|
505
|
+
if r3
|
506
|
+
i6, s6 = index, []
|
507
|
+
if has_terminal?(".", false, index)
|
508
|
+
r7 = instantiate_node(SyntaxNode,input, index...(index + 1))
|
509
|
+
@index += 1
|
510
|
+
else
|
511
|
+
terminal_parse_failure(".")
|
512
|
+
r7 = nil
|
513
|
+
end
|
514
|
+
s6 << r7
|
515
|
+
if r7
|
516
|
+
s8, i8 = [], index
|
517
|
+
loop do
|
518
|
+
if has_terminal?('\G[0-9]', true, index)
|
519
|
+
r9 = true
|
520
|
+
@index += 1
|
521
|
+
else
|
522
|
+
r9 = nil
|
523
|
+
end
|
524
|
+
if r9
|
525
|
+
s8 << r9
|
526
|
+
else
|
527
|
+
break
|
528
|
+
end
|
529
|
+
end
|
530
|
+
if s8.empty?
|
531
|
+
@index = i8
|
532
|
+
r8 = nil
|
533
|
+
else
|
534
|
+
r8 = instantiate_node(SyntaxNode,input, i8...index, s8)
|
535
|
+
end
|
536
|
+
s6 << r8
|
537
|
+
end
|
538
|
+
if s6.last
|
539
|
+
r6 = instantiate_node(SyntaxNode,input, i6...index, s6)
|
540
|
+
r6.extend(Number0)
|
541
|
+
else
|
542
|
+
@index = i6
|
543
|
+
r6 = nil
|
544
|
+
end
|
545
|
+
if r6
|
546
|
+
r5 = r6
|
547
|
+
else
|
548
|
+
r5 = instantiate_node(SyntaxNode,input, index...index)
|
549
|
+
end
|
550
|
+
s0 << r5
|
551
|
+
end
|
552
|
+
end
|
553
|
+
if s0.last
|
554
|
+
r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
|
555
|
+
r0.extend(Number1)
|
556
|
+
r0.extend(Number2)
|
557
|
+
else
|
558
|
+
@index = i0
|
559
|
+
r0 = nil
|
560
|
+
end
|
561
|
+
|
562
|
+
node_cache[:number][start_index] = r0
|
563
|
+
|
564
|
+
r0
|
565
|
+
end
|
566
|
+
|
567
|
+
module String0
|
568
|
+
def raw
|
569
|
+
elements[1]
|
570
|
+
end
|
571
|
+
|
572
|
+
end
|
573
|
+
|
574
|
+
module String1
|
575
|
+
def to_value(config_map=nil)
|
576
|
+
rv = raw.elements.inject("") { |total, segment| total + segment.unquoted }
|
577
|
+
config_map ? config_map.interpolate(rv) : rv
|
578
|
+
end
|
579
|
+
end
|
580
|
+
|
581
|
+
def _nt_string
|
582
|
+
start_index = index
|
583
|
+
if node_cache[:string].has_key?(index)
|
584
|
+
cached = node_cache[:string][index]
|
585
|
+
@index = cached.interval.end if cached
|
586
|
+
return cached
|
587
|
+
end
|
588
|
+
|
589
|
+
i0, s0 = index, []
|
590
|
+
if has_terminal?("\"", false, index)
|
591
|
+
r1 = instantiate_node(SyntaxNode,input, index...(index + 1))
|
592
|
+
@index += 1
|
593
|
+
else
|
594
|
+
terminal_parse_failure("\"")
|
595
|
+
r1 = nil
|
596
|
+
end
|
597
|
+
s0 << r1
|
598
|
+
if r1
|
599
|
+
s2, i2 = [], index
|
600
|
+
loop do
|
601
|
+
r3 = _nt_string_innards
|
602
|
+
if r3
|
603
|
+
s2 << r3
|
604
|
+
else
|
605
|
+
break
|
606
|
+
end
|
607
|
+
end
|
608
|
+
r2 = instantiate_node(SyntaxNode,input, i2...index, s2)
|
609
|
+
s0 << r2
|
610
|
+
if r2
|
611
|
+
if has_terminal?("\"", false, index)
|
612
|
+
r4 = instantiate_node(SyntaxNode,input, index...(index + 1))
|
613
|
+
@index += 1
|
614
|
+
else
|
615
|
+
terminal_parse_failure("\"")
|
616
|
+
r4 = nil
|
617
|
+
end
|
618
|
+
s0 << r4
|
619
|
+
end
|
620
|
+
end
|
621
|
+
if s0.last
|
622
|
+
r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
|
623
|
+
r0.extend(String0)
|
624
|
+
r0.extend(String1)
|
625
|
+
else
|
626
|
+
@index = i0
|
627
|
+
r0 = nil
|
628
|
+
end
|
629
|
+
|
630
|
+
node_cache[:string][start_index] = r0
|
631
|
+
|
632
|
+
r0
|
633
|
+
end
|
634
|
+
|
635
|
+
module StringInnards0
|
636
|
+
def unquoted
|
637
|
+
text_value
|
638
|
+
end
|
639
|
+
end
|
640
|
+
|
641
|
+
module StringInnards1
|
642
|
+
def quoted_entity
|
643
|
+
elements[1]
|
644
|
+
end
|
645
|
+
end
|
646
|
+
|
647
|
+
module StringInnards2
|
648
|
+
def unquoted
|
649
|
+
quoted_entity.unquoted
|
650
|
+
end
|
651
|
+
end
|
652
|
+
|
653
|
+
def _nt_string_innards
|
654
|
+
start_index = index
|
655
|
+
if node_cache[:string_innards].has_key?(index)
|
656
|
+
cached = node_cache[:string_innards][index]
|
657
|
+
@index = cached.interval.end if cached
|
658
|
+
return cached
|
659
|
+
end
|
660
|
+
|
661
|
+
i0 = index
|
662
|
+
s1, i1 = [], index
|
663
|
+
loop do
|
664
|
+
if has_terminal?('\G[^\\\\\\"]', true, index)
|
665
|
+
r2 = true
|
666
|
+
@index += 1
|
667
|
+
else
|
668
|
+
r2 = nil
|
669
|
+
end
|
670
|
+
if r2
|
671
|
+
s1 << r2
|
672
|
+
else
|
673
|
+
break
|
674
|
+
end
|
675
|
+
end
|
676
|
+
if s1.empty?
|
677
|
+
@index = i1
|
678
|
+
r1 = nil
|
679
|
+
else
|
680
|
+
r1 = instantiate_node(SyntaxNode,input, i1...index, s1)
|
681
|
+
r1.extend(StringInnards0)
|
682
|
+
end
|
683
|
+
if r1
|
684
|
+
r0 = r1
|
685
|
+
else
|
686
|
+
i3, s3 = index, []
|
687
|
+
if has_terminal?("\\", false, index)
|
688
|
+
r4 = instantiate_node(SyntaxNode,input, index...(index + 1))
|
689
|
+
@index += 1
|
690
|
+
else
|
691
|
+
terminal_parse_failure("\\")
|
692
|
+
r4 = nil
|
693
|
+
end
|
694
|
+
s3 << r4
|
695
|
+
if r4
|
696
|
+
r5 = _nt_quoted_entity
|
697
|
+
s3 << r5
|
698
|
+
end
|
699
|
+
if s3.last
|
700
|
+
r3 = instantiate_node(SyntaxNode,input, i3...index, s3)
|
701
|
+
r3.extend(StringInnards1)
|
702
|
+
r3.extend(StringInnards2)
|
703
|
+
else
|
704
|
+
@index = i3
|
705
|
+
r3 = nil
|
706
|
+
end
|
707
|
+
if r3
|
708
|
+
r0 = r3
|
709
|
+
else
|
710
|
+
@index = i0
|
711
|
+
r0 = nil
|
712
|
+
end
|
713
|
+
end
|
714
|
+
|
715
|
+
node_cache[:string_innards][start_index] = r0
|
716
|
+
|
717
|
+
r0
|
718
|
+
end
|
719
|
+
|
720
|
+
module QuotedEntity0
|
721
|
+
def unquoted
|
722
|
+
case text_value
|
723
|
+
when "r" then "\r"
|
724
|
+
when "n" then "\n"
|
725
|
+
when "t" then "\t"
|
726
|
+
when "$" then "\\$"
|
727
|
+
else text_value
|
728
|
+
end
|
729
|
+
end
|
730
|
+
end
|
731
|
+
|
732
|
+
module QuotedEntity1
|
733
|
+
def hex_digit1
|
734
|
+
elements[0]
|
735
|
+
end
|
736
|
+
|
737
|
+
def hex_digit2
|
738
|
+
elements[1]
|
739
|
+
end
|
740
|
+
|
741
|
+
def hex_digit3
|
742
|
+
elements[2]
|
743
|
+
end
|
744
|
+
|
745
|
+
def hex_digit4
|
746
|
+
elements[3]
|
747
|
+
end
|
748
|
+
end
|
749
|
+
|
750
|
+
module QuotedEntity2
|
751
|
+
def digits
|
752
|
+
elements[1]
|
753
|
+
end
|
754
|
+
end
|
755
|
+
|
756
|
+
module QuotedEntity3
|
757
|
+
def unquoted
|
758
|
+
[ digits.text_value.to_i(16) ].pack("U")
|
759
|
+
end
|
760
|
+
end
|
761
|
+
|
762
|
+
module QuotedEntity4
|
763
|
+
def hex_digit1
|
764
|
+
elements[0]
|
765
|
+
end
|
766
|
+
|
767
|
+
def hex_digit2
|
768
|
+
elements[1]
|
769
|
+
end
|
770
|
+
end
|
771
|
+
|
772
|
+
module QuotedEntity5
|
773
|
+
def digits
|
774
|
+
elements[1]
|
775
|
+
end
|
776
|
+
end
|
777
|
+
|
778
|
+
module QuotedEntity6
|
779
|
+
def unquoted
|
780
|
+
digits.text_value.to_i(16).chr
|
781
|
+
end
|
782
|
+
end
|
783
|
+
|
784
|
+
def _nt_quoted_entity
|
785
|
+
start_index = index
|
786
|
+
if node_cache[:quoted_entity].has_key?(index)
|
787
|
+
cached = node_cache[:quoted_entity][index]
|
788
|
+
@index = cached.interval.end if cached
|
789
|
+
return cached
|
790
|
+
end
|
791
|
+
|
792
|
+
i0 = index
|
793
|
+
if has_terminal?('\G[^ux]', true, index)
|
794
|
+
r1 = instantiate_node(SyntaxNode,input, index...(index + 1))
|
795
|
+
r1.extend(QuotedEntity0)
|
796
|
+
@index += 1
|
797
|
+
else
|
798
|
+
r1 = nil
|
799
|
+
end
|
800
|
+
if r1
|
801
|
+
r0 = r1
|
802
|
+
else
|
803
|
+
i2, s2 = index, []
|
804
|
+
if has_terminal?("u", false, index)
|
805
|
+
r3 = instantiate_node(SyntaxNode,input, index...(index + 1))
|
806
|
+
@index += 1
|
807
|
+
else
|
808
|
+
terminal_parse_failure("u")
|
809
|
+
r3 = nil
|
810
|
+
end
|
811
|
+
s2 << r3
|
812
|
+
if r3
|
813
|
+
i4, s4 = index, []
|
814
|
+
r5 = _nt_hex_digit
|
815
|
+
s4 << r5
|
816
|
+
if r5
|
817
|
+
r6 = _nt_hex_digit
|
818
|
+
s4 << r6
|
819
|
+
if r6
|
820
|
+
r7 = _nt_hex_digit
|
821
|
+
s4 << r7
|
822
|
+
if r7
|
823
|
+
r8 = _nt_hex_digit
|
824
|
+
s4 << r8
|
825
|
+
end
|
826
|
+
end
|
827
|
+
end
|
828
|
+
if s4.last
|
829
|
+
r4 = instantiate_node(SyntaxNode,input, i4...index, s4)
|
830
|
+
r4.extend(QuotedEntity1)
|
831
|
+
else
|
832
|
+
@index = i4
|
833
|
+
r4 = nil
|
834
|
+
end
|
835
|
+
s2 << r4
|
836
|
+
end
|
837
|
+
if s2.last
|
838
|
+
r2 = instantiate_node(SyntaxNode,input, i2...index, s2)
|
839
|
+
r2.extend(QuotedEntity2)
|
840
|
+
r2.extend(QuotedEntity3)
|
841
|
+
else
|
842
|
+
@index = i2
|
843
|
+
r2 = nil
|
844
|
+
end
|
845
|
+
if r2
|
846
|
+
r0 = r2
|
847
|
+
else
|
848
|
+
i9, s9 = index, []
|
849
|
+
if has_terminal?("x", false, index)
|
850
|
+
r10 = instantiate_node(SyntaxNode,input, index...(index + 1))
|
851
|
+
@index += 1
|
852
|
+
else
|
853
|
+
terminal_parse_failure("x")
|
854
|
+
r10 = nil
|
855
|
+
end
|
856
|
+
s9 << r10
|
857
|
+
if r10
|
858
|
+
i11, s11 = index, []
|
859
|
+
r12 = _nt_hex_digit
|
860
|
+
s11 << r12
|
861
|
+
if r12
|
862
|
+
r13 = _nt_hex_digit
|
863
|
+
s11 << r13
|
864
|
+
end
|
865
|
+
if s11.last
|
866
|
+
r11 = instantiate_node(SyntaxNode,input, i11...index, s11)
|
867
|
+
r11.extend(QuotedEntity4)
|
868
|
+
else
|
869
|
+
@index = i11
|
870
|
+
r11 = nil
|
871
|
+
end
|
872
|
+
s9 << r11
|
873
|
+
end
|
874
|
+
if s9.last
|
875
|
+
r9 = instantiate_node(SyntaxNode,input, i9...index, s9)
|
876
|
+
r9.extend(QuotedEntity5)
|
877
|
+
r9.extend(QuotedEntity6)
|
878
|
+
else
|
879
|
+
@index = i9
|
880
|
+
r9 = nil
|
881
|
+
end
|
882
|
+
if r9
|
883
|
+
r0 = r9
|
884
|
+
else
|
885
|
+
@index = i0
|
886
|
+
r0 = nil
|
887
|
+
end
|
888
|
+
end
|
889
|
+
end
|
890
|
+
|
891
|
+
node_cache[:quoted_entity][start_index] = r0
|
892
|
+
|
893
|
+
r0
|
894
|
+
end
|
895
|
+
|
896
|
+
def _nt_hex_digit
|
897
|
+
start_index = index
|
898
|
+
if node_cache[:hex_digit].has_key?(index)
|
899
|
+
cached = node_cache[:hex_digit][index]
|
900
|
+
@index = cached.interval.end if cached
|
901
|
+
return cached
|
902
|
+
end
|
903
|
+
|
904
|
+
if has_terminal?('\G[0-9a-fA-F]', true, index)
|
905
|
+
r0 = instantiate_node(SyntaxNode,input, index...(index + 1))
|
906
|
+
@index += 1
|
907
|
+
else
|
908
|
+
r0 = nil
|
909
|
+
end
|
910
|
+
|
911
|
+
node_cache[:hex_digit][start_index] = r0
|
912
|
+
|
913
|
+
r0
|
914
|
+
end
|
915
|
+
|
916
|
+
module TrueFalse0
|
917
|
+
def to_value(config_map=nil)
|
918
|
+
true
|
919
|
+
end
|
920
|
+
end
|
921
|
+
|
922
|
+
module TrueFalse1
|
923
|
+
def to_value(config_map=nil)
|
924
|
+
true
|
925
|
+
end
|
926
|
+
end
|
927
|
+
|
928
|
+
module TrueFalse2
|
929
|
+
def to_value(config_map=nil)
|
930
|
+
false
|
931
|
+
end
|
932
|
+
end
|
933
|
+
|
934
|
+
module TrueFalse3
|
935
|
+
def to_value(config_map=nil)
|
936
|
+
false
|
937
|
+
end
|
938
|
+
end
|
939
|
+
|
940
|
+
def _nt_true_false
|
941
|
+
start_index = index
|
942
|
+
if node_cache[:true_false].has_key?(index)
|
943
|
+
cached = node_cache[:true_false][index]
|
944
|
+
@index = cached.interval.end if cached
|
945
|
+
return cached
|
946
|
+
end
|
947
|
+
|
948
|
+
i0 = index
|
949
|
+
if has_terminal?("true", false, index)
|
950
|
+
r1 = instantiate_node(SyntaxNode,input, index...(index + 4))
|
951
|
+
r1.extend(TrueFalse0)
|
952
|
+
@index += 4
|
953
|
+
else
|
954
|
+
terminal_parse_failure("true")
|
955
|
+
r1 = nil
|
956
|
+
end
|
957
|
+
if r1
|
958
|
+
r0 = r1
|
959
|
+
else
|
960
|
+
if has_terminal?("on", false, index)
|
961
|
+
r2 = instantiate_node(SyntaxNode,input, index...(index + 2))
|
962
|
+
r2.extend(TrueFalse1)
|
963
|
+
@index += 2
|
964
|
+
else
|
965
|
+
terminal_parse_failure("on")
|
966
|
+
r2 = nil
|
967
|
+
end
|
968
|
+
if r2
|
969
|
+
r0 = r2
|
970
|
+
else
|
971
|
+
if has_terminal?("false", false, index)
|
972
|
+
r3 = instantiate_node(SyntaxNode,input, index...(index + 5))
|
973
|
+
r3.extend(TrueFalse2)
|
974
|
+
@index += 5
|
975
|
+
else
|
976
|
+
terminal_parse_failure("false")
|
977
|
+
r3 = nil
|
978
|
+
end
|
979
|
+
if r3
|
980
|
+
r0 = r3
|
981
|
+
else
|
982
|
+
if has_terminal?("off", false, index)
|
983
|
+
r4 = instantiate_node(SyntaxNode,input, index...(index + 3))
|
984
|
+
r4.extend(TrueFalse3)
|
985
|
+
@index += 3
|
986
|
+
else
|
987
|
+
terminal_parse_failure("off")
|
988
|
+
r4 = nil
|
989
|
+
end
|
990
|
+
if r4
|
991
|
+
r0 = r4
|
992
|
+
else
|
993
|
+
@index = i0
|
994
|
+
r0 = nil
|
995
|
+
end
|
996
|
+
end
|
997
|
+
end
|
998
|
+
end
|
999
|
+
|
1000
|
+
node_cache[:true_false][start_index] = r0
|
1001
|
+
|
1002
|
+
r0
|
1003
|
+
end
|
1004
|
+
|
1005
|
+
module StringList0
|
1006
|
+
end
|
1007
|
+
|
1008
|
+
module StringList1
|
1009
|
+
def item
|
1010
|
+
elements[0]
|
1011
|
+
end
|
1012
|
+
|
1013
|
+
end
|
1014
|
+
|
1015
|
+
module StringList2
|
1016
|
+
def list
|
1017
|
+
elements[2]
|
1018
|
+
end
|
1019
|
+
|
1020
|
+
end
|
1021
|
+
|
1022
|
+
module StringList3
|
1023
|
+
def to_value(config_map=nil)
|
1024
|
+
list.elements.map { |e| e.item.to_value(config_map) }
|
1025
|
+
end
|
1026
|
+
end
|
1027
|
+
|
1028
|
+
def _nt_string_list
|
1029
|
+
start_index = index
|
1030
|
+
if node_cache[:string_list].has_key?(index)
|
1031
|
+
cached = node_cache[:string_list][index]
|
1032
|
+
@index = cached.interval.end if cached
|
1033
|
+
return cached
|
1034
|
+
end
|
1035
|
+
|
1036
|
+
i0, s0 = index, []
|
1037
|
+
if has_terminal?("[", false, index)
|
1038
|
+
r1 = instantiate_node(SyntaxNode,input, index...(index + 1))
|
1039
|
+
@index += 1
|
1040
|
+
else
|
1041
|
+
terminal_parse_failure("[")
|
1042
|
+
r1 = nil
|
1043
|
+
end
|
1044
|
+
s0 << r1
|
1045
|
+
if r1
|
1046
|
+
s2, i2 = [], index
|
1047
|
+
loop do
|
1048
|
+
r3 = _nt_whitespace
|
1049
|
+
if r3
|
1050
|
+
s2 << r3
|
1051
|
+
else
|
1052
|
+
break
|
1053
|
+
end
|
1054
|
+
end
|
1055
|
+
r2 = instantiate_node(SyntaxNode,input, i2...index, s2)
|
1056
|
+
s0 << r2
|
1057
|
+
if r2
|
1058
|
+
s4, i4 = [], index
|
1059
|
+
loop do
|
1060
|
+
i5, s5 = index, []
|
1061
|
+
i6 = index
|
1062
|
+
r7 = _nt_string
|
1063
|
+
if r7
|
1064
|
+
r6 = r7
|
1065
|
+
else
|
1066
|
+
r8 = _nt_number
|
1067
|
+
if r8
|
1068
|
+
r6 = r8
|
1069
|
+
else
|
1070
|
+
@index = i6
|
1071
|
+
r6 = nil
|
1072
|
+
end
|
1073
|
+
end
|
1074
|
+
s5 << r6
|
1075
|
+
if r6
|
1076
|
+
i10, s10 = index, []
|
1077
|
+
s11, i11 = [], index
|
1078
|
+
loop do
|
1079
|
+
r12 = _nt_whitespace
|
1080
|
+
if r12
|
1081
|
+
s11 << r12
|
1082
|
+
else
|
1083
|
+
break
|
1084
|
+
end
|
1085
|
+
end
|
1086
|
+
r11 = instantiate_node(SyntaxNode,input, i11...index, s11)
|
1087
|
+
s10 << r11
|
1088
|
+
if r11
|
1089
|
+
if has_terminal?(",", false, index)
|
1090
|
+
r13 = instantiate_node(SyntaxNode,input, index...(index + 1))
|
1091
|
+
@index += 1
|
1092
|
+
else
|
1093
|
+
terminal_parse_failure(",")
|
1094
|
+
r13 = nil
|
1095
|
+
end
|
1096
|
+
s10 << r13
|
1097
|
+
end
|
1098
|
+
if s10.last
|
1099
|
+
r10 = instantiate_node(SyntaxNode,input, i10...index, s10)
|
1100
|
+
r10.extend(StringList0)
|
1101
|
+
else
|
1102
|
+
@index = i10
|
1103
|
+
r10 = nil
|
1104
|
+
end
|
1105
|
+
if r10
|
1106
|
+
r9 = r10
|
1107
|
+
else
|
1108
|
+
r9 = instantiate_node(SyntaxNode,input, index...index)
|
1109
|
+
end
|
1110
|
+
s5 << r9
|
1111
|
+
if r9
|
1112
|
+
s14, i14 = [], index
|
1113
|
+
loop do
|
1114
|
+
r15 = _nt_whitespace
|
1115
|
+
if r15
|
1116
|
+
s14 << r15
|
1117
|
+
else
|
1118
|
+
break
|
1119
|
+
end
|
1120
|
+
end
|
1121
|
+
r14 = instantiate_node(SyntaxNode,input, i14...index, s14)
|
1122
|
+
s5 << r14
|
1123
|
+
end
|
1124
|
+
end
|
1125
|
+
if s5.last
|
1126
|
+
r5 = instantiate_node(SyntaxNode,input, i5...index, s5)
|
1127
|
+
r5.extend(StringList1)
|
1128
|
+
else
|
1129
|
+
@index = i5
|
1130
|
+
r5 = nil
|
1131
|
+
end
|
1132
|
+
if r5
|
1133
|
+
s4 << r5
|
1134
|
+
else
|
1135
|
+
break
|
1136
|
+
end
|
1137
|
+
end
|
1138
|
+
r4 = instantiate_node(SyntaxNode,input, i4...index, s4)
|
1139
|
+
s0 << r4
|
1140
|
+
if r4
|
1141
|
+
if has_terminal?("]", false, index)
|
1142
|
+
r16 = instantiate_node(SyntaxNode,input, index...(index + 1))
|
1143
|
+
@index += 1
|
1144
|
+
else
|
1145
|
+
terminal_parse_failure("]")
|
1146
|
+
r16 = nil
|
1147
|
+
end
|
1148
|
+
s0 << r16
|
1149
|
+
end
|
1150
|
+
end
|
1151
|
+
end
|
1152
|
+
if s0.last
|
1153
|
+
r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
|
1154
|
+
r0.extend(StringList2)
|
1155
|
+
r0.extend(StringList3)
|
1156
|
+
else
|
1157
|
+
@index = i0
|
1158
|
+
r0 = nil
|
1159
|
+
end
|
1160
|
+
|
1161
|
+
node_cache[:string_list][start_index] = r0
|
1162
|
+
|
1163
|
+
r0
|
1164
|
+
end
|
1165
|
+
|
1166
|
+
module Identifier0
|
1167
|
+
def identifier_token
|
1168
|
+
elements[1]
|
1169
|
+
end
|
1170
|
+
end
|
1171
|
+
|
1172
|
+
module Identifier1
|
1173
|
+
def identifier_token
|
1174
|
+
elements[0]
|
1175
|
+
end
|
1176
|
+
|
1177
|
+
end
|
1178
|
+
|
1179
|
+
def _nt_identifier
|
1180
|
+
start_index = index
|
1181
|
+
if node_cache[:identifier].has_key?(index)
|
1182
|
+
cached = node_cache[:identifier][index]
|
1183
|
+
@index = cached.interval.end if cached
|
1184
|
+
return cached
|
1185
|
+
end
|
1186
|
+
|
1187
|
+
i0, s0 = index, []
|
1188
|
+
r1 = _nt_identifier_token
|
1189
|
+
s0 << r1
|
1190
|
+
if r1
|
1191
|
+
s2, i2 = [], index
|
1192
|
+
loop do
|
1193
|
+
i3, s3 = index, []
|
1194
|
+
if has_terminal?("\.", false, index)
|
1195
|
+
r4 = instantiate_node(SyntaxNode,input, index...(index + 1))
|
1196
|
+
@index += 1
|
1197
|
+
else
|
1198
|
+
terminal_parse_failure("\.")
|
1199
|
+
r4 = nil
|
1200
|
+
end
|
1201
|
+
s3 << r4
|
1202
|
+
if r4
|
1203
|
+
r5 = _nt_identifier_token
|
1204
|
+
s3 << r5
|
1205
|
+
end
|
1206
|
+
if s3.last
|
1207
|
+
r3 = instantiate_node(SyntaxNode,input, i3...index, s3)
|
1208
|
+
r3.extend(Identifier0)
|
1209
|
+
else
|
1210
|
+
@index = i3
|
1211
|
+
r3 = nil
|
1212
|
+
end
|
1213
|
+
if r3
|
1214
|
+
s2 << r3
|
1215
|
+
else
|
1216
|
+
break
|
1217
|
+
end
|
1218
|
+
end
|
1219
|
+
r2 = instantiate_node(SyntaxNode,input, i2...index, s2)
|
1220
|
+
s0 << r2
|
1221
|
+
end
|
1222
|
+
if s0.last
|
1223
|
+
r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
|
1224
|
+
r0.extend(Identifier1)
|
1225
|
+
else
|
1226
|
+
@index = i0
|
1227
|
+
r0 = nil
|
1228
|
+
end
|
1229
|
+
|
1230
|
+
node_cache[:identifier][start_index] = r0
|
1231
|
+
|
1232
|
+
r0
|
1233
|
+
end
|
1234
|
+
|
1235
|
+
module IdentifierToken0
|
1236
|
+
end
|
1237
|
+
|
1238
|
+
def _nt_identifier_token
|
1239
|
+
start_index = index
|
1240
|
+
if node_cache[:identifier_token].has_key?(index)
|
1241
|
+
cached = node_cache[:identifier_token][index]
|
1242
|
+
@index = cached.interval.end if cached
|
1243
|
+
return cached
|
1244
|
+
end
|
1245
|
+
|
1246
|
+
i0, s0 = index, []
|
1247
|
+
if has_terminal?('\G[\\da-zA-Z]', true, index)
|
1248
|
+
r1 = true
|
1249
|
+
@index += 1
|
1250
|
+
else
|
1251
|
+
r1 = nil
|
1252
|
+
end
|
1253
|
+
s0 << r1
|
1254
|
+
if r1
|
1255
|
+
s2, i2 = [], index
|
1256
|
+
loop do
|
1257
|
+
if has_terminal?('\G[-\\da-zA-Z_]', true, index)
|
1258
|
+
r3 = true
|
1259
|
+
@index += 1
|
1260
|
+
else
|
1261
|
+
r3 = nil
|
1262
|
+
end
|
1263
|
+
if r3
|
1264
|
+
s2 << r3
|
1265
|
+
else
|
1266
|
+
break
|
1267
|
+
end
|
1268
|
+
end
|
1269
|
+
r2 = instantiate_node(SyntaxNode,input, i2...index, s2)
|
1270
|
+
s0 << r2
|
1271
|
+
end
|
1272
|
+
if s0.last
|
1273
|
+
r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
|
1274
|
+
r0.extend(IdentifierToken0)
|
1275
|
+
else
|
1276
|
+
@index = i0
|
1277
|
+
r0 = nil
|
1278
|
+
end
|
1279
|
+
|
1280
|
+
node_cache[:identifier_token][start_index] = r0
|
1281
|
+
|
1282
|
+
r0
|
1283
|
+
end
|
1284
|
+
|
1285
|
+
module Section0
|
1286
|
+
def tag_attribute
|
1287
|
+
elements[0]
|
1288
|
+
end
|
1289
|
+
|
1290
|
+
end
|
1291
|
+
|
1292
|
+
module Section1
|
1293
|
+
def attributes
|
1294
|
+
elements[2]
|
1295
|
+
end
|
1296
|
+
|
1297
|
+
end
|
1298
|
+
|
1299
|
+
module Section2
|
1300
|
+
def identifier_token
|
1301
|
+
elements[0]
|
1302
|
+
end
|
1303
|
+
|
1304
|
+
def attribute_list
|
1305
|
+
elements[2]
|
1306
|
+
end
|
1307
|
+
|
1308
|
+
def root
|
1309
|
+
elements[5]
|
1310
|
+
end
|
1311
|
+
|
1312
|
+
end
|
1313
|
+
|
1314
|
+
module Section3
|
1315
|
+
def apply(config_map, parser)
|
1316
|
+
new_name = identifier_token.text_value
|
1317
|
+
nested_config_map = Configgy::ConfigMap.new(config_map.root, config_map.name == "" ? new_name : config_map.name + "." + new_name)
|
1318
|
+
if attribute_list.elements
|
1319
|
+
attribute_list.attributes.elements.map { |e| e.tag_attribute }.each do |attr|
|
1320
|
+
case attr.name.text_value
|
1321
|
+
when "inherit"
|
1322
|
+
v = attr.value.to_value
|
1323
|
+
if config_map[v].instance_of?(Configgy::ConfigMap)
|
1324
|
+
nested_config_map.inherit_from = config_map[v]
|
1325
|
+
elsif config_map.root
|
1326
|
+
config_map.root[v] = Configgy::ConfigMap.new(config_map.root, v) unless config_map.root.has_key?(v)
|
1327
|
+
if config_map.root[v].instance_of?(Configgy::ConfigMap)
|
1328
|
+
nested_config_map.inherit_from = config_map.root[v]
|
1329
|
+
else
|
1330
|
+
raise ConfigException("can only inherit from blocks")
|
1331
|
+
end
|
1332
|
+
end
|
1333
|
+
end
|
1334
|
+
end
|
1335
|
+
end
|
1336
|
+
config_map[new_name] = nested_config_map
|
1337
|
+
root.apply(nested_config_map, parser)
|
1338
|
+
end
|
1339
|
+
end
|
1340
|
+
|
1341
|
+
def _nt_section
|
1342
|
+
start_index = index
|
1343
|
+
if node_cache[:section].has_key?(index)
|
1344
|
+
cached = node_cache[:section][index]
|
1345
|
+
@index = cached.interval.end if cached
|
1346
|
+
return cached
|
1347
|
+
end
|
1348
|
+
|
1349
|
+
i0, s0 = index, []
|
1350
|
+
r1 = _nt_identifier_token
|
1351
|
+
s0 << r1
|
1352
|
+
if r1
|
1353
|
+
s2, i2 = [], index
|
1354
|
+
loop do
|
1355
|
+
r3 = _nt_whitespace
|
1356
|
+
if r3
|
1357
|
+
s2 << r3
|
1358
|
+
else
|
1359
|
+
break
|
1360
|
+
end
|
1361
|
+
end
|
1362
|
+
r2 = instantiate_node(SyntaxNode,input, i2...index, s2)
|
1363
|
+
s0 << r2
|
1364
|
+
if r2
|
1365
|
+
i5, s5 = index, []
|
1366
|
+
if has_terminal?("(", false, index)
|
1367
|
+
r6 = instantiate_node(SyntaxNode,input, index...(index + 1))
|
1368
|
+
@index += 1
|
1369
|
+
else
|
1370
|
+
terminal_parse_failure("(")
|
1371
|
+
r6 = nil
|
1372
|
+
end
|
1373
|
+
s5 << r6
|
1374
|
+
if r6
|
1375
|
+
s7, i7 = [], index
|
1376
|
+
loop do
|
1377
|
+
r8 = _nt_whitespace
|
1378
|
+
if r8
|
1379
|
+
s7 << r8
|
1380
|
+
else
|
1381
|
+
break
|
1382
|
+
end
|
1383
|
+
end
|
1384
|
+
r7 = instantiate_node(SyntaxNode,input, i7...index, s7)
|
1385
|
+
s5 << r7
|
1386
|
+
if r7
|
1387
|
+
s9, i9 = [], index
|
1388
|
+
loop do
|
1389
|
+
i10, s10 = index, []
|
1390
|
+
r11 = _nt_tag_attribute
|
1391
|
+
s10 << r11
|
1392
|
+
if r11
|
1393
|
+
s12, i12 = [], index
|
1394
|
+
loop do
|
1395
|
+
r13 = _nt_whitespace
|
1396
|
+
if r13
|
1397
|
+
s12 << r13
|
1398
|
+
else
|
1399
|
+
break
|
1400
|
+
end
|
1401
|
+
end
|
1402
|
+
r12 = instantiate_node(SyntaxNode,input, i12...index, s12)
|
1403
|
+
s10 << r12
|
1404
|
+
end
|
1405
|
+
if s10.last
|
1406
|
+
r10 = instantiate_node(SyntaxNode,input, i10...index, s10)
|
1407
|
+
r10.extend(Section0)
|
1408
|
+
else
|
1409
|
+
@index = i10
|
1410
|
+
r10 = nil
|
1411
|
+
end
|
1412
|
+
if r10
|
1413
|
+
s9 << r10
|
1414
|
+
else
|
1415
|
+
break
|
1416
|
+
end
|
1417
|
+
end
|
1418
|
+
r9 = instantiate_node(SyntaxNode,input, i9...index, s9)
|
1419
|
+
s5 << r9
|
1420
|
+
if r9
|
1421
|
+
if has_terminal?(")", false, index)
|
1422
|
+
r14 = instantiate_node(SyntaxNode,input, index...(index + 1))
|
1423
|
+
@index += 1
|
1424
|
+
else
|
1425
|
+
terminal_parse_failure(")")
|
1426
|
+
r14 = nil
|
1427
|
+
end
|
1428
|
+
s5 << r14
|
1429
|
+
end
|
1430
|
+
end
|
1431
|
+
end
|
1432
|
+
if s5.last
|
1433
|
+
r5 = instantiate_node(SyntaxNode,input, i5...index, s5)
|
1434
|
+
r5.extend(Section1)
|
1435
|
+
else
|
1436
|
+
@index = i5
|
1437
|
+
r5 = nil
|
1438
|
+
end
|
1439
|
+
if r5
|
1440
|
+
r4 = r5
|
1441
|
+
else
|
1442
|
+
r4 = instantiate_node(SyntaxNode,input, index...index)
|
1443
|
+
end
|
1444
|
+
s0 << r4
|
1445
|
+
if r4
|
1446
|
+
s15, i15 = [], index
|
1447
|
+
loop do
|
1448
|
+
r16 = _nt_whitespace
|
1449
|
+
if r16
|
1450
|
+
s15 << r16
|
1451
|
+
else
|
1452
|
+
break
|
1453
|
+
end
|
1454
|
+
end
|
1455
|
+
r15 = instantiate_node(SyntaxNode,input, i15...index, s15)
|
1456
|
+
s0 << r15
|
1457
|
+
if r15
|
1458
|
+
if has_terminal?("{", false, index)
|
1459
|
+
r17 = instantiate_node(SyntaxNode,input, index...(index + 1))
|
1460
|
+
@index += 1
|
1461
|
+
else
|
1462
|
+
terminal_parse_failure("{")
|
1463
|
+
r17 = nil
|
1464
|
+
end
|
1465
|
+
s0 << r17
|
1466
|
+
if r17
|
1467
|
+
r18 = _nt_root
|
1468
|
+
s0 << r18
|
1469
|
+
if r18
|
1470
|
+
if has_terminal?("}", false, index)
|
1471
|
+
r19 = instantiate_node(SyntaxNode,input, index...(index + 1))
|
1472
|
+
@index += 1
|
1473
|
+
else
|
1474
|
+
terminal_parse_failure("}")
|
1475
|
+
r19 = nil
|
1476
|
+
end
|
1477
|
+
s0 << r19
|
1478
|
+
end
|
1479
|
+
end
|
1480
|
+
end
|
1481
|
+
end
|
1482
|
+
end
|
1483
|
+
end
|
1484
|
+
if s0.last
|
1485
|
+
r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
|
1486
|
+
r0.extend(Section2)
|
1487
|
+
r0.extend(Section3)
|
1488
|
+
else
|
1489
|
+
@index = i0
|
1490
|
+
r0 = nil
|
1491
|
+
end
|
1492
|
+
|
1493
|
+
node_cache[:section][start_index] = r0
|
1494
|
+
|
1495
|
+
r0
|
1496
|
+
end
|
1497
|
+
|
1498
|
+
module TagAttribute0
|
1499
|
+
def name
|
1500
|
+
elements[0]
|
1501
|
+
end
|
1502
|
+
|
1503
|
+
def value
|
1504
|
+
elements[2]
|
1505
|
+
end
|
1506
|
+
end
|
1507
|
+
|
1508
|
+
def _nt_tag_attribute
|
1509
|
+
start_index = index
|
1510
|
+
if node_cache[:tag_attribute].has_key?(index)
|
1511
|
+
cached = node_cache[:tag_attribute][index]
|
1512
|
+
@index = cached.interval.end if cached
|
1513
|
+
return cached
|
1514
|
+
end
|
1515
|
+
|
1516
|
+
i0, s0 = index, []
|
1517
|
+
if has_terminal?("inherit", false, index)
|
1518
|
+
r1 = instantiate_node(SyntaxNode,input, index...(index + 7))
|
1519
|
+
@index += 7
|
1520
|
+
else
|
1521
|
+
terminal_parse_failure("inherit")
|
1522
|
+
r1 = nil
|
1523
|
+
end
|
1524
|
+
s0 << r1
|
1525
|
+
if r1
|
1526
|
+
if has_terminal?("=", false, index)
|
1527
|
+
r2 = instantiate_node(SyntaxNode,input, index...(index + 1))
|
1528
|
+
@index += 1
|
1529
|
+
else
|
1530
|
+
terminal_parse_failure("=")
|
1531
|
+
r2 = nil
|
1532
|
+
end
|
1533
|
+
s0 << r2
|
1534
|
+
if r2
|
1535
|
+
r3 = _nt_string
|
1536
|
+
s0 << r3
|
1537
|
+
end
|
1538
|
+
end
|
1539
|
+
if s0.last
|
1540
|
+
r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
|
1541
|
+
r0.extend(TagAttribute0)
|
1542
|
+
else
|
1543
|
+
@index = i0
|
1544
|
+
r0 = nil
|
1545
|
+
end
|
1546
|
+
|
1547
|
+
node_cache[:tag_attribute][start_index] = r0
|
1548
|
+
|
1549
|
+
r0
|
1550
|
+
end
|
1551
|
+
|
1552
|
+
module IncludeFile0
|
1553
|
+
def string
|
1554
|
+
elements[2]
|
1555
|
+
end
|
1556
|
+
end
|
1557
|
+
|
1558
|
+
module IncludeFile1
|
1559
|
+
def apply(config_map, parser)
|
1560
|
+
parser.load_file(string.to_value, config_map)
|
1561
|
+
end
|
1562
|
+
end
|
1563
|
+
|
1564
|
+
def _nt_include_file
|
1565
|
+
start_index = index
|
1566
|
+
if node_cache[:include_file].has_key?(index)
|
1567
|
+
cached = node_cache[:include_file][index]
|
1568
|
+
@index = cached.interval.end if cached
|
1569
|
+
return cached
|
1570
|
+
end
|
1571
|
+
|
1572
|
+
i0, s0 = index, []
|
1573
|
+
if has_terminal?("include", false, index)
|
1574
|
+
r1 = instantiate_node(SyntaxNode,input, index...(index + 7))
|
1575
|
+
@index += 7
|
1576
|
+
else
|
1577
|
+
terminal_parse_failure("include")
|
1578
|
+
r1 = nil
|
1579
|
+
end
|
1580
|
+
s0 << r1
|
1581
|
+
if r1
|
1582
|
+
s2, i2 = [], index
|
1583
|
+
loop do
|
1584
|
+
r3 = _nt_whitespace
|
1585
|
+
if r3
|
1586
|
+
s2 << r3
|
1587
|
+
else
|
1588
|
+
break
|
1589
|
+
end
|
1590
|
+
end
|
1591
|
+
r2 = instantiate_node(SyntaxNode,input, i2...index, s2)
|
1592
|
+
s0 << r2
|
1593
|
+
if r2
|
1594
|
+
r4 = _nt_string
|
1595
|
+
s0 << r4
|
1596
|
+
end
|
1597
|
+
end
|
1598
|
+
if s0.last
|
1599
|
+
r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
|
1600
|
+
r0.extend(IncludeFile0)
|
1601
|
+
r0.extend(IncludeFile1)
|
1602
|
+
else
|
1603
|
+
@index = i0
|
1604
|
+
r0 = nil
|
1605
|
+
end
|
1606
|
+
|
1607
|
+
node_cache[:include_file][start_index] = r0
|
1608
|
+
|
1609
|
+
r0
|
1610
|
+
end
|
1611
|
+
|
1612
|
+
end
|
1613
|
+
|
1614
|
+
class Treetop_ConfiggyParser < Treetop::Runtime::CompiledParser
|
1615
|
+
include Treetop_Configgy
|
1616
|
+
end
|
1617
|
+
|