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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0fb32099921d6d4cabb4f18af23ced18a1549769
4
- data.tar.gz: 08adb1404068e0d263cfd71e4381306b6c74bbfd
3
+ metadata.gz: 752cc47c45ecffc6b2c80ec8ff41ba2bec5481d6
4
+ data.tar.gz: de853f73c1ce4b01827c642ae894ad21d0ddc2a7
5
5
  SHA512:
6
- metadata.gz: 8241b67862dac85836e6b4502c5acc143bc735ae0a4bc8921c51f77817494a9f62e2bba5b2b9be564d0a3dcca29e2099062fbd03b36a3148aa661e127c6dbdc9
7
- data.tar.gz: 1aa537c52381ee9bdca4ccfa7b4be8ec364e2483b8f1c355cc73b7eccabb75e14547b4e1b95d51e268c0c9c9cc84e7d435093bc7d10dfca59c67087cf934f9ec
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
@@ -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
- 12, 19, 10, 23, 11, 23, 29, 30, 10, 17,
14
- 11, 18, 7, 54, 55, 9, 24, 21, 7, 21,
15
- 15, 9, 46, 47, 48, 49, 45, 42, 41, 43,
16
- 44, 35, 25, 26, 9, 46, 47, 48, 49, 45,
17
- 42, 41, 43, 44, 35, 27, 32, 9, 46, 47,
18
- 48, 49, 45, 42, 41, 43, 44, 35, 51, nil,
19
- 9, 46, 47, 48, 49, 45, 42, 41, 43, 44,
20
- 35, 58, nil, 9, 46, 47, 48, 49, 45, 42,
21
- 41, 43, 44, 35, 58, 17, 9, 18, 62, nil,
22
- nil, nil, 63, nil, nil, nil, 15 ]
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, 7, 1, 8, 1, 55, 16, 16, 0, 6,
26
- 0, 6, 1, 31, 31, 1, 10, 8, 0, 55,
27
- 6, 0, 24, 24, 24, 24, 24, 24, 24, 24,
28
- 24, 24, 11, 12, 24, 25, 25, 25, 25, 25,
29
- 25, 25, 25, 25, 25, 15, 22, 25, 32, 32,
30
- 32, 32, 32, 32, 32, 32, 32, 32, 29, nil,
31
- 32, 34, 34, 34, 34, 34, 34, 34, 34, 34,
32
- 34, 34, nil, 34, 63, 63, 63, 63, 63, 63,
33
- 63, 63, 63, 63, 63, 30, 63, 30, 59, nil,
34
- nil, nil, 59, nil, nil, nil, 30 ]
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
- 6, 0, nil, nil, nil, nil, 7, -11, 1, nil,
38
- -2, 14, 33, nil, nil, 32, -7, nil, nil, nil,
39
- nil, nil, 28, nil, 19, 32, nil, nil, nil, 45,
40
- 83, -3, 45, nil, 58, nil, nil, nil, nil, nil,
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, nil, 3, nil, nil, nil, 75,
43
- nil, nil, nil, 71, 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
- -49, -49, -2, -3, -4, -5, -49, -8, -49, -18,
47
- -49, -49, -49, -1, -6, -10, -49, -15, -16, -7,
48
- -17, -19, -49, -23, -39, -39, 65, -9, -11, -13,
49
- -49, -49, -39, -25, -39, -32, -34, -35, -36, -37,
50
- -38, -40, -41, -42, -43, -44, -45, -46, -47, -48,
51
- -26, -12, -14, -20, -21, -49, -24, -27, -28, -49,
52
- -22, -29, -30, -39, -31 ]
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, 57, 14, 33, 50, 2, 13, 5, 5, 1,
56
- 28, 56, 31, 53, 61, nil, nil, nil, nil, nil,
57
- nil, nil, nil, nil, nil, nil, 52, nil, nil, nil,
58
- 64, nil, nil, nil, nil, nil, nil, nil, nil, nil,
59
- nil, nil, nil, nil, nil, nil, nil, 60 ]
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, 2, 2, 5, 5, 1,
63
- 9, 15, 13, 14, 19, nil, nil, nil, nil, nil,
64
- nil, nil, nil, nil, nil, nil, 7, 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, nil, nil, 11 ]
66
+ nil, nil, nil, nil, nil, 11 ]
67
67
 
68
68
  racc_goto_pointer = [
69
- nil, 9, 5, nil, nil, 7, nil, -4, nil, -6,
70
- nil, -8, nil, -10, -18, -21, nil, nil, -33, -45,
71
- nil, 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, 3, 4, 38, 6, nil, 16, nil,
75
- 8, nil, 22, nil, nil, 59, 37, 34, nil, nil,
76
- nil, 36, 39, 40 ]
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, 39, :_reduce_none,
113
- 1, 34, :_reduce_34,
112
+ 1, 34, :_reduce_33,
114
113
  1, 34, :_reduce_none,
115
114
  1, 34, :_reduce_none,
116
- 1, 40, :_reduce_none,
117
- 1, 40, :_reduce_none,
118
- 0, 42, :_reduce_none,
119
- 1, 42, :_reduce_40,
120
- 1, 42, :_reduce_41,
121
- 1, 42, :_reduce_42,
122
- 1, 42, :_reduce_43,
123
- 1, 42, :_reduce_44,
124
- 1, 41, :_reduce_45,
125
- 1, 41, :_reduce_46,
126
- 1, 41, :_reduce_47,
127
- 1, 41, :_reduce_48 ]
128
-
129
- racc_reduce_n = 49
130
-
131
- racc_shift_n = 65
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', 16)
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', 17)
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', 20)
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', 21)
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', 25)
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', 26)
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', 30)
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', 31)
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', 37)
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', 40)
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', 44)
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', 48)
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', 54)
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', 55)
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', 61)
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', 65)
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', 69)
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
- # reduce 33 omitted
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
- # reduce 39 omitted
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', 85)
401
- def _reduce_41(val, _values, result)
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', 86)
408
- def _reduce_42(val, _values, result)
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', 87)
415
- def _reduce_43(val, _values, result)
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', 88)
422
- def _reduce_44(val, _values, result)
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', 91)
429
- def _reduce_45(val, _values, result)
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', 92)
436
- def _reduce_46(val, _values, result)
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', 93)
443
- def _reduce_47(val, _values, result)
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', 94)
450
- def _reduce_48(val, _values, result)
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
@@ -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(identifierz, is_array_of_tables: false)
12
+ def set_context(identifiers, is_array_of_tables: false)
12
13
  @current = @output
13
14
 
14
- deal_with_array_of_table(identifierz, is_array_of_tables) do |identifiers|
15
- identifiers.each do |k|
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 deal_with_array_of_table(identifiers, is_array_of_tables)
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
 
@@ -2,9 +2,9 @@ require "tomlrb/generated_parser"
2
2
 
3
3
  class Tomlrb::Parser < Tomlrb::GeneratedParser
4
4
 
5
- def initialize(tokenizer, handler = Tomlrb::Handler.new)
5
+ def initialize(tokenizer, **options)
6
6
  @tokenizer = tokenizer
7
- @handler = handler
7
+ @handler = Tomlrb::Handler.new(options)
8
8
  super()
9
9
  end
10
10
 
@@ -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
- : expressions expression
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
@@ -1,3 +1,3 @@
1
1
  module Tomlrb
2
- VERSION = "1.0.1"
2
+ VERSION = "1.0.2"
3
3
  end
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.1
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-17 00:00:00.000000000 Z
11
+ date: 2015-04-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler