tomlrb 1.0.1 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +4 -2
- data/lib/tomlrb.rb +2 -1
- data/lib/tomlrb/generated_parser.rb +105 -109
- data/lib/tomlrb/handler.rb +9 -5
- data/lib/tomlrb/parser.rb +2 -2
- data/lib/tomlrb/parser.y +1 -5
- data/lib/tomlrb/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 752cc47c45ecffc6b2c80ec8ff41ba2bec5481d6
|
4
|
+
data.tar.gz: de853f73c1ce4b01827c642ae894ad21d0ddc2a7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3a16252642e7a281b696cb44f008d00bb85ecd2a7d50986ffa9e8eec710588a3bcde859285a3e954b9bd850b0a6d2750a975c94c53a07067c2b5cb48218bea5d
|
7
|
+
data.tar.gz: 65ef3514b3fe8f93c9cfc3f535401f9340e57a2910a5b2afdf13d7d8ad578eefb739bc1b9e637215fcfede56e76496d22c4ee1cde134d0a4f67a78409d954c60
|
data/README.md
CHANGED
@@ -1,14 +1,16 @@
|
|
1
1
|
# Tomlrb
|
2
2
|
|
3
|
-
[![Code Climate](https://codeclimate.com/github/fbernier/tomlrb/badges/gpa.svg)](https://codeclimate.com/github/fbernier/tomlrb) [![Build Status](https://travis-ci.org/fbernier/tomlrb.svg)](https://travis-ci.org/fbernier/tomlrb)
|
3
|
+
[![Code Climate](https://codeclimate.com/github/fbernier/tomlrb/badges/gpa.svg)](https://codeclimate.com/github/fbernier/tomlrb) [![Build Status](https://travis-ci.org/fbernier/tomlrb.svg)](https://travis-ci.org/fbernier/tomlrb) [![Gem Version](https://badge.fury.io/rb/tomlrb.svg)](http://badge.fury.io/rb/tomlrb)
|
4
4
|
|
5
5
|
A Racc based [TOML](https://github.com/toml-lang/toml) parser supporting the 0.4.0 version of the spec.
|
6
6
|
|
7
7
|
|
8
8
|
## TODO
|
9
9
|
|
10
|
+
* Error handling
|
10
11
|
* Better tests
|
11
12
|
* Dumper
|
13
|
+
* Refactoring
|
12
14
|
|
13
15
|
## Installation
|
14
16
|
|
@@ -35,7 +37,7 @@ Tomlrb.parse("[toml]\na = [\"array\", 123]")
|
|
35
37
|
or
|
36
38
|
|
37
39
|
```ruby
|
38
|
-
Tomlrb.load_file('my_file')
|
40
|
+
Tomlrb.load_file('my_file', symbolize_keys: true)
|
39
41
|
```
|
40
42
|
|
41
43
|
## Development
|
data/lib/tomlrb.rb
CHANGED
@@ -7,10 +7,11 @@ require "tomlrb/parser"
|
|
7
7
|
require "tomlrb/handler"
|
8
8
|
|
9
9
|
module Tomlrb
|
10
|
+
|
10
11
|
def self.parse(string_or_io, **options)
|
11
12
|
io = string_or_io.is_a?(String) ? StringIO.new(string_or_io) : string_or_io
|
12
13
|
scanner = Scanner.new(io)
|
13
|
-
parser = Parser.new(scanner)
|
14
|
+
parser = Parser.new(scanner, options)
|
14
15
|
handler = parser.parse
|
15
16
|
handler.output
|
16
17
|
end
|
@@ -10,75 +10,75 @@ module Tomlrb
|
|
10
10
|
##### State transition tables begin ###
|
11
11
|
|
12
12
|
racc_action_table = [
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
42,
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
nil, nil,
|
13
|
+
2, 13, 11, 23, 12, 23, 61, 17, 19, 18,
|
14
|
+
62, 24, 8, 28, 29, 10, 25, 21, 15, 21,
|
15
|
+
45, 46, 47, 48, 44, 41, 40, 42, 43, 34,
|
16
|
+
53, 54, 10, 45, 46, 47, 48, 44, 41, 40,
|
17
|
+
42, 43, 34, 26, 31, 10, 45, 46, 47, 48,
|
18
|
+
44, 41, 40, 42, 43, 34, 50, nil, 10, 45,
|
19
|
+
46, 47, 48, 44, 41, 40, 42, 43, 34, 57,
|
20
|
+
nil, 10, 45, 46, 47, 48, 44, 41, 40, 42,
|
21
|
+
43, 34, 57, 17, 10, 18, nil, nil, nil, nil,
|
22
|
+
nil, nil, nil, nil, 15 ]
|
23
23
|
|
24
24
|
racc_action_check = [
|
25
|
-
1,
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
25, 25, 25,
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
nil, nil,
|
25
|
+
1, 2, 1, 9, 1, 54, 58, 7, 8, 7,
|
26
|
+
58, 11, 1, 16, 16, 1, 12, 9, 7, 54,
|
27
|
+
24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
|
28
|
+
30, 30, 24, 25, 25, 25, 25, 25, 25, 25,
|
29
|
+
25, 25, 25, 15, 22, 25, 31, 31, 31, 31,
|
30
|
+
31, 31, 31, 31, 31, 31, 28, nil, 31, 33,
|
31
|
+
33, 33, 33, 33, 33, 33, 33, 33, 33, 33,
|
32
|
+
nil, 33, 62, 62, 62, 62, 62, 62, 62, 62,
|
33
|
+
62, 62, 62, 29, 62, 29, nil, nil, nil, nil,
|
34
|
+
nil, nil, nil, nil, 29 ]
|
35
35
|
|
36
36
|
racc_action_pointer = [
|
37
|
-
|
38
|
-
-
|
39
|
-
nil, nil,
|
40
|
-
|
37
|
+
nil, 0, 1, nil, nil, nil, nil, 5, -4, 1,
|
38
|
+
nil, -7, -2, nil, nil, 30, 0, nil, nil, nil,
|
39
|
+
nil, nil, 26, nil, 17, 30, nil, nil, 43, 81,
|
40
|
+
14, 43, nil, 56, nil, nil, nil, nil, nil, nil,
|
41
41
|
nil, nil, nil, nil, nil, nil, nil, nil, nil, nil,
|
42
|
-
nil, nil, nil, nil,
|
43
|
-
nil, nil,
|
42
|
+
nil, nil, nil, nil, 3, nil, nil, nil, -7, nil,
|
43
|
+
nil, nil, 69, nil ]
|
44
44
|
|
45
45
|
racc_action_default = [
|
46
|
-
-
|
47
|
-
-
|
48
|
-
-17, -19, -
|
49
|
-
-
|
50
|
-
-
|
51
|
-
-
|
52
|
-
-
|
46
|
+
-1, -48, -48, -2, -3, -4, -5, -48, -8, -48,
|
47
|
+
-18, -48, -48, 64, -6, -10, -48, -15, -16, -7,
|
48
|
+
-17, -19, -48, -23, -38, -38, -9, -11, -13, -48,
|
49
|
+
-48, -38, -25, -38, -32, -33, -34, -35, -36, -37,
|
50
|
+
-39, -40, -41, -42, -43, -44, -45, -46, -47, -26,
|
51
|
+
-12, -14, -20, -21, -48, -24, -27, -28, -48, -22,
|
52
|
+
-29, -30, -38, -31 ]
|
53
53
|
|
54
54
|
racc_goto_table = [
|
55
|
-
20,
|
56
|
-
|
57
|
-
nil, nil, nil, nil, nil, nil,
|
58
|
-
|
59
|
-
nil, nil, nil, nil, nil,
|
55
|
+
20, 56, 14, 32, 49, 1, 3, 4, 5, 6,
|
56
|
+
55, 7, 27, 30, 52, 60, nil, nil, nil, nil,
|
57
|
+
nil, nil, nil, nil, 51, nil, nil, nil, nil, nil,
|
58
|
+
63, nil, nil, nil, nil, nil, nil, nil, nil, nil,
|
59
|
+
nil, nil, nil, nil, nil, 59 ]
|
60
60
|
|
61
61
|
racc_goto_check = [
|
62
|
-
11, 18, 7, 15, 15,
|
63
|
-
9,
|
64
|
-
nil, nil, nil, nil, nil, nil,
|
62
|
+
11, 18, 7, 15, 15, 1, 2, 3, 4, 5,
|
63
|
+
15, 6, 9, 13, 14, 19, nil, nil, nil, nil,
|
64
|
+
nil, nil, nil, nil, 7, nil, nil, nil, nil, nil,
|
65
65
|
18, nil, nil, nil, nil, nil, nil, nil, nil, nil,
|
66
|
-
nil, nil, nil, nil, nil,
|
66
|
+
nil, nil, nil, nil, nil, 11 ]
|
67
67
|
|
68
68
|
racc_goto_pointer = [
|
69
|
-
nil,
|
70
|
-
nil, -
|
71
|
-
nil, nil, nil
|
69
|
+
nil, 5, 5, 6, 7, 8, 10, -5, nil, -4,
|
70
|
+
nil, -9, nil, -9, -16, -21, nil, nil, -32, -43,
|
71
|
+
nil, nil, nil ]
|
72
72
|
|
73
73
|
racc_goto_default = [
|
74
|
-
nil, nil, nil,
|
75
|
-
|
76
|
-
|
74
|
+
nil, nil, nil, nil, nil, 37, nil, nil, 16, nil,
|
75
|
+
9, nil, 22, nil, nil, 58, 36, 33, nil, nil,
|
76
|
+
35, 38, 39 ]
|
77
77
|
|
78
78
|
racc_reduce_table = [
|
79
79
|
0, 0, :racc_error,
|
80
|
+
0, 20, :_reduce_none,
|
80
81
|
2, 20, :_reduce_none,
|
81
|
-
1, 20, :_reduce_none,
|
82
82
|
1, 21, :_reduce_none,
|
83
83
|
1, 21, :_reduce_none,
|
84
84
|
1, 21, :_reduce_none,
|
@@ -109,26 +109,25 @@ racc_reduce_table = [
|
|
109
109
|
1, 38, :_reduce_30,
|
110
110
|
2, 38, :_reduce_none,
|
111
111
|
1, 36, :_reduce_32,
|
112
|
-
1,
|
113
|
-
1, 34, :_reduce_34,
|
112
|
+
1, 34, :_reduce_33,
|
114
113
|
1, 34, :_reduce_none,
|
115
114
|
1, 34, :_reduce_none,
|
116
|
-
1,
|
117
|
-
1,
|
118
|
-
0,
|
119
|
-
1,
|
120
|
-
1,
|
121
|
-
1,
|
122
|
-
1,
|
123
|
-
1,
|
124
|
-
1,
|
125
|
-
1,
|
126
|
-
1,
|
127
|
-
1,
|
128
|
-
|
129
|
-
racc_reduce_n =
|
130
|
-
|
131
|
-
racc_shift_n =
|
115
|
+
1, 39, :_reduce_none,
|
116
|
+
1, 39, :_reduce_none,
|
117
|
+
0, 41, :_reduce_none,
|
118
|
+
1, 41, :_reduce_39,
|
119
|
+
1, 41, :_reduce_40,
|
120
|
+
1, 41, :_reduce_41,
|
121
|
+
1, 41, :_reduce_42,
|
122
|
+
1, 41, :_reduce_43,
|
123
|
+
1, 40, :_reduce_44,
|
124
|
+
1, 40, :_reduce_45,
|
125
|
+
1, 40, :_reduce_46,
|
126
|
+
1, 40, :_reduce_47 ]
|
127
|
+
|
128
|
+
racc_reduce_n = 48
|
129
|
+
|
130
|
+
racc_shift_n = 64
|
132
131
|
|
133
132
|
racc_token_table = {
|
134
133
|
false => 0,
|
@@ -211,7 +210,6 @@ Racc_token_to_s_table = [
|
|
211
210
|
"start_array",
|
212
211
|
"array_continued",
|
213
212
|
"array_next",
|
214
|
-
"end_array",
|
215
213
|
"scalar",
|
216
214
|
"string",
|
217
215
|
"literal" ]
|
@@ -234,28 +232,28 @@ Racc_debug_parser = false
|
|
234
232
|
|
235
233
|
# reduce 6 omitted
|
236
234
|
|
237
|
-
module_eval(<<'.,.,', 'parser.y',
|
235
|
+
module_eval(<<'.,.,', 'parser.y', 15)
|
238
236
|
def _reduce_7(val, _values, result)
|
239
237
|
@handler.start_(:array_of_tables)
|
240
238
|
result
|
241
239
|
end
|
242
240
|
.,.,
|
243
241
|
|
244
|
-
module_eval(<<'.,.,', 'parser.y',
|
242
|
+
module_eval(<<'.,.,', 'parser.y', 16)
|
245
243
|
def _reduce_8(val, _values, result)
|
246
244
|
@handler.start_(:table)
|
247
245
|
result
|
248
246
|
end
|
249
247
|
.,.,
|
250
248
|
|
251
|
-
module_eval(<<'.,.,', 'parser.y',
|
249
|
+
module_eval(<<'.,.,', 'parser.y', 19)
|
252
250
|
def _reduce_9(val, _values, result)
|
253
251
|
array = @handler.end_(:array_of_tables); @handler.set_context(array, is_array_of_tables: true)
|
254
252
|
result
|
255
253
|
end
|
256
254
|
.,.,
|
257
255
|
|
258
|
-
module_eval(<<'.,.,', 'parser.y',
|
256
|
+
module_eval(<<'.,.,', 'parser.y', 20)
|
259
257
|
def _reduce_10(val, _values, result)
|
260
258
|
array = @handler.end_(:table); @handler.set_context(array)
|
261
259
|
result
|
@@ -264,14 +262,14 @@ module_eval(<<'.,.,', 'parser.y', 21)
|
|
264
262
|
|
265
263
|
# reduce 11 omitted
|
266
264
|
|
267
|
-
module_eval(<<'.,.,', 'parser.y',
|
265
|
+
module_eval(<<'.,.,', 'parser.y', 24)
|
268
266
|
def _reduce_12(val, _values, result)
|
269
267
|
array = @handler.end_(:array_of_tables); @handler.set_context(array, is_array_of_tables: true)
|
270
268
|
result
|
271
269
|
end
|
272
270
|
.,.,
|
273
271
|
|
274
|
-
module_eval(<<'.,.,', 'parser.y',
|
272
|
+
module_eval(<<'.,.,', 'parser.y', 25)
|
275
273
|
def _reduce_13(val, _values, result)
|
276
274
|
array = @handler.end_(:table); @handler.set_context(array)
|
277
275
|
result
|
@@ -280,14 +278,14 @@ module_eval(<<'.,.,', 'parser.y', 26)
|
|
280
278
|
|
281
279
|
# reduce 14 omitted
|
282
280
|
|
283
|
-
module_eval(<<'.,.,', 'parser.y',
|
281
|
+
module_eval(<<'.,.,', 'parser.y', 29)
|
284
282
|
def _reduce_15(val, _values, result)
|
285
283
|
@handler.push(val[0])
|
286
284
|
result
|
287
285
|
end
|
288
286
|
.,.,
|
289
287
|
|
290
|
-
module_eval(<<'.,.,', 'parser.y',
|
288
|
+
module_eval(<<'.,.,', 'parser.y', 30)
|
291
289
|
def _reduce_16(val, _values, result)
|
292
290
|
@handler.push(val[0])
|
293
291
|
result
|
@@ -296,14 +294,14 @@ module_eval(<<'.,.,', 'parser.y', 31)
|
|
296
294
|
|
297
295
|
# reduce 17 omitted
|
298
296
|
|
299
|
-
module_eval(<<'.,.,', 'parser.y',
|
297
|
+
module_eval(<<'.,.,', 'parser.y', 36)
|
300
298
|
def _reduce_18(val, _values, result)
|
301
299
|
@handler.start_(:inline)
|
302
300
|
result
|
303
301
|
end
|
304
302
|
.,.,
|
305
303
|
|
306
|
-
module_eval(<<'.,.,', 'parser.y',
|
304
|
+
module_eval(<<'.,.,', 'parser.y', 39)
|
307
305
|
def _reduce_19(val, _values, result)
|
308
306
|
array = @handler.end_(:inline); @handler.push(Hash[*array])
|
309
307
|
result
|
@@ -312,7 +310,7 @@ module_eval(<<'.,.,', 'parser.y', 40)
|
|
312
310
|
|
313
311
|
# reduce 20 omitted
|
314
312
|
|
315
|
-
module_eval(<<'.,.,', 'parser.y',
|
313
|
+
module_eval(<<'.,.,', 'parser.y', 43)
|
316
314
|
def _reduce_21(val, _values, result)
|
317
315
|
array = @handler.end_(:inline); @handler.push(Hash[*array])
|
318
316
|
result
|
@@ -321,7 +319,7 @@ module_eval(<<'.,.,', 'parser.y', 44)
|
|
321
319
|
|
322
320
|
# reduce 22 omitted
|
323
321
|
|
324
|
-
module_eval(<<'.,.,', 'parser.y',
|
322
|
+
module_eval(<<'.,.,', 'parser.y', 47)
|
325
323
|
def _reduce_23(val, _values, result)
|
326
324
|
@handler.push(val[0])
|
327
325
|
result
|
@@ -330,14 +328,14 @@ module_eval(<<'.,.,', 'parser.y', 48)
|
|
330
328
|
|
331
329
|
# reduce 24 omitted
|
332
330
|
|
333
|
-
module_eval(<<'.,.,', 'parser.y',
|
331
|
+
module_eval(<<'.,.,', 'parser.y', 53)
|
334
332
|
def _reduce_25(val, _values, result)
|
335
333
|
@handler.assign(val[0])
|
336
334
|
result
|
337
335
|
end
|
338
336
|
.,.,
|
339
337
|
|
340
|
-
module_eval(<<'.,.,', 'parser.y',
|
338
|
+
module_eval(<<'.,.,', 'parser.y', 54)
|
341
339
|
def _reduce_26(val, _values, result)
|
342
340
|
@handler.assign(val[0])
|
343
341
|
result
|
@@ -346,7 +344,7 @@ module_eval(<<'.,.,', 'parser.y', 55)
|
|
346
344
|
|
347
345
|
# reduce 27 omitted
|
348
346
|
|
349
|
-
module_eval(<<'.,.,', 'parser.y',
|
347
|
+
module_eval(<<'.,.,', 'parser.y', 60)
|
350
348
|
def _reduce_28(val, _values, result)
|
351
349
|
array = @handler.end_(:array); @handler.push(array)
|
352
350
|
result
|
@@ -355,7 +353,7 @@ module_eval(<<'.,.,', 'parser.y', 61)
|
|
355
353
|
|
356
354
|
# reduce 29 omitted
|
357
355
|
|
358
|
-
module_eval(<<'.,.,', 'parser.y',
|
356
|
+
module_eval(<<'.,.,', 'parser.y', 64)
|
359
357
|
def _reduce_30(val, _values, result)
|
360
358
|
array = @handler.end_(:array); @handler.push(array)
|
361
359
|
result
|
@@ -364,22 +362,22 @@ module_eval(<<'.,.,', 'parser.y', 65)
|
|
364
362
|
|
365
363
|
# reduce 31 omitted
|
366
364
|
|
367
|
-
module_eval(<<'.,.,', 'parser.y',
|
365
|
+
module_eval(<<'.,.,', 'parser.y', 68)
|
368
366
|
def _reduce_32(val, _values, result)
|
369
367
|
@handler.start_(:array)
|
370
368
|
result
|
371
369
|
end
|
372
370
|
.,.,
|
373
371
|
|
374
|
-
|
375
|
-
|
376
|
-
module_eval(<<'.,.,', 'parser.y', 75)
|
377
|
-
def _reduce_34(val, _values, result)
|
372
|
+
module_eval(<<'.,.,', 'parser.y', 71)
|
373
|
+
def _reduce_33(val, _values, result)
|
378
374
|
@handler.push(val[0])
|
379
375
|
result
|
380
376
|
end
|
381
377
|
.,.,
|
382
378
|
|
379
|
+
# reduce 34 omitted
|
380
|
+
|
383
381
|
# reduce 35 omitted
|
384
382
|
|
385
383
|
# reduce 36 omitted
|
@@ -388,66 +386,64 @@ module_eval(<<'.,.,', 'parser.y', 75)
|
|
388
386
|
|
389
387
|
# reduce 38 omitted
|
390
388
|
|
391
|
-
|
392
|
-
|
393
|
-
module_eval(<<'.,.,', 'parser.y', 84)
|
394
|
-
def _reduce_40(val, _values, result)
|
389
|
+
module_eval(<<'.,.,', 'parser.y', 80)
|
390
|
+
def _reduce_39(val, _values, result)
|
395
391
|
result = val[0].to_f
|
396
392
|
result
|
397
393
|
end
|
398
394
|
.,.,
|
399
395
|
|
400
|
-
module_eval(<<'.,.,', 'parser.y',
|
401
|
-
def
|
396
|
+
module_eval(<<'.,.,', 'parser.y', 81)
|
397
|
+
def _reduce_40(val, _values, result)
|
402
398
|
result = val[0].to_i
|
403
399
|
result
|
404
400
|
end
|
405
401
|
.,.,
|
406
402
|
|
407
|
-
module_eval(<<'.,.,', 'parser.y',
|
408
|
-
def
|
403
|
+
module_eval(<<'.,.,', 'parser.y', 82)
|
404
|
+
def _reduce_41(val, _values, result)
|
409
405
|
result = true
|
410
406
|
result
|
411
407
|
end
|
412
408
|
.,.,
|
413
409
|
|
414
|
-
module_eval(<<'.,.,', 'parser.y',
|
415
|
-
def
|
410
|
+
module_eval(<<'.,.,', 'parser.y', 83)
|
411
|
+
def _reduce_42(val, _values, result)
|
416
412
|
result = false
|
417
413
|
result
|
418
414
|
end
|
419
415
|
.,.,
|
420
416
|
|
421
|
-
module_eval(<<'.,.,', 'parser.y',
|
422
|
-
def
|
417
|
+
module_eval(<<'.,.,', 'parser.y', 84)
|
418
|
+
def _reduce_43(val, _values, result)
|
423
419
|
result = Time.parse(val[0])
|
424
420
|
result
|
425
421
|
end
|
426
422
|
.,.,
|
427
423
|
|
428
|
-
module_eval(<<'.,.,', 'parser.y',
|
429
|
-
def
|
424
|
+
module_eval(<<'.,.,', 'parser.y', 87)
|
425
|
+
def _reduce_44(val, _values, result)
|
430
426
|
result = StringUtils.replace_escaped_chars(StringUtils.multiline_replacements(val[0]))
|
431
427
|
result
|
432
428
|
end
|
433
429
|
.,.,
|
434
430
|
|
435
|
-
module_eval(<<'.,.,', 'parser.y',
|
436
|
-
def
|
431
|
+
module_eval(<<'.,.,', 'parser.y', 88)
|
432
|
+
def _reduce_45(val, _values, result)
|
437
433
|
result = StringUtils.replace_escaped_chars(val[0])
|
438
434
|
result
|
439
435
|
end
|
440
436
|
.,.,
|
441
437
|
|
442
|
-
module_eval(<<'.,.,', 'parser.y',
|
443
|
-
def
|
438
|
+
module_eval(<<'.,.,', 'parser.y', 89)
|
439
|
+
def _reduce_46(val, _values, result)
|
444
440
|
result = StringUtils.replace_escaped_chars(StringUtils.strip_spaces(val[0]))
|
445
441
|
result
|
446
442
|
end
|
447
443
|
.,.,
|
448
444
|
|
449
|
-
module_eval(<<'.,.,', 'parser.y',
|
450
|
-
def
|
445
|
+
module_eval(<<'.,.,', 'parser.y', 90)
|
446
|
+
def _reduce_47(val, _values, result)
|
451
447
|
result = StringUtils.strip_spaces(val[0])
|
452
448
|
result
|
453
449
|
end
|
data/lib/tomlrb/handler.rb
CHANGED
@@ -2,17 +2,19 @@ module Tomlrb
|
|
2
2
|
class Handler
|
3
3
|
attr_reader :output
|
4
4
|
|
5
|
-
def initialize
|
5
|
+
def initialize(**options)
|
6
6
|
@output = {}
|
7
7
|
@current = @output
|
8
8
|
@stack = []
|
9
|
+
@symbolize_keys = options[:symbolize_keys]
|
9
10
|
end
|
10
11
|
|
11
|
-
def set_context(
|
12
|
+
def set_context(identifiers, is_array_of_tables: false)
|
12
13
|
@current = @output
|
13
14
|
|
14
|
-
|
15
|
-
|
15
|
+
deal_with_array_of_tables(identifiers, is_array_of_tables) do |identifierz|
|
16
|
+
identifierz.each do |k|
|
17
|
+
k = k.to_sym if @symbolize_keys
|
16
18
|
if @current[k].is_a?(Array)
|
17
19
|
@current[k] << {} if @current[k].empty?
|
18
20
|
@current = @current[k].last
|
@@ -24,13 +26,14 @@ module Tomlrb
|
|
24
26
|
end
|
25
27
|
end
|
26
28
|
|
27
|
-
def
|
29
|
+
def deal_with_array_of_tables(identifiers, is_array_of_tables)
|
28
30
|
identifiers.map!{|n| n.gsub("\"", '')}
|
29
31
|
last_identifier = identifiers.pop if is_array_of_tables
|
30
32
|
|
31
33
|
yield(identifiers)
|
32
34
|
|
33
35
|
if is_array_of_tables
|
36
|
+
last_identifier = last_identifier.to_sym if @symbolize_keys
|
34
37
|
@current[last_identifier] ||= []
|
35
38
|
@current[last_identifier] << {}
|
36
39
|
@current = @current[last_identifier].last
|
@@ -38,6 +41,7 @@ module Tomlrb
|
|
38
41
|
end
|
39
42
|
|
40
43
|
def assign(k)
|
44
|
+
k = k.to_sym if @symbolize_keys
|
41
45
|
@current[k] = @stack.pop
|
42
46
|
end
|
43
47
|
|
data/lib/tomlrb/parser.rb
CHANGED
@@ -2,9 +2,9 @@ require "tomlrb/generated_parser"
|
|
2
2
|
|
3
3
|
class Tomlrb::Parser < Tomlrb::GeneratedParser
|
4
4
|
|
5
|
-
def initialize(tokenizer,
|
5
|
+
def initialize(tokenizer, **options)
|
6
6
|
@tokenizer = tokenizer
|
7
|
-
@handler =
|
7
|
+
@handler = Tomlrb::Handler.new(options)
|
8
8
|
super()
|
9
9
|
end
|
10
10
|
|
data/lib/tomlrb/parser.y
CHANGED
@@ -2,8 +2,7 @@ class Tomlrb::GeneratedParser
|
|
2
2
|
token IDENTIFIER STRING_MULTI STRING_BASIC STRING_LITERAL_MULTI STRING_LITERAL DATETIME INTEGER FLOAT TRUE FALSE
|
3
3
|
rule
|
4
4
|
expressions
|
5
|
-
|
6
|
-
| expression
|
5
|
+
| expressions expression
|
7
6
|
;
|
8
7
|
expression
|
9
8
|
: table
|
@@ -69,9 +68,6 @@ rule
|
|
69
68
|
start_array
|
70
69
|
: '[' { @handler.start_(:array) }
|
71
70
|
;
|
72
|
-
end_array
|
73
|
-
: ']'
|
74
|
-
;
|
75
71
|
value
|
76
72
|
: scalar { @handler.push(val[0]) }
|
77
73
|
| array
|
data/lib/tomlrb/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tomlrb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Francois Bernier
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-04-
|
11
|
+
date: 2015-04-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|