toml_empty 0.1.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
2
  SHA256:
3
- metadata.gz: 18f7758393bd1544a64b10d28ab7a83340f07c14d90a2e6177b362abd43debea
4
- data.tar.gz: 89879113263d7ecd003a6f0b950dcfe1657d45a5296532a711ff82285c249e37
3
+ metadata.gz: 19bc2aa9b433f24bf3993b405f6dddf4376bca85b9b15273760c2a887670fce2
4
+ data.tar.gz: 675533c77eed0f2e39e5135d7fb298ed838eae6ac2d6ed55dbbdf4417af5bd60
5
5
  SHA512:
6
- metadata.gz: 45613e3e99d0123782583bdcf4fe98e010353e52b33519da766a9bb5e9ee9e41ccb9dac5ff492467fb4c28f5a22b71e37c6180c3bcf905e2e6d554f9c39a3a9a
7
- data.tar.gz: fbbb621d8725790a55aad4da7b355c301fd0f0869ffa77b20d05dd6b56dbe48eeb7c527117933347f23d11c314098f2b609d483e8e2dcaefc31ce179ae221740
6
+ metadata.gz: 506c2602a4ac496c0862402158a6b6611c96871b1068ae8052346c500a62a3b7c3722cddbcff4e904fb69abffe5ad16aa69b8e231986144f1b0f3608d1f71832
7
+ data.tar.gz: b3364307323970f6f3cbbdd3fedabe99a3c8dbe9fb308cd854f5e2679c218d2d7ea1efc8ec410782c55ea8bc89808a3fc50f87a824c49e5ead5c23ecf839ea3b
data/CHANGELOG.md CHANGED
@@ -1,5 +1,6 @@
1
1
  ## 0.3.0 / 2020-06-09
2
2
 
3
+ - Fix "undefined method `ascii_tree' for nil:NilClass" when printing parse error
3
4
  - Fixes TOML to work with version 2.0 of Parslet
4
5
 
5
6
  ## 0.2.0 / 2017-11-11
data/README.md CHANGED
@@ -1,15 +1,33 @@
1
+ # Fork
2
+
3
+ This repo is a fork of toml.
4
+
5
+ The main modification is that it allows empty group to be generated (in toml gem, they are read, but not saved)
6
+
7
+ If you have a group with no value like this:
8
+ ```toml
9
+ [group.with.no.value]
10
+
11
+ [otherkey]
12
+ key = value
13
+ ```
14
+
15
+ It will be managed correctly (load and save)
16
+
1
17
  # TOML
2
18
 
3
- A sane configuration format from @mojombo. More information here: https://github.com/mojombo/toml
19
+ A Ruby parser for [TOML](https://github.com/mojombo/toml), built on [parslet](https://github.com/kschiess/parslet).
4
20
 
5
21
  This is far superior to YAML and JSON because it doesn't suck. Really it doesn't.
6
22
 
23
+ [![Gem Version](https://badge.fury.io/rb/toml.svg)](http://badge.fury.io/rb/toml)
24
+
7
25
  ## Usage
8
26
 
9
- Add to your Gemfile:
27
+ Install this library:
10
28
 
11
29
  ```ruby
12
- gem "toml", "~> 0.3.0"
30
+ gem "toml_empty", "~> 0.3.0"
13
31
  ```
14
32
 
15
33
  It's simple, really.
@@ -38,6 +56,8 @@ TOML.load_file("my_file.toml")
38
56
  # => {"whatever" => "keys"}
39
57
  ```
40
58
 
59
+ In case a syntax error occurs, the parser will raise a `Parslet::ParseFailed` exception.
60
+
41
61
  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.
42
62
 
43
63
  ```ruby
@@ -60,4 +80,4 @@ doc = TOML::Generator.new(hash).body
60
80
 
61
81
  ## Contributors
62
82
 
63
- Written by Jeremy McAnally (@jm) and Dirk Gadsden (@dirk) based on TOML from Tom Preston-Werner (@mojombo).
83
+ Written by Jeremy McAnally ([@jm](https://github.com/jm)) and Dirk Gadsden ([@dirk](https://github.com/dirk)) based on TOML from Tom Preston-Werner ([@mojombo](https://github.com/mojombo)).
@@ -84,6 +84,6 @@ class Numeric
84
84
  end
85
85
  class DateTime
86
86
  def to_toml(path = "")
87
- self.to_time.utc.strftime("%Y-%m-%dT%H:%M:%SZ")
87
+ self.rfc3339
88
88
  end
89
89
  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.1.0'
2
+ VERSION = '0.3.0'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: toml_empty
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeremy McAnally
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2021-05-13 00:00:00.000000000 Z
13
+ date: 2022-11-27 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: parslet
@@ -87,7 +87,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
87
87
  - !ruby/object:Gem::Version
88
88
  version: '0'
89
89
  requirements: []
90
- rubygems_version: 3.1.6
90
+ rubygems_version: 3.3.7
91
91
  signing_key:
92
92
  specification_version: 2
93
93
  summary: Parse your TOML (allow empty group).