lunar_cheese 0.2.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 4932384681af36606d0bb204cf859d9a1b6286ce
4
+ data.tar.gz: f4ce54c92446ee47a805f58669f14be0f09313f0
5
+ SHA512:
6
+ metadata.gz: a103d93908ed0087bfd55be0dc9091c6a7b6ce56d41e733e1999b16e1bf749df57e203206c5f9e019cd5309289a778244220a5a226021be2367e9fda09035198
7
+ data.tar.gz: 81073d37bc2764b7a2c1d5fe66aebc4e1cd69b8f4263efda8962eb5785c3b74e7c19e34414ffad80cde805cffefbbf26a6124cd6df7fdfa20a0b97c0288402f6
data/.yardopts ADDED
@@ -0,0 +1,3 @@
1
+ --title "Lunar Cheese"
2
+ --exclude grammar.rb
3
+ --exclude ast.rb
data/LICENSE ADDED
@@ -0,0 +1,14 @@
1
+ Copyright 2013 Michael Senn
2
+
3
+ Licensed under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License.
5
+ You may obtain a copy of the License at
6
+
7
+ http://www.apache.org/licenses/LICENSE-2.0
8
+
9
+ Unless required by applicable law or agreed to in writing, software
10
+ distributed under the License is distributed on an "AS IS" BASIS,
11
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ See the License for the specific language governing permissions and
13
+ limitations under the License.
14
+
data/README.md ADDED
@@ -0,0 +1,44 @@
1
+ # Lunar Cheese
2
+ ## Introduction
3
+ This gem allows you to convert between Ruby objects, and Lua table dumps as they are used by the game [Don't Starve](http://www.dontstarvegame.com/).
4
+
5
+ It consists of:
6
+
7
+ * A Treetop-based PEG grammar, to parse the Lua table dump into a Ruby object.
8
+ * Additions to Ruby core classes, to dump those objects back into the same format.
9
+
10
+ If you find any issues, create a ticket on the [issue tracker](https://bitbucket.org/Lavode/lunar-cheese/issues?status=new&status=open).
11
+
12
+ ## Usage
13
+ Example usage, Ruby 1.9 & 2.0
14
+
15
+ #!/usr/bin/env ruby
16
+ # coding: utf-8
17
+
18
+ require 'zlib'
19
+ require 'base64'
20
+ require 'lunar_cheese'
21
+
22
+ raw = IO::read('survival_1')
23
+ # Base64-decoding, discarding the first eleven bytes
24
+ decoded = Base64::decode64(raw[11..-1])
25
+ # Inflating, discarding the first 16 bytes
26
+ inflated = Zlib::inflate(decoded[16..-1])
27
+ # Discarding the 'return' string at the beginning
28
+ input = inflated[7..-1]
29
+
30
+ parser = LunarCheese::LuaTableDumpParser.new
31
+ ast = parser.parse(input)
32
+ result = ast.to_rb
33
+ puts result.inspect
34
+
35
+ ## Compatability
36
+ This gem has been tested to work on Ruby 2.0.0-p0, 2.0.0-p247, Ruby 1.9.3-p448 and JRuby 1.7.4.
37
+
38
+ Note that performance on JRuby is worse by quite a bit. Probably related to [Treetop's constant usage of extend()](https://groups.google.com/forum/#!topic/treetop-dev/aujDDSZw368)
39
+
40
+ ## Contributing
41
+
42
+ * Fork
43
+ * Feature branch
44
+ * Pull request / git-format-patch
data/Rakefile ADDED
@@ -0,0 +1,5 @@
1
+ #coding: utf-8
2
+
3
+ task :compile_grammar do
4
+ `rm lib/lunar_cheese/grammar.rb & tt lib/lunar_cheese/grammar.treetop`
5
+ end
@@ -0,0 +1,6 @@
1
+ #coding: utf-8
2
+
3
+ require 'treetop'
4
+
5
+ require_relative 'lunar_cheese/ast'
6
+ require_relative 'lunar_cheese/grammar'
@@ -0,0 +1,105 @@
1
+ #coding: utf-8
2
+
3
+ module LunarCheese
4
+
5
+ module AST
6
+
7
+ class IntegerLiteral < Treetop::Runtime::SyntaxNode
8
+ def to_rb
9
+ text_value.to_i
10
+ end
11
+
12
+ def clean_tree
13
+ elements.delete_if { true }
14
+ end
15
+ end
16
+
17
+ class FloatLiteral < Treetop::Runtime::SyntaxNode
18
+ def to_rb
19
+ text_value.to_f
20
+ end
21
+
22
+ def clean_tree
23
+ elements.delete_if { true }
24
+ end
25
+ end
26
+
27
+ class BooleanLit < Treetop::Runtime::SyntaxNode
28
+ def to_rb
29
+ text_value == 'true'
30
+ end
31
+
32
+ def clean_tree
33
+ elements.delete_if { true }
34
+ end
35
+ end
36
+
37
+ class StringLiteral < Treetop::Runtime::SyntaxNode
38
+ def to_rb
39
+ (@internal_text || text.text_value).gsub(/\\"/, '"')
40
+ end
41
+
42
+ def clean_tree
43
+ # Cleaning the tree will remove the 'text' node, so in order for #to_rb to work we'll have to either
44
+ # a) keep that node, b) use self.text_value and get rid of leading and closing quote or c) store the value somewhere.
45
+ @internal_text = text.text_value
46
+ elements.delete_if { true }
47
+ end
48
+ end
49
+
50
+ class IdentifierLiteral < Treetop::Runtime::SyntaxNode
51
+ def to_rb
52
+ text_value.to_sym
53
+ end
54
+
55
+ def clean_tree
56
+ elements.delete_if { true }
57
+ end
58
+ end
59
+
60
+ class Assignment < Treetop::Runtime::SyntaxNode
61
+ def to_rb
62
+ { identifier.to_rb => value.to_rb }
63
+ end
64
+ end
65
+
66
+ class LuaArray < Treetop::Runtime::SyntaxNode
67
+ def to_rb
68
+ index = 0
69
+ other_values.elements.map(&:value).inject({ index => value.to_rb }) do |hash, value|
70
+ index += 1
71
+ hash.merge({ index => value.to_rb })
72
+ end
73
+ end
74
+ end
75
+
76
+ class LuaHash < Treetop::Runtime::SyntaxNode
77
+ def to_rb
78
+ other_assignments.elements.inject(assignment.to_rb) { |hash, comma_and_assignment| hash.merge(comma_and_assignment.assignment.to_rb) }
79
+ end
80
+ end
81
+
82
+ class LuaTable < Treetop::Runtime::SyntaxNode
83
+ def to_rb
84
+ # Todo: Refactor this. Also, the grammar currently allows {,1,2,3} which wouldn't be correct.
85
+ return {} if text_value == '{}'
86
+
87
+ index = 0
88
+
89
+ ([child] + other_children.elements.map(&:child)).inject({}) do |result, child|
90
+ if child.is_a? Assignment
91
+ result.update(child.to_rb)
92
+ else
93
+ result[index] = child.to_rb
94
+ index += 1
95
+ end
96
+
97
+ result
98
+ end
99
+
100
+ end
101
+ end
102
+
103
+ end
104
+
105
+ end
@@ -0,0 +1,144 @@
1
+ #coding: utf-8
2
+
3
+ class String
4
+
5
+ # Dump the string to a format used by Don't Starve table dumps.
6
+ # This will a) surround the string with quotation marks (") and b) escape any quotation marks which it contains.
7
+ #
8
+ # @example Dumping string
9
+ # puts 'Hello "John", if this truly is your name.'.to_lua
10
+ # => "Hello \"John\", if this truly is your name."
11
+ #
12
+ # @return [String] Dumped version of the string.
13
+ def to_lua
14
+ "\"#{ gsub(/"/, '\"') }\""
15
+ end
16
+
17
+ end
18
+
19
+ class Fixnum
20
+
21
+ # Dump the fixnum to a format used by Don't Starve table dumps.
22
+ # This will simply call #to_s
23
+ #
24
+ # @example Dumping fixnum
25
+ # puts 21.to_lua
26
+ # => '21'
27
+ #
28
+ # @return [String] Dumped version of the fixnum.
29
+ def to_lua
30
+ to_s
31
+ end
32
+
33
+ end
34
+
35
+ class Float
36
+
37
+ # Dump the float to a format used by Don't Starve table dumps.
38
+ # This will simply call #to_s
39
+ #
40
+ # @example Dumping float
41
+ # puts 21.5.to_lua
42
+ # => '21.5'
43
+ #
44
+ # @return [String] Dumped version of the float.
45
+ def to_lua
46
+ to_s
47
+ end
48
+
49
+ end
50
+
51
+ class FalseClass
52
+
53
+ # Dump 'false' to a format used by Don't Starve table dumps.
54
+ #
55
+ # @example Dumping 'false'
56
+ # puts false.to_lua
57
+ # => 'false'
58
+ #
59
+ # @return [String] 'false'
60
+ def to_lua
61
+ to_s
62
+ end
63
+
64
+ end
65
+
66
+ class TrueClass
67
+
68
+ # Dump 'true' to a format used by Don't Starve table dumps.
69
+ #
70
+ # @example Dumping 'true'
71
+ # puts true.to_lua
72
+ # => 'true'
73
+ #
74
+ # @return [String] 'true'
75
+ def to_lua
76
+ to_s
77
+ end
78
+
79
+ end
80
+
81
+ class Symbol
82
+
83
+ # Dump the symbol to a format used by Don't Starve table dumps.
84
+ # Depending on the symbol this will return a different string:
85
+ # If it consists of alphanumeric characters & underscores, its string value will be returned.
86
+ # If it consists of an opening bracket, followed by any amount of characters except an opening or closing bracket, followed by a closing bracket, its string value will be returned.
87
+ # Else its string value, surrounded by brackets, will be returned.
88
+ #
89
+ # @example Dumping alphanumeric + underscore symbol.
90
+ # puts :is_alive.to_lua
91
+ # => 'is_alive'
92
+ #
93
+ # @example Dumping symbol starting and ending with bracket.
94
+ # puts :'[3 * 2]'.to_lua
95
+ # => '[3 * 2]'
96
+ #
97
+ # @example Dumping non-alphanumeric symbol, not enclosed in brackets.
98
+ # puts :'number one'
99
+ # => '[number one]'
100
+ #
101
+ # @return [String] Dumped version of the symbol.
102
+ def to_lua
103
+ s = to_s
104
+ if s =~ /^[a-zA-Z0-9_]+$/
105
+ s
106
+ elsif s=~ /^\[[^\[\]]+\]$/ # An opening bracket, followed by >=1 of anything except an opening or closing bracket, followed by a closing bracket.
107
+ s
108
+ else
109
+ "[#{ s }]"
110
+ end
111
+ end
112
+
113
+ end
114
+
115
+ class Hash
116
+
117
+ # Dump the Hash to a format used by Don't Starve table dumps.
118
+ # The result will, roughly, contain of a comma-separated list of assignments, which are the result of calling #to_lua on each key and value, and joining them with an '=' sign.
119
+ # One exemption are Fixnum keys - in those cases, merely the result of calling #to_lua on the value will be part of the result.
120
+ # This is to make use of the implicit indices in a Lua table dump like '!{1,2,"foo","bar",3}'.
121
+ #
122
+ # @example Dumping array-like hash.
123
+ # puts { 0 => 'a', 1 => 'b', 2 => 'c' }.to_lua
124
+ # => {"a","b","c"}
125
+ #
126
+ # @example Dumping nested hash.
127
+ # puts { :name => { :first_name => 'John', :last_name => 'Madden' } }.to_lua
128
+ # => {name={first_name="John",last_name="Madden"}}
129
+ #
130
+ # @return [String] Dumped version of the hash.
131
+ def to_lua
132
+
133
+ results = each_pair.map do |key, value|
134
+ if key.is_a? Fixnum
135
+ value.to_lua
136
+ else
137
+ "#{key.to_lua}=#{value.to_lua}"
138
+ end
139
+ end
140
+
141
+ "{#{ results.join(',') }}"
142
+ end
143
+
144
+ end
@@ -0,0 +1,680 @@
1
+ # Autogenerated from a Treetop grammar. Edits may be lost.
2
+
3
+
4
+ module LunarCheese
5
+ module LuaTableDump
6
+ include Treetop::Runtime
7
+
8
+ def root
9
+ @root ||= :table
10
+ end
11
+
12
+ module Table0
13
+ def child
14
+ elements[1]
15
+ end
16
+ end
17
+
18
+ module Table1
19
+ def child
20
+ elements[1]
21
+ end
22
+
23
+ def other_children
24
+ elements[2]
25
+ end
26
+
27
+ end
28
+
29
+ def _nt_table
30
+ start_index = index
31
+ if node_cache[:table].has_key?(index)
32
+ cached = node_cache[:table][index]
33
+ if cached
34
+ cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
35
+ @index = cached.interval.end
36
+ end
37
+ return cached
38
+ end
39
+
40
+ i0, s0 = index, []
41
+ if has_terminal?('{', false, index)
42
+ r1 = instantiate_node(SyntaxNode,input, index...(index + 1))
43
+ @index += 1
44
+ else
45
+ terminal_parse_failure('{')
46
+ r1 = nil
47
+ end
48
+ s0 << r1
49
+ if r1
50
+ i3 = index
51
+ r4 = _nt_assignment
52
+ if r4
53
+ r3 = r4
54
+ else
55
+ r5 = _nt_value
56
+ if r5
57
+ r3 = r5
58
+ else
59
+ @index = i3
60
+ r3 = nil
61
+ end
62
+ end
63
+ if r3
64
+ r2 = r3
65
+ else
66
+ r2 = instantiate_node(SyntaxNode,input, index...index)
67
+ end
68
+ s0 << r2
69
+ if r2
70
+ s6, i6 = [], index
71
+ loop do
72
+ i7, s7 = index, []
73
+ if has_terminal?(',', false, index)
74
+ r8 = instantiate_node(SyntaxNode,input, index...(index + 1))
75
+ @index += 1
76
+ else
77
+ terminal_parse_failure(',')
78
+ r8 = nil
79
+ end
80
+ s7 << r8
81
+ if r8
82
+ i9 = index
83
+ r10 = _nt_assignment
84
+ if r10
85
+ r9 = r10
86
+ else
87
+ r11 = _nt_value
88
+ if r11
89
+ r9 = r11
90
+ else
91
+ @index = i9
92
+ r9 = nil
93
+ end
94
+ end
95
+ s7 << r9
96
+ end
97
+ if s7.last
98
+ r7 = instantiate_node(SyntaxNode,input, i7...index, s7)
99
+ r7.extend(Table0)
100
+ else
101
+ @index = i7
102
+ r7 = nil
103
+ end
104
+ if r7
105
+ s6 << r7
106
+ else
107
+ break
108
+ end
109
+ end
110
+ r6 = instantiate_node(SyntaxNode,input, i6...index, s6)
111
+ s0 << r6
112
+ if r6
113
+ if has_terminal?('}', false, index)
114
+ r12 = instantiate_node(SyntaxNode,input, index...(index + 1))
115
+ @index += 1
116
+ else
117
+ terminal_parse_failure('}')
118
+ r12 = nil
119
+ end
120
+ s0 << r12
121
+ end
122
+ end
123
+ end
124
+ if s0.last
125
+ r0 = instantiate_node(AST::LuaTable,input, i0...index, s0)
126
+ r0.extend(Table1)
127
+ else
128
+ @index = i0
129
+ r0 = nil
130
+ end
131
+
132
+ node_cache[:table][start_index] = r0
133
+
134
+ r0
135
+ end
136
+
137
+ def _nt_prefix
138
+ start_index = index
139
+ if node_cache[:prefix].has_key?(index)
140
+ cached = node_cache[:prefix][index]
141
+ if cached
142
+ cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
143
+ @index = cached.interval.end
144
+ end
145
+ return cached
146
+ end
147
+
148
+ i0 = index
149
+ if has_terminal?('+', false, index)
150
+ r1 = instantiate_node(SyntaxNode,input, index...(index + 1))
151
+ @index += 1
152
+ else
153
+ terminal_parse_failure('+')
154
+ r1 = nil
155
+ end
156
+ if r1
157
+ r0 = r1
158
+ else
159
+ if has_terminal?('-', false, index)
160
+ r2 = instantiate_node(SyntaxNode,input, index...(index + 1))
161
+ @index += 1
162
+ else
163
+ terminal_parse_failure('-')
164
+ r2 = nil
165
+ end
166
+ if r2
167
+ r0 = r2
168
+ else
169
+ @index = i0
170
+ r0 = nil
171
+ end
172
+ end
173
+
174
+ node_cache[:prefix][start_index] = r0
175
+
176
+ r0
177
+ end
178
+
179
+ module Integer0
180
+ end
181
+
182
+ def _nt_integer
183
+ start_index = index
184
+ if node_cache[:integer].has_key?(index)
185
+ cached = node_cache[:integer][index]
186
+ if cached
187
+ cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
188
+ @index = cached.interval.end
189
+ end
190
+ return cached
191
+ end
192
+
193
+ i0, s0 = index, []
194
+ r2 = _nt_prefix
195
+ if r2
196
+ r1 = r2
197
+ else
198
+ r1 = instantiate_node(SyntaxNode,input, index...index)
199
+ end
200
+ s0 << r1
201
+ if r1
202
+ s3, i3 = [], index
203
+ loop do
204
+ if has_terminal?('\G[0-9]', true, index)
205
+ r4 = true
206
+ @index += 1
207
+ else
208
+ r4 = nil
209
+ end
210
+ if r4
211
+ s3 << r4
212
+ else
213
+ break
214
+ end
215
+ end
216
+ if s3.empty?
217
+ @index = i3
218
+ r3 = nil
219
+ else
220
+ r3 = instantiate_node(SyntaxNode,input, i3...index, s3)
221
+ end
222
+ s0 << r3
223
+ end
224
+ if s0.last
225
+ r0 = instantiate_node(AST::IntegerLiteral,input, i0...index, s0)
226
+ r0.extend(Integer0)
227
+ else
228
+ @index = i0
229
+ r0 = nil
230
+ end
231
+
232
+ node_cache[:integer][start_index] = r0
233
+
234
+ r0
235
+ end
236
+
237
+ module Float0
238
+ def integer
239
+ elements[0]
240
+ end
241
+
242
+ end
243
+
244
+ def _nt_float
245
+ start_index = index
246
+ if node_cache[:float].has_key?(index)
247
+ cached = node_cache[:float][index]
248
+ if cached
249
+ cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
250
+ @index = cached.interval.end
251
+ end
252
+ return cached
253
+ end
254
+
255
+ i0, s0 = index, []
256
+ r1 = _nt_integer
257
+ s0 << r1
258
+ if r1
259
+ if has_terminal?('.', false, index)
260
+ r2 = instantiate_node(SyntaxNode,input, index...(index + 1))
261
+ @index += 1
262
+ else
263
+ terminal_parse_failure('.')
264
+ r2 = nil
265
+ end
266
+ s0 << r2
267
+ if r2
268
+ s3, i3 = [], index
269
+ loop do
270
+ if has_terminal?('\G[0-9]', true, index)
271
+ r4 = true
272
+ @index += 1
273
+ else
274
+ r4 = nil
275
+ end
276
+ if r4
277
+ s3 << r4
278
+ else
279
+ break
280
+ end
281
+ end
282
+ if s3.empty?
283
+ @index = i3
284
+ r3 = nil
285
+ else
286
+ r3 = instantiate_node(SyntaxNode,input, i3...index, s3)
287
+ end
288
+ s0 << r3
289
+ end
290
+ end
291
+ if s0.last
292
+ r0 = instantiate_node(AST::FloatLiteral,input, i0...index, s0)
293
+ r0.extend(Float0)
294
+ else
295
+ @index = i0
296
+ r0 = nil
297
+ end
298
+
299
+ node_cache[:float][start_index] = r0
300
+
301
+ r0
302
+ end
303
+
304
+ def _nt_boolean
305
+ start_index = index
306
+ if node_cache[:boolean].has_key?(index)
307
+ cached = node_cache[:boolean][index]
308
+ if cached
309
+ cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
310
+ @index = cached.interval.end
311
+ end
312
+ return cached
313
+ end
314
+
315
+ i0 = index
316
+ if has_terminal?('false', false, index)
317
+ r1 = instantiate_node(AST::BooleanLit,input, index...(index + 5))
318
+ @index += 5
319
+ else
320
+ terminal_parse_failure('false')
321
+ r1 = nil
322
+ end
323
+ if r1
324
+ r0 = r1
325
+ else
326
+ if has_terminal?('true', false, index)
327
+ r2 = instantiate_node(AST::BooleanLit,input, index...(index + 4))
328
+ @index += 4
329
+ else
330
+ terminal_parse_failure('true')
331
+ r2 = nil
332
+ end
333
+ if r2
334
+ r0 = r2
335
+ else
336
+ @index = i0
337
+ r0 = nil
338
+ end
339
+ end
340
+
341
+ node_cache[:boolean][start_index] = r0
342
+
343
+ r0
344
+ end
345
+
346
+ module String0
347
+ end
348
+
349
+ module String1
350
+ def text
351
+ elements[1]
352
+ end
353
+
354
+ end
355
+
356
+ def _nt_string
357
+ start_index = index
358
+ if node_cache[:string].has_key?(index)
359
+ cached = node_cache[:string][index]
360
+ if cached
361
+ cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
362
+ @index = cached.interval.end
363
+ end
364
+ return cached
365
+ end
366
+
367
+ i0, s0 = index, []
368
+ if has_terminal?('"', false, index)
369
+ r1 = instantiate_node(SyntaxNode,input, index...(index + 1))
370
+ @index += 1
371
+ else
372
+ terminal_parse_failure('"')
373
+ r1 = nil
374
+ end
375
+ s0 << r1
376
+ if r1
377
+ s2, i2 = [], index
378
+ loop do
379
+ i3 = index
380
+ if has_terminal?('\"', false, index)
381
+ r4 = instantiate_node(SyntaxNode,input, index...(index + 2))
382
+ @index += 2
383
+ else
384
+ terminal_parse_failure('\"')
385
+ r4 = nil
386
+ end
387
+ if r4
388
+ r3 = r4
389
+ else
390
+ i5, s5 = index, []
391
+ i6 = index
392
+ if has_terminal?('"', false, index)
393
+ r7 = instantiate_node(SyntaxNode,input, index...(index + 1))
394
+ @index += 1
395
+ else
396
+ terminal_parse_failure('"')
397
+ r7 = nil
398
+ end
399
+ if r7
400
+ r6 = nil
401
+ else
402
+ @index = i6
403
+ r6 = instantiate_node(SyntaxNode,input, index...index)
404
+ end
405
+ s5 << r6
406
+ if r6
407
+ if index < input_length
408
+ r8 = instantiate_node(SyntaxNode,input, index...(index + 1))
409
+ @index += 1
410
+ else
411
+ terminal_parse_failure("any character")
412
+ r8 = nil
413
+ end
414
+ s5 << r8
415
+ end
416
+ if s5.last
417
+ r5 = instantiate_node(SyntaxNode,input, i5...index, s5)
418
+ r5.extend(String0)
419
+ else
420
+ @index = i5
421
+ r5 = nil
422
+ end
423
+ if r5
424
+ r3 = r5
425
+ else
426
+ @index = i3
427
+ r3 = nil
428
+ end
429
+ end
430
+ if r3
431
+ s2 << r3
432
+ else
433
+ break
434
+ end
435
+ end
436
+ r2 = instantiate_node(SyntaxNode,input, i2...index, s2)
437
+ s0 << r2
438
+ if r2
439
+ if has_terminal?('"', false, index)
440
+ r9 = instantiate_node(SyntaxNode,input, index...(index + 1))
441
+ @index += 1
442
+ else
443
+ terminal_parse_failure('"')
444
+ r9 = nil
445
+ end
446
+ s0 << r9
447
+ end
448
+ end
449
+ if s0.last
450
+ r0 = instantiate_node(AST::StringLiteral,input, i0...index, s0)
451
+ r0.extend(String1)
452
+ else
453
+ @index = i0
454
+ r0 = nil
455
+ end
456
+
457
+ node_cache[:string][start_index] = r0
458
+
459
+ r0
460
+ end
461
+
462
+ module Identifier0
463
+ end
464
+
465
+ module Identifier1
466
+ end
467
+
468
+ def _nt_identifier
469
+ start_index = index
470
+ if node_cache[:identifier].has_key?(index)
471
+ cached = node_cache[:identifier][index]
472
+ if cached
473
+ cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
474
+ @index = cached.interval.end
475
+ end
476
+ return cached
477
+ end
478
+
479
+ i0 = index
480
+ i1, s1 = index, []
481
+ if has_terminal?('\G[a-zA-Z_]', true, index)
482
+ r2 = true
483
+ @index += 1
484
+ else
485
+ r2 = nil
486
+ end
487
+ s1 << r2
488
+ if r2
489
+ s3, i3 = [], index
490
+ loop do
491
+ if has_terminal?('\G[a-zA-Z0-9_]', true, index)
492
+ r4 = true
493
+ @index += 1
494
+ else
495
+ r4 = nil
496
+ end
497
+ if r4
498
+ s3 << r4
499
+ else
500
+ break
501
+ end
502
+ end
503
+ r3 = instantiate_node(SyntaxNode,input, i3...index, s3)
504
+ s1 << r3
505
+ end
506
+ if s1.last
507
+ r1 = instantiate_node(AST::IdentifierLiteral,input, i1...index, s1)
508
+ r1.extend(Identifier0)
509
+ else
510
+ @index = i1
511
+ r1 = nil
512
+ end
513
+ if r1
514
+ r0 = r1
515
+ else
516
+ i5, s5 = index, []
517
+ if has_terminal?('[', false, index)
518
+ r6 = instantiate_node(SyntaxNode,input, index...(index + 1))
519
+ @index += 1
520
+ else
521
+ terminal_parse_failure('[')
522
+ r6 = nil
523
+ end
524
+ s5 << r6
525
+ if r6
526
+ s7, i7 = [], index
527
+ loop do
528
+ if has_terminal?('\G[^\\[\\]]', true, index)
529
+ r8 = true
530
+ @index += 1
531
+ else
532
+ r8 = nil
533
+ end
534
+ if r8
535
+ s7 << r8
536
+ else
537
+ break
538
+ end
539
+ end
540
+ if s7.empty?
541
+ @index = i7
542
+ r7 = nil
543
+ else
544
+ r7 = instantiate_node(SyntaxNode,input, i7...index, s7)
545
+ end
546
+ s5 << r7
547
+ if r7
548
+ if has_terminal?(']', false, index)
549
+ r9 = instantiate_node(SyntaxNode,input, index...(index + 1))
550
+ @index += 1
551
+ else
552
+ terminal_parse_failure(']')
553
+ r9 = nil
554
+ end
555
+ s5 << r9
556
+ end
557
+ end
558
+ if s5.last
559
+ r5 = instantiate_node(AST::IdentifierLiteral,input, i5...index, s5)
560
+ r5.extend(Identifier1)
561
+ else
562
+ @index = i5
563
+ r5 = nil
564
+ end
565
+ if r5
566
+ r0 = r5
567
+ else
568
+ @index = i0
569
+ r0 = nil
570
+ end
571
+ end
572
+
573
+ node_cache[:identifier][start_index] = r0
574
+
575
+ r0
576
+ end
577
+
578
+ def _nt_value
579
+ start_index = index
580
+ if node_cache[:value].has_key?(index)
581
+ cached = node_cache[:value][index]
582
+ if cached
583
+ cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
584
+ @index = cached.interval.end
585
+ end
586
+ return cached
587
+ end
588
+
589
+ i0 = index
590
+ r1 = _nt_float
591
+ if r1
592
+ r0 = r1
593
+ else
594
+ r2 = _nt_integer
595
+ if r2
596
+ r0 = r2
597
+ else
598
+ r3 = _nt_string
599
+ if r3
600
+ r0 = r3
601
+ else
602
+ r4 = _nt_boolean
603
+ if r4
604
+ r0 = r4
605
+ else
606
+ r5 = _nt_table
607
+ if r5
608
+ r0 = r5
609
+ else
610
+ @index = i0
611
+ r0 = nil
612
+ end
613
+ end
614
+ end
615
+ end
616
+ end
617
+
618
+ node_cache[:value][start_index] = r0
619
+
620
+ r0
621
+ end
622
+
623
+ module Assignment0
624
+ def identifier
625
+ elements[0]
626
+ end
627
+
628
+ def value
629
+ elements[2]
630
+ end
631
+ end
632
+
633
+ def _nt_assignment
634
+ start_index = index
635
+ if node_cache[:assignment].has_key?(index)
636
+ cached = node_cache[:assignment][index]
637
+ if cached
638
+ cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
639
+ @index = cached.interval.end
640
+ end
641
+ return cached
642
+ end
643
+
644
+ i0, s0 = index, []
645
+ r1 = _nt_identifier
646
+ s0 << r1
647
+ if r1
648
+ if has_terminal?('=', false, index)
649
+ r2 = instantiate_node(SyntaxNode,input, index...(index + 1))
650
+ @index += 1
651
+ else
652
+ terminal_parse_failure('=')
653
+ r2 = nil
654
+ end
655
+ s0 << r2
656
+ if r2
657
+ r3 = _nt_value
658
+ s0 << r3
659
+ end
660
+ end
661
+ if s0.last
662
+ r0 = instantiate_node(AST::Assignment,input, i0...index, s0)
663
+ r0.extend(Assignment0)
664
+ else
665
+ @index = i0
666
+ r0 = nil
667
+ end
668
+
669
+ node_cache[:assignment][start_index] = r0
670
+
671
+ r0
672
+ end
673
+
674
+ end
675
+
676
+ class LuaTableDumpParser < Treetop::Runtime::CompiledParser
677
+ include LuaTableDump
678
+ end
679
+
680
+ end