tomlrb 2.0.4 → 3.0.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 +103 -0
- data/README.md +85 -0
- data/lib/tomlrb/local_date.rb +24 -13
- data/lib/tomlrb/local_date_time.rb +33 -20
- data/lib/tomlrb/local_time.rb +36 -16
- data/lib/tomlrb/parser.rb +789 -14
- data/lib/tomlrb/version.rb +2 -2
- data/lib/tomlrb.rb +18 -32
- data/sig/tomlrb.rbs +75 -0
- metadata +16 -26
- data/lib/tomlrb/generated_parser.rb +0 -808
- data/lib/tomlrb/handler.rb +0 -279
- data/lib/tomlrb/parser.y +0 -230
- data/lib/tomlrb/scanner.rb +0 -92
- data/lib/tomlrb/string_utils.rb +0 -40
data/lib/tomlrb/version.rb
CHANGED
data/lib/tomlrb.rb
CHANGED
|
@@ -1,49 +1,35 @@
|
|
|
1
|
-
#
|
|
1
|
+
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
require 'tomlrb/local_time'
|
|
9
|
-
require 'tomlrb/string_utils'
|
|
10
|
-
require 'tomlrb/scanner'
|
|
11
|
-
require 'tomlrb/parser'
|
|
12
|
-
require 'tomlrb/handler'
|
|
3
|
+
require_relative "tomlrb/version"
|
|
4
|
+
require_relative "tomlrb/local_date"
|
|
5
|
+
require_relative "tomlrb/local_date_time"
|
|
6
|
+
require_relative "tomlrb/local_time"
|
|
7
|
+
require_relative "tomlrb/parser"
|
|
13
8
|
|
|
14
9
|
module Tomlrb
|
|
15
10
|
class ParseError < StandardError; end
|
|
16
11
|
|
|
17
|
-
# Parses a
|
|
12
|
+
# Parses a TOML document into a Hash.
|
|
18
13
|
#
|
|
19
|
-
# @param string_or_io [String,
|
|
14
|
+
# @param string_or_io [String, #read] the document
|
|
20
15
|
# @param options [Hash] the options hash
|
|
21
16
|
# @option options [Boolean] :symbolize_keys (false) whether to return the keys as symbols or strings
|
|
17
|
+
# @option options ["1.1", "1.0"] :version ("1.1") the TOML spec to follow. A valid 1.0 document parses the
|
|
18
|
+
# same under 1.1; "1.0" also rejects what 1.1 added (`\e`, `\xHH`, times without seconds, multi-line
|
|
19
|
+
# inline tables), for when another consumer of the file only reads 1.0
|
|
22
20
|
# @return [Hash] the Ruby data structure represented by the input
|
|
21
|
+
# @raise [ParseError] on invalid TOML
|
|
23
22
|
def self.parse(string_or_io, **options)
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
parser = Parser.new(scanner, **options)
|
|
27
|
-
begin
|
|
28
|
-
handler = parser.parse
|
|
29
|
-
rescue Racc::ParseError => e
|
|
30
|
-
raise ParseError, e.message
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
handler.output
|
|
23
|
+
src = string_or_io.is_a?(String) ? string_or_io : string_or_io.read
|
|
24
|
+
Parser.new(src, **options).parse
|
|
34
25
|
end
|
|
35
26
|
|
|
36
|
-
# Reads a file
|
|
27
|
+
# Reads a UTF-8 file and parses it; see {.parse} for the options.
|
|
37
28
|
#
|
|
38
|
-
# @param path [String] the path to the file
|
|
39
|
-
# @param options [Hash] the options hash
|
|
40
|
-
# @option options [Boolean] :symbolize_keys (false) whether to return the keys as symbols or strings
|
|
29
|
+
# @param path [String, Pathname] the path to the file
|
|
41
30
|
# @return [Hash] the Ruby data structure represented by the input
|
|
42
31
|
def self.load_file(path, **options)
|
|
43
|
-
#
|
|
44
|
-
|
|
45
|
-
# locale encoding or the interpreter -E option.
|
|
46
|
-
tmp = File.read(path, encoding: 'utf-8')
|
|
47
|
-
Tomlrb.parse(tmp, **options)
|
|
32
|
+
# Read as UTF-8 whatever the default external encoding (locale, -E) is.
|
|
33
|
+
parse(File.read(path, encoding: "utf-8"), **options)
|
|
48
34
|
end
|
|
49
35
|
end
|
data/sig/tomlrb.rbs
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
module Tomlrb
|
|
2
|
+
VERSION: String
|
|
3
|
+
|
|
4
|
+
class ParseError < StandardError
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
# TOML spec to follow; "1.0" also rejects what 1.1 added.
|
|
8
|
+
type version = "1.1" | "1.0"
|
|
9
|
+
|
|
10
|
+
type key = String | Symbol
|
|
11
|
+
type table = Hash[key, value]
|
|
12
|
+
type value = String | Integer | Float | bool | Time | LocalDate | LocalDateTime | LocalTime | Array[value] | table
|
|
13
|
+
|
|
14
|
+
interface _Reader
|
|
15
|
+
def read: () -> String
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
# Parses a TOML document (TOML 1.1 unless `version: "1.0"`). Keys are Strings, or Symbols with `symbolize_keys: true`.
|
|
19
|
+
def self.parse: (String | _Reader string_or_io, ?symbolize_keys: boolish, ?version: version) -> table
|
|
20
|
+
|
|
21
|
+
# Reads a UTF-8 file and parses it.
|
|
22
|
+
def self.load_file: (path path, ?symbolize_keys: boolish, ?version: version) -> table
|
|
23
|
+
|
|
24
|
+
class Parser
|
|
25
|
+
def initialize: (String src, ?symbolize_keys: boolish, ?version: version) -> void
|
|
26
|
+
def parse: () -> table
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
class LocalDate
|
|
30
|
+
def self.valid_date?: (Integer year, Integer month, Integer day) -> bool
|
|
31
|
+
|
|
32
|
+
attr_reader year: Integer
|
|
33
|
+
attr_reader month: Integer
|
|
34
|
+
attr_reader day: Integer
|
|
35
|
+
|
|
36
|
+
def initialize: (int | String year, int | String month, int | String day) -> void
|
|
37
|
+
def to_time: (?String | Integer | nil offset) -> Time
|
|
38
|
+
def to_s: () -> String
|
|
39
|
+
def ==: (untyped other) -> bool
|
|
40
|
+
def inspect: () -> String
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
class LocalDateTime
|
|
44
|
+
def initialize: (int | String year, int | String month, int | String day,
|
|
45
|
+
int | String hour, int | String min, Numeric sec) -> void
|
|
46
|
+
def year: () -> Integer
|
|
47
|
+
def month: () -> Integer
|
|
48
|
+
def day: () -> Integer
|
|
49
|
+
def hour: () -> Integer
|
|
50
|
+
def min: () -> Integer
|
|
51
|
+
def sec: () -> Integer
|
|
52
|
+
def usec: () -> Integer
|
|
53
|
+
def nsec: () -> Integer
|
|
54
|
+
def to_time: (?String | Integer | nil offset) -> Time
|
|
55
|
+
def to_s: () -> String
|
|
56
|
+
def ==: (untyped other) -> bool
|
|
57
|
+
def inspect: () -> String
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
class LocalTime
|
|
61
|
+
# `hh:mm:ss`, plus `.` and the fraction digits if `sec` has any.
|
|
62
|
+
def self.format: (Integer hour, Integer min, Numeric sec) -> String
|
|
63
|
+
|
|
64
|
+
def initialize: (int | String hour, int | String min, Numeric sec) -> void
|
|
65
|
+
def hour: () -> Integer
|
|
66
|
+
def min: () -> Integer
|
|
67
|
+
def sec: () -> Integer
|
|
68
|
+
def usec: () -> Integer
|
|
69
|
+
def nsec: () -> Integer
|
|
70
|
+
def to_time: (int year, int month, int day, ?String | Integer | nil offset) -> Time
|
|
71
|
+
def to_s: () -> String
|
|
72
|
+
def ==: (untyped other) -> bool
|
|
73
|
+
def inspect: () -> String
|
|
74
|
+
end
|
|
75
|
+
end
|
metadata
CHANGED
|
@@ -1,51 +1,41 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: tomlrb
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version:
|
|
4
|
+
version: 3.0.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Francois Bernier
|
|
8
8
|
bindir: bin
|
|
9
9
|
cert_chain: []
|
|
10
10
|
date: 1980-01-02 00:00:00.000000000 Z
|
|
11
|
-
dependencies:
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
requirement: !ruby/object:Gem::Requirement
|
|
15
|
-
requirements:
|
|
16
|
-
- - "~>"
|
|
17
|
-
- !ruby/object:Gem::Version
|
|
18
|
-
version: '4'
|
|
19
|
-
type: :development
|
|
20
|
-
prerelease: false
|
|
21
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
22
|
-
requirements:
|
|
23
|
-
- - "~>"
|
|
24
|
-
- !ruby/object:Gem::Version
|
|
25
|
-
version: '4'
|
|
26
|
-
description: A racc based toml parser
|
|
11
|
+
dependencies: []
|
|
12
|
+
description: Parses TOML 1.1 and 1.0 documents into Ruby Hashes. Pure Ruby, no runtime
|
|
13
|
+
dependencies, checked against the official toml-test suite.
|
|
27
14
|
email:
|
|
28
15
|
- frankbernier@gmail.com
|
|
29
16
|
executables: []
|
|
30
17
|
extensions: []
|
|
31
18
|
extra_rdoc_files: []
|
|
32
19
|
files:
|
|
20
|
+
- CHANGELOG.md
|
|
33
21
|
- LICENSE.txt
|
|
22
|
+
- README.md
|
|
34
23
|
- lib/tomlrb.rb
|
|
35
|
-
- lib/tomlrb/generated_parser.rb
|
|
36
|
-
- lib/tomlrb/handler.rb
|
|
37
24
|
- lib/tomlrb/local_date.rb
|
|
38
25
|
- lib/tomlrb/local_date_time.rb
|
|
39
26
|
- lib/tomlrb/local_time.rb
|
|
40
27
|
- lib/tomlrb/parser.rb
|
|
41
|
-
- lib/tomlrb/parser.y
|
|
42
|
-
- lib/tomlrb/scanner.rb
|
|
43
|
-
- lib/tomlrb/string_utils.rb
|
|
44
28
|
- lib/tomlrb/version.rb
|
|
29
|
+
- sig/tomlrb.rbs
|
|
45
30
|
homepage: https://github.com/fbernier/tomlrb
|
|
46
31
|
licenses:
|
|
47
32
|
- MIT
|
|
48
|
-
metadata:
|
|
33
|
+
metadata:
|
|
34
|
+
source_code_uri: https://github.com/fbernier/tomlrb
|
|
35
|
+
changelog_uri: https://github.com/fbernier/tomlrb/blob/master/CHANGELOG.md
|
|
36
|
+
bug_tracker_uri: https://github.com/fbernier/tomlrb/issues
|
|
37
|
+
documentation_uri: https://rubydoc.info/gems/tomlrb
|
|
38
|
+
rubygems_mfa_required: 'true'
|
|
49
39
|
rdoc_options: []
|
|
50
40
|
require_paths:
|
|
51
41
|
- lib
|
|
@@ -53,14 +43,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
53
43
|
requirements:
|
|
54
44
|
- - ">="
|
|
55
45
|
- !ruby/object:Gem::Version
|
|
56
|
-
version: '
|
|
46
|
+
version: '3.3'
|
|
57
47
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
58
48
|
requirements:
|
|
59
49
|
- - ">="
|
|
60
50
|
- !ruby/object:Gem::Version
|
|
61
51
|
version: '0'
|
|
62
52
|
requirements: []
|
|
63
|
-
rubygems_version:
|
|
53
|
+
rubygems_version: 4.0.20
|
|
64
54
|
specification_version: 4
|
|
65
|
-
summary: A
|
|
55
|
+
summary: A fast, pure-Ruby TOML 1.1 and 1.0 parser
|
|
66
56
|
test_files: []
|