toml 0.2.0 → 0.3.0

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
- SHA1:
3
- metadata.gz: 21fdb895a9bab72e0d83617219b906ad14e56f58
4
- data.tar.gz: 0cfdac6172ef69b7c1d217109d416457ff6360a6
2
+ SHA256:
3
+ metadata.gz: 6fe891b78d0c8ef3788c8abe359d4350bc1a1a9774d2576c94b8840160acee62
4
+ data.tar.gz: 948287584ed396f0f07bdaf358f4263f25528a5de4ccb3b8cfecabc1514936fb
5
5
  SHA512:
6
- metadata.gz: 37c9a523b090f8afb92d050397ffe0e22ce342f90a30ae72d6e62c033907b1496cd9859252ce70079440b880b4e01849f0ea9aa9fb1dba624cb883f0ae0da0f9
7
- data.tar.gz: 38835f89d190d8b7b018739602a96cccc2c8e41b9ce8aa268b8899e9cf56716403c10c7265134e836b56cc5704ebefef13e61dc31b624f19ad0b4b30aa86d836
6
+ metadata.gz: 867a7f6183e52213106e50d68e8e2e1262b87875a6cbe20e43637803011d3796bc77ad50e5e6c64e778cd84ebb833fad474f39ac8abc605e1a436e41aff24edd
7
+ data.tar.gz: efd7be04b02c6487ce8a1bc686e8943f426ceb8054852eebb944ba655bcab152b299dd6a189f73d5671df16446cdeeb11d0bea2fe51171aad661c392efbfb4bb
data/CHANGELOG.md CHANGED
@@ -1,3 +1,13 @@
1
+ ## 0.3.0 / 2020-06-09
2
+
3
+ - Fix "undefined method `ascii_tree' for nil:NilClass" when printing parse error
4
+ - Fixes TOML to work with version 2.0 of Parslet
5
+
6
+ ## 0.2.0 / 2017-11-11
7
+
8
+ - Add support for underscored Integers and Floats
9
+ - Fixes TOML to work with version 1.8.0 of Parslet
10
+
1
11
  ## 0.1.2 / 2014-10-16
2
12
 
3
13
  - Add support for `CR` and `CRLF` newlines (#13)
data/README.md CHANGED
@@ -1,17 +1,25 @@
1
1
  # TOML
2
2
 
3
- A sane configuration format from @mojombo. More information here: https://github.com/mojombo/toml
3
+ A Ruby parser for [TOML](https://github.com/mojombo/toml), built on [parslet](https://github.com/kschiess/parslet).
4
4
 
5
5
  This is far superior to YAML and JSON because it doesn't suck. Really it doesn't.
6
6
 
7
- **There is a bug in Rails 2.3's vendored version of BlankSlate (a dependency of Parslet which is used for parsing TOML) that breaks Parslet; please see this [Gist](https://gist.github.com/dirk/5264004) for a workaround.**
7
+ <<<<<<< HEAD
8
+ =======
9
+ [![Gem Version](https://badge.fury.io/rb/toml.svg)](http://badge.fury.io/rb/toml)
8
10
 
11
+ >>>>>>> Update README
9
12
  ## Usage
10
13
 
11
- Add to your Gemfile:
14
+ Install this library:
12
15
 
16
+ <<<<<<< HEAD
13
17
  ```ruby
14
- gem "toml", "~> 0.0.3"
18
+ gem "toml", "~> 0.3.0"
19
+ =======
20
+ ```bash
21
+ gem install "toml"
22
+ >>>>>>> Update README
15
23
  ```
16
24
 
17
25
  It's simple, really.
@@ -40,6 +48,8 @@ TOML.load_file("my_file.toml")
40
48
  # => {"whatever" => "keys"}
41
49
  ```
42
50
 
51
+ In case a syntax error occurs, the parser will raise a `Parslet::ParseFailed` exception.
52
+
43
53
  There's also a beta feature for generating a TOML file from a Ruby hash. Please note this will likely not give beautiful output right now.
44
54
 
45
55
  ```ruby
@@ -82,6 +82,6 @@ class Numeric
82
82
  end
83
83
  class DateTime
84
84
  def to_toml(path = "")
85
- self.to_time.utc.strftime("%Y-%m-%dT%H:%M:%SZ")
85
+ self.rfc3339
86
86
  end
87
87
  end
data/lib/toml/parser.rb CHANGED
@@ -6,13 +6,8 @@ module TOML
6
6
  # Make sure we have a newline on the end
7
7
 
8
8
  markup += "\n" unless markup.end_with?("\n") || markup.length == 0
9
- begin
10
- tree = Parslet.new.parse(markup)
11
- rescue Parslet::ParseFailed => failure
12
- puts failure.cause.ascii_tree
13
- end
14
-
15
-
9
+ tree = Parslet.new.parse(markup)
10
+
16
11
  parts = Transformer.new.apply(tree) || []
17
12
  @parsed = {}
18
13
  @current = @parsed
data/lib/toml/parslet.rb CHANGED
@@ -2,7 +2,7 @@ module TOML
2
2
  class Parslet < ::Parslet::Parser
3
3
  rule(:document) {
4
4
  all_space >>
5
- (table | table_array | key_value | comment_line).repeat >>
5
+ (comment_line | table | table_array | key_value).repeat >>
6
6
  all_space
7
7
  }
8
8
  root :document
@@ -11,15 +11,16 @@ module TOML
11
11
  array |
12
12
  string |
13
13
  datetime.as(:datetime) |
14
+ datetime_rfc3339.as(:datetime_rfc3339) |
14
15
  float.as(:float) |
15
16
  integer.as(:integer) |
16
17
  boolean
17
18
  }
18
-
19
+
19
20
  # Finding comments in multiline arrays requires accepting a bunch of
20
21
  # possible newlines and stuff before the comment
21
22
  rule(:array_comments) { (all_space >> comment_line).repeat }
22
-
23
+
23
24
  rule(:array) {
24
25
  str("[") >> all_space >> array_comments >>
25
26
  ( array_comments >> # Match any comments on first line
@@ -32,10 +33,10 @@ module TOML
32
33
  ).repeat >>
33
34
  (all_space >> str(",")).maybe >> # possible trailing comma
34
35
  all_space >> array_comments # Grab any remaining comments just in case
35
- ).maybe.as(:array) >> str("]")
36
+ ).maybe.as(:array) >> str("]")
36
37
  }
37
-
38
- rule(:key_value) {
38
+
39
+ rule(:key_value) {
39
40
  space >> key.as(:key) >>
40
41
  space >> str("=") >>
41
42
  space >> value.as(:value) >>
@@ -53,7 +54,7 @@ module TOML
53
54
  str("]]") >>
54
55
  space >> comment.maybe >> str("\n") >> all_space
55
56
  }
56
-
57
+
57
58
  rule(:key) { match["^. \t\\]"].repeat(1) }
58
59
  rule(:table_name) { key.as(:key) >> (str(".") >> key.as(:key)).repeat }
59
60
 
@@ -63,17 +64,17 @@ module TOML
63
64
  rule(:space) { match[" \t"].repeat }
64
65
  rule(:all_space) { match[" \t\r\n"].repeat }
65
66
  rule(:newline) { str("\r").maybe >> str("\n") | str("\r") >> str("\n").maybe }
66
-
67
+
67
68
  rule(:string) {
68
69
  str('"') >> (
69
70
  match["^\"\\\\"] |
70
71
  (str("\\") >> match["0tnr\"\\\\"])
71
72
  ).repeat.as(:string) >> str('"')
72
73
  }
73
-
74
+
74
75
  rule(:sign) { str("-") }
75
76
  rule(:sign?) { sign.maybe }
76
-
77
+
77
78
  rule(:integer) {
78
79
  str("0") | sign? >>
79
80
  (match["1-9"] >> (match["_"].maybe >> match["0-9"]).repeat)
@@ -85,7 +86,7 @@ module TOML
85
86
  }
86
87
 
87
88
  rule(:boolean) { str("true").as(:true) | str("false").as(:false) }
88
-
89
+
89
90
  rule(:date) {
90
91
  match["0-9"].repeat(4,4) >> str("-") >>
91
92
  match["0-9"].repeat(2,2) >> str("-") >>
@@ -98,6 +99,16 @@ module TOML
98
99
  match["0-9"].repeat(2,2)
99
100
  }
100
101
 
102
+ rule(:timezone) {
103
+ match["0-9"].repeat(2,2) >> str(":") >>
104
+ match["0-9"].repeat(2,2)
105
+ }
106
+
101
107
  rule(:datetime) { date >> str("T") >> time >> str("Z") }
108
+
109
+ rule(:datetime_rfc3339) {
110
+ # rfc3339 section 5.6 allows replacing 'T' with a space.
111
+ date >> (str("T") | str(" ")) >> time >> (str("+") | str("-")) >> timezone
112
+ }
102
113
  end
103
- end
114
+ end
@@ -52,6 +52,7 @@ module TOML
52
52
  ""
53
53
  }
54
54
  rule(:datetime => simple(:d)) { DateTime.iso8601(d) }
55
+ rule(:datetime_rfc3339 => simple(:d)) { DateTime.rfc3339(d) }
55
56
  rule(:true => simple(:b)) { true }
56
57
  rule(:false => simple(:b)) { false }
57
58
 
data/lib/toml/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module TOML
2
- VERSION = '0.2.0'
2
+ VERSION = '0.3.0'
3
3
  end
metadata CHANGED
@@ -1,30 +1,36 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: toml
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeremy McAnally
8
8
  - Dirk Gadsden
9
- autorequire:
9
+ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2017-11-11 00:00:00.000000000 Z
12
+ date: 2021-06-01 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: parslet
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  requirements:
18
- - - "~>"
18
+ - - ">="
19
19
  - !ruby/object:Gem::Version
20
20
  version: 1.8.0
21
+ - - "<"
22
+ - !ruby/object:Gem::Version
23
+ version: 3.0.0
21
24
  type: :runtime
22
25
  prerelease: false
23
26
  version_requirements: !ruby/object:Gem::Requirement
24
27
  requirements:
25
- - - "~>"
28
+ - - ">="
26
29
  - !ruby/object:Gem::Version
27
30
  version: 1.8.0
31
+ - - "<"
32
+ - !ruby/object:Gem::Version
33
+ version: 3.0.0
28
34
  - !ruby/object:Gem::Dependency
29
35
  name: rake
30
36
  requirement: !ruby/object:Gem::Requirement
@@ -64,7 +70,7 @@ homepage: http://github.com/jm/toml
64
70
  licenses:
65
71
  - MIT
66
72
  metadata: {}
67
- post_install_message:
73
+ post_install_message:
68
74
  rdoc_options:
69
75
  - "--charset=UTF-8"
70
76
  require_paths:
@@ -80,9 +86,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
80
86
  - !ruby/object:Gem::Version
81
87
  version: '0'
82
88
  requirements: []
83
- rubyforge_project:
84
- rubygems_version: 2.5.2
85
- signing_key:
89
+ rubygems_version: 3.1.4
90
+ signing_key:
86
91
  specification_version: 2
87
92
  summary: Parse your TOML.
88
93
  test_files: []