toml_empty 0.1.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +1 -0
- data/README.md +24 -4
- data/lib/toml/monkey_patch.rb +1 -1
- data/lib/toml/parser.rb +2 -7
- data/lib/toml/parslet.rb +23 -12
- data/lib/toml/transformer.rb +1 -0
- data/lib/toml/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 19bc2aa9b433f24bf3993b405f6dddf4376bca85b9b15273760c2a887670fce2
|
4
|
+
data.tar.gz: 675533c77eed0f2e39e5135d7fb298ed838eae6ac2d6ed55dbbdf4417af5bd60
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 506c2602a4ac496c0862402158a6b6611c96871b1068ae8052346c500a62a3b7c3722cddbcff4e904fb69abffe5ad16aa69b8e231986144f1b0f3608d1f71832
|
7
|
+
data.tar.gz: b3364307323970f6f3cbbdd3fedabe99a3c8dbe9fb308cd854f5e2679c218d2d7ea1efc8ec410782c55ea8bc89808a3fc50f87a824c49e5ead5c23ecf839ea3b
|
data/CHANGELOG.md
CHANGED
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
|
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
|
+
[](http://badge.fury.io/rb/toml)
|
24
|
+
|
7
25
|
## Usage
|
8
26
|
|
9
|
-
|
27
|
+
Install this library:
|
10
28
|
|
11
29
|
```ruby
|
12
|
-
gem "
|
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)).
|
data/lib/toml/monkey_patch.rb
CHANGED
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
|
-
|
10
|
-
|
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
|
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
|
data/lib/toml/transformer.rb
CHANGED
data/lib/toml/version.rb
CHANGED
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.
|
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:
|
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.
|
90
|
+
rubygems_version: 3.3.7
|
91
91
|
signing_key:
|
92
92
|
specification_version: 2
|
93
93
|
summary: Parse your TOML (allow empty group).
|