toml-rb 0.3.10 → 0.3.11

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: c08aa29a171d7d63f32f49b003ba684889066e10
4
- data.tar.gz: 6e691196c2fbf7f76d84bd9e3d9c4f404dc4b44b
3
+ metadata.gz: 49771b4d2a6fdf577cafa264b5da35661c74610f
4
+ data.tar.gz: c4d4032d52979ef02600913a61719ec28164c435
5
5
  SHA512:
6
- metadata.gz: afc71aad3baf66c57e2e5edb067a3bf03855a35abb9f983e6b1300d3d7ca1ebfdcdb7fce5a82fc04067300ee84f1b7b9563832bc98ff9d97a9156ce5a6bd921a
7
- data.tar.gz: 7e779c92833849403f5b805883126611212d43582a9e852395254eb99d78831d1d5cae33d4485eb1faf8f62ea0306fe85bb77000f176833835cfabdfdff96130
6
+ metadata.gz: 75df0a53ca6c3c98a9b8e9a53a4201538fb6e2d3afe9f19f8edf7f1016fa95ddf8b6ceb93d6e6961a53b86a2465b3c0b186fc60d3a505ca3d64e1d3f64957f0f
7
+ data.tar.gz: 8bf0535e21dce48b87e5ffa774be8155c8427278db6f2a8bcaaf790b6f2591f4e680c2d5ed61e2b9a63cbf3cbfae88fbd9dd34f957644ebf1b9ffdf7a9f287f5
@@ -7,15 +7,15 @@ grammar TOML::Document
7
7
  end
8
8
 
9
9
  rule table_array
10
- (space? '[[' ((key "."?)+|'"'(space? key space? "."?)+'"') ']]' space? comment?) <TOML::TableArrayParser>
10
+ (space? '[[' stripped_key ("." stripped_key)* ']]' comment?) <TOML::TableArrayParser>
11
11
  end
12
12
 
13
13
  rule keygroup
14
- (space? '[' ((key "."?)+|'"'(space? key space? "."?)+'"') ']' space? comment?) <TOML::KeygroupParser>
14
+ (space? '[' stripped_key ("." stripped_key)* ']' comment?) <TOML::KeygroupParser>
15
15
  end
16
16
 
17
17
  rule keyvalue
18
- (space? key space? '=' space? v:(toml_values) comment?) <TOML::KeyvalueParser>
18
+ (stripped_key '=' space? v:(toml_values) comment?) <TOML::KeyvalueParser>
19
19
  end
20
20
 
21
21
  rule inline_table
@@ -34,5 +34,7 @@ grammar TOML::Document
34
34
  primitive | inline_table | array | inline_table_array
35
35
  end
36
36
 
37
-
37
+ rule stripped_key
38
+ (space? key space?) { captures[:key].first.value }
39
+ end
38
40
  end
@@ -34,8 +34,8 @@ grammar TOML::Primitive
34
34
  ##
35
35
 
36
36
  rule datetime
37
- (date_skeleton ("Z" | date_offset | [,\.] frac:(/\d/1*6) date_offset)) {
38
- skeleton = captures[:date_skeleton].first
37
+ ( skeleton:(datetime_skeleton | date_skeleton) ("Z" | date_offset | [,\.] frac:(/\d/1*6) date_offset?)? ) {
38
+ skeleton = captures[:skeleton].first
39
39
  y,m,d,h,mi,s = skeleton.value
40
40
  offset = captures[:date_offset].first || "+00:00"
41
41
  sec_frac = captures[:frac].first || 0
@@ -45,7 +45,7 @@ grammar TOML::Primitive
45
45
  }
46
46
  end
47
47
 
48
- rule date_skeleton
48
+ rule datetime_skeleton
49
49
  (y:/\d\d\d\d/ "-" m:/\d\d/ "-" d:/\d\d/ "T" h:/\d\d/ ":" mi:/\d\d/ ":" s:/\d\d/) {
50
50
  [:y,:m,:d,:h,:mi,:s].map{ |s| capture(s).value }
51
51
  }
@@ -55,6 +55,12 @@ grammar TOML::Primitive
55
55
  offset:(sign /\d\d/ ":" /\d\d/)
56
56
  end
57
57
 
58
+ rule date_skeleton
59
+ (y:/\d\d\d\d/ "-" m:/\d\d/ "-" d:/\d\d/) {
60
+ [:y,:m,:d].map{ |s| capture(s).value } + [0, 0, 0]
61
+ }
62
+ end
63
+
58
64
  ##
59
65
  # Number rules
60
66
  ##
@@ -34,7 +34,7 @@ module TOML
34
34
  # Used in document.citrus
35
35
  module KeygroupParser
36
36
  def value
37
- TOML::Keygroup.new(captures[:key].map(&:value))
37
+ TOML::Keygroup.new(captures[:stripped_key].map(&:value))
38
38
  end
39
39
  end
40
40
  end
@@ -43,7 +43,7 @@ module TOML
43
43
  # Used in document.citrus
44
44
  module KeyvalueParser
45
45
  def value
46
- TOML::Keyvalue.new(capture(:key).value, capture(:v).value)
46
+ TOML::Keyvalue.new(capture(:stripped_key).value, capture(:v).value)
47
47
  end
48
48
  end
49
49
  end
@@ -39,7 +39,7 @@ module TOML
39
39
  # Used in document.citrus
40
40
  module TableArrayParser
41
41
  def value
42
- TOML::TableArray.new(captures[:key].map(&:value))
42
+ TOML::TableArray.new(captures[:stripped_key].map(&:value))
43
43
  end
44
44
  end
45
45
  end
@@ -34,8 +34,12 @@ class GrammarTest < Minitest::Test
34
34
  assert_equal(['first key', 'second key'],
35
35
  match.value.instance_variable_get('@nested_keys'))
36
36
 
37
+ match = TOML::Document.parse('[ owner . emancu ]', root: :keygroup)
38
+ assert_equal(%w(owner emancu),
39
+ match.value.instance_variable_get('@nested_keys'))
40
+
37
41
  assert_raises Citrus::ParseError do
38
- TOML::Document.parse('[ owner . emancu ]', root: :keygroup)
42
+ TOML::Document.parse('[ owner emancu ]', root: :keygroup)
39
43
  end
40
44
  end
41
45
 
@@ -189,6 +193,8 @@ class GrammarTest < Minitest::Test
189
193
  assert_equal([1, 3], match.value)
190
194
  end
191
195
 
196
+ # Dates are really hard to test from JSON, due the imposibility to represent
197
+ # datetimes without quotes.
192
198
  def test_datetime
193
199
  match = TOML::Document.parse('1986-08-28T15:15:00Z', root: :datetime)
194
200
  assert_equal(Time.utc(1986, 8, 28, 15, 15), match.value)
@@ -198,6 +204,15 @@ class GrammarTest < Minitest::Test
198
204
 
199
205
  match = TOML::Document.parse('1986-08-28T15:15:00.123-03:00', root: :datetime)
200
206
  assert_equal(Time.utc(1986, 8, 28, 18, 15, 0.123), match.value)
207
+
208
+ match = TOML::Document.parse('1986-08-28', root: :datetime)
209
+ assert_equal(Time.utc(1986, 8, 28, 0, 0, 0), match.value)
210
+
211
+ match = TOML::Document.parse('1986-08-28T15:15:00', root: :datetime)
212
+ assert_equal(Time.utc(1986, 8, 28, 15, 15), match.value)
213
+
214
+ match = TOML::Document.parse('1986-08-28T15:15:00.999999', root: :datetime)
215
+ assert_equal(Time.utc(1986, 8, 28, 15, 15, 0.999999), match.value)
201
216
  end
202
217
 
203
218
  def test_inline_table
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'toml-rb'
3
- s.version = '0.3.10'
3
+ s.version = '0.3.11'
4
4
  s.date = Time.now.strftime('%Y-%m-%d')
5
5
  s.summary = 'TOML parser in ruby, for ruby.'
6
6
  s.description = 'A TOML parser using Citrus parsing library. '
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: toml-rb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.10
4
+ version: 0.3.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Emiliano Mancuso
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2016-02-23 00:00:00.000000000 Z
12
+ date: 2016-03-08 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: citrus