Recent Releases of https://github.com/emancu/toml-rb
https://github.com/emancu/toml-rb - v6.0.0: pure Ruby, no dependencies
toml-rb 6.0.0 is pure Ruby, and it has no runtime dependencies π
A new parser on the StringScanner class of the Ruby standard library replaces the Citrus grammar. gem install toml-rb now installs one gem, and require "toml-rb" loads only toml-rb.
60 to 90 times faster π
| Document | 5.0.0 | 6.0.0 | Speedup |
|---|---|---|---|
example.toml (0.8 KB) |
4.5 ms | 67.2 Β΅s | 67Γ |
| Lock file (100 KB) | 506.9 ms | 5.9 ms | 86Γ |
| Lock file (1 MB) | 5.43 s | 60.5 ms | 90Γ |
These numbers are the CPU time for one TomlRB.parse call on Ruby 3.4.1 (Apple M3 Pro). With YJIT, the 1 MB file parses 199 times faster than on 5.0.0.
TomlRB.dump is faster too. A 3.3 MB lock file dumps 45 times faster than before.
benchmark/README.md has all the results, with Ruby 4.0.7, YJIT, ZJIT, tomlrb, perfect_toml and tomlib.
The same results
- The new parser gives the same data as 5.0.0 on 9,257 real-world TOML files: Cargo, uv, Poetry, Hugo, Julia and more. Only the local datetimes change (see below).
- toml-rb still passes all toml-test v2.2.0 decoder tests for TOML 1.1.0.
- CI runs on MRI 2.5 to 4.0, JRuby and TruffleRuby.
Better error messages
A syntax error now gives the line, the column and the expected text:
Unexpected "e" at line 1, column 9: expected ']'
Before you upgrade
- Code that matches the old error message text must change.
TomlRB::LocalDateTimeandTomlRB::LocalDateare now UTCTimevalues, likeTomlRB::LocalTime. Their clock time matches the TOML text in every time zone, also inside a daylight saving time gap. Compare them withTime.utc, notTime.local.- More than 100 nested levels of arrays and inline tables raise
TomlRB::ParseError. - This release removes the Citrus grammar constants, like
TomlRB::Document.
CHANGELOG.md lists every change.
Full Changelog: https://github.com/emancu/toml-rb/compare/v5.0.0...v6.0.0
- Ruby
Published by emancu about 2 months ago
https://github.com/emancu/toml-rb - v5.0.0
Breaking changes
parsereturnsTomlRB::LocalDateTime,TomlRB::LocalDateand
TomlRB::LocalTimefor local values. Each is aTimesubclass:is_a?(Time)
stays true andinstance_of?(Time)is false. Offset datetimes stayTime.
UseTime.at(value)for a plainTime. (#183)- A local time is a UTC
Timeon 1970-01-01, at the same instant as in v4.
hour,minandsecmatch the TOML text in all zones.to_s,zoneand
utc?can change. (#183) dumpwrites local values without offsets:1979-05-27,07:32:00or
1979-05-27T07:32:00. Before, it wrote datetimes withZ. (#183)dumpwrites the UTC offset of aTimeorDateTimeand up to 9 fractional
digits, with no final zeros. Before, it wrote the clock time withZand no
fraction. (#183, #193)parsekeeps exact fractions:.123givesnsec123000000. ATimebuilt
from Float seconds is not equal, and dumps with the Float error. Build the
Timefrom a Rational. (#193)- Leading zeros, out-of-range dates, times and offsets, comma fractions,
[,]
and two statements per line raiseTomlRB::ParseError. (#196, #199) a=[12:00:00,5]now has two elements: a local time and an integer. (#199)- Duplicate tables or tables that headers and dotted keys both extend now raise
TomlRB::ValueOverwriteError(toml-lang/toml#859). Some parsed before. (#197) - Invalid input raises
TomlRB::Erroror a subclass instead ofNoMethodError,
TypeErrororArgumentError. Userescue TomlRB::Error. (#197, #199, #202) - Some valid multi-line strings change value to match the spec. Indentation
and blank lines after the first newline stay. Multi-line literal strings keep
backslashes at line ends.\\before a newline escapes a backslash. (#203) - The escape
\0, invalid\uand\Ucode points, and more than two quotes
before a multi-line end delimiter raiseTomlRB::ParseError. (#203) - Control characters in strings and comments raise
TomlRB::ParseError. Tabs
stay valid. Multi-line strings accept LF and CRLF newlines. (#204) dumpraisesTomlRB::Errorfornil, Rational, Complex, Set, Struct, other
objects and non-finite BigDecimal. Before, it wrote Rubyinspectoutput.
Removenilvalues beforedump. (#202)symbolize_keys: truealso applies to inline tables inside arrays:
a = [{b = 1}]gives{a: [{b: 1}]}. Before,bstayed a String key.
parsecan raise a different error for a document with many errors. (#209)
TOML 1.1.0
- Basic strings accept
\efor ESC.dumpstill writes\u001B. (#181) - Basic strings accept
\xHHcode points, not bytes ("\xff"is"ΓΏ"). (#182) - Seconds are optional in times and datetimes. (#184)
- Fractions can exceed 6 digits. toml-rb keeps 9 and truncates the rest. (#193)
- toml-rb passes all toml-test v2.2.0 decoder tests for TOML 1.1.0. (#180)
Fixes
["a.b"]and[a.b]define separate tables. (#197)- Inline tables accept shared dotted key prefixes. (#197)
- Datetimes accept lowercase
tandz. (#199) - Spaces and tabs alone give
{}. Arrays accept comments before commas. (#196) - Multi-line basic strings accept spaces and tabs after a final backslash.
Escaped quotes do not close these strings. (#203) dumpaccepts a hash with String and Symbol keys. Two keys with the same
string form, like"a"and:a, raiseTomlRB::Error. (#202)dumpwrites Symbol values as strings and Regexp with string escapes. (#202)dumpuses inline tables for hashes in mixed or nested arrays. (#202)load_filereads files as UTF-8, also underLANG=C. (#207)- The gem no longer depends on racc. (#205)
Known limitations
- In the system time zone, a DST gap moves local datetimes later, as in v4.
- A YAML round trip or ActiveSupport
changeandadvanceturn a local value
into a plainTime, sodumpwrites an offset datetime. dumptruncates UTC offsets with seconds to whole minutes.- toml-rb always accepts TOML 1.1.0 syntax. No option selects TOML 1.0.0, so 9
toml-test 1.0.0 tests that expect an error do not pass. - Deep arrays or inline tables raise
SystemStackError, notTomlRB::Error.
- Ruby
Published by emancu about 2 months ago
https://github.com/emancu/toml-rb - v5.0.0.rc.1
Breaking changes
TomlRB.parsereturnsTomlRB::LocalDateTime,TomlRB::LocalDateand
TomlRB::LocalTimefor local datetimes, local dates and local times. Each
class is a subclass ofTime. Offset datetimes stayTime. For a local
value,instance_of?(Time)and.class == Timeare false, but
is_a?(Time)andwhen Timematch. UseTime.at(value)to get a plain
Time, becausevalue.to_timereturnsvalue. (#183)- A local time is a UTC
Timeon 1970-01-01, at the same instant as before.
Itshour,minandsecnow match the TOML text in every system time
zone.to_s,zone,utc?,to_date,wdayandydaycan return other
values. (#183) TomlRB.dumpwrites the UTC offset and the fractional seconds of aTimeor
aDateTime, with up to 9 digits. Before, it wrote the clock time of the
value with aZsuffix and no fraction. For example,
TomlRB.dump(t: Time.now)now writes the offset of the system time zone
and up to 9 fractional digits. The dumper removes zeros at the end of the
fraction, soTime.at(0, 123456780, :nanosecond).utcdumps as
1970-01-01T00:00:00.12345678Z. (#183, #193)- A
Timebuilt from Float seconds dumps with the binary error of the Float:
Time.utc(1979, 5, 27, 7, 32, 0.999999)dumps as
1979-05-27T07:32:00.999998999Z. Build theTimefrom a Rational to get
exact digits. (#193) TomlRB.dumpwrites aTomlRB::LocalDateTimewithout an offset, a
TomlRB::LocalDateasYYYY-MM-DD, and aTomlRB::LocalTimeas
HH:MM:SS, with a fraction when the value has one. Before, each local value
dumped as an offset datetime with aZsuffix. (#183)- Offset datetimes keep exact fractional seconds:
.123givesnsec
123000000, not 122999999. So a parsed value is not equal to aTimebuilt
from Float seconds. Build the expectedTimefrom a Rational, for example
Rational(123, 1000). (#193) - These documents raise
TomlRB::ParseError(#199):- Integers and floats with leading zeros, like
0123and00.5. Before,
they parsed as123and0.5. - Dates, times and offsets out of range, like
2025-02-30,25:00:00,
07:32:61and+24:00. Before, some values became a later date or time
(2025-02-30became 2025-03-02), and others raisedArgumentError. - A comma before the fractional seconds, like
07:32:00,5.
- Integers and floats with leading zeros, like
a=[12:00:00,5]is now an array of the local time12:00:00and the
integer5. Before, it was an array of one time with the fraction.5.
The document parses in both versions, so no error shows the change. (#199)- Two statements on one line raise
TomlRB::ParseError, likea=1 b=2and
[a] b=2. An array with a comma and no element,[,], also raises it.
Before, these documents parsed. (#196) - These invalid documents parsed before, and now raise
TomlRB::ValueOverwriteError(#197):"[ab]\n[[a]]\n[ab]""x = false\n[[x]]""a = []\n[[a]]""[a.b]\n[a]\nb = {c = 1}"- A header inside an inline table or a static array, like
"a = {b = 1}\n[a.c]". - A header for a table that dotted keys made, like
"a.b = 1\n[a]"and
"[fruit]\napple.color = \"red\"\n[fruit.apple]"(toml-lang/toml#859). - Dotted keys that extend a table that a header defined, like
"[a.b]\n[a]\nb.c=1"(toml-lang/toml#859).
- These invalid documents raise
TomlRB::ValueOverwriteErrorinstead of
another error.rescue TomlRB::ErrorcatchesTomlRB::ValueOverwriteError
andTomlRB::ParseError. (#197)"a = true\n[[a]]": wasNoMethodError."a = 1\n[[a.b]]"and"a = 1\na.b = {}": wasTypeError."inline-t = {nest = {}}\n[[inline-t.nest]]": wasTomlRB::ParseError.
- Some valid multi-line strings change value. The new value is the value that
the spec requires (#203):- Indentation and blank lines after the opening newline stay.
- In a multi-line literal string, a backslash at the end of a line stays.
\\before a newline is an escaped backslash, not a line-ending backslash.
- These strings raise
TomlRB::ParseError(#203):- The escape
\0, which TOML does not define. - A
\uor\Uescape that is not a Unicode scalar value:\uD800to
\uDFFF, and\U00110000and higher. - More than two quotes directly before the closing delimiter of a multi-line
string, like"""x"""""".
- The escape
- Control characters in strings and comments raise
TomlRB::ParseError:
U+0000 to U+0008, U+000A to U+001F and U+007F. Tab stays valid, and a
multi-line string can contain LF and CRLF newlines. (#204) TomlRB.dumpraisesTomlRB::Errorforniland for values without a TOML
form: Rational, Complex, Set, Struct, other objects, and BigDecimal NaN or
Infinity. Before, it wrote Rubyinspectoutput, which is not TOML. Remove
nilvalues before the dump, because TOML has no null. A finite BigDecimal
dumps as before, like0.15e1. (#202)TomlRB.dumpraisesTomlRB::Errorwhen two keys have the same string form,
like"a"and:a. Before, it raisedArgumentError. (#202)
TOML 1.1.0
- Basic and multi-line basic strings accept the
\eescape for ESC (U+001B).
The dumper still writes ESC as\u001B, which is valid TOML 1.0.0. (#181) - Basic and multi-line basic strings accept the
\xHHescape for the code
point U+00HH, not a byte:"\xff"is"ΓΏ". (#182) - Seconds are optional in times and datetimes, like
10:30and
1979-05-27T07:32Z. (#184) - Fractional seconds can have more than 6 digits. toml-rb keeps 9 digits and
truncates the rest. (#193) - Headers and dotted keys follow toml-lang/toml#859. See Breaking changes.
(#197) - toml-rb passes all toml-test v2.2.0 decoder tests for TOML 1.1.0. (#180)
Fixes
["a.b"]and[a.b]in one document are two tables. Before, they raised
TomlRB::ValueOverwriteError. (#197)a = {b.c = 1, b.d = 2}parses. (#197)- Datetimes accept a lowercase
tandz. (#199) - A document with only spaces and tabs, and no line break, returns
{}. (#196) - An array accepts a comment before a comma. (#196)
- A multi-line basic string accepts spaces and tabs between a line-ending
backslash and the newline. (#203) - An escaped quote does not close a multi-line basic string, for example in
"""a\""" b""". (#203) TomlRB.dumpaccepts a hash with String and Symbol keys. (#202)TomlRB.dumpwrites a hash inside a mixed or nested array as an inline
table:TomlRB.dump(a: [1, {b: 1}])givesa = [1, {b = 1}]. Before, it
wrote Rubyinspectoutput. For a mixed array with a hash as the first
element, like[{b: 1}, 2], it raisedNoMethodError. An array of only
hashes still dumps as an array of tables ([[a]]). (#202)TomlRB.dumpwrites a Symbol value as a string and a Regexp with the string
escapes. Before, it wrote Rubyinspectoutput. (#202)TomlRB.load_filereads the file as UTF-8. Before, it used the default
external encoding, and underLANG=Cit raisedTomlRB::ParseErrorfor
non-ASCII text. (#207)symbolize_keys: trueapplies to inline tables inside arrays. For a
document with more than one error,TomlRB.parsecan raise a different one
of them. (#209)- The gem no longer depends on racc. racc is a native extension, and toml-rb
does not load it. (#205)
Known limitations
- A local datetime inside a daylight saving time (DST) gap of the system time
zone changes to a later time. For example,2026-03-29T02:30:00in
Europe/Warsaw becomes 03:30. v4 has the same behavior. - Psych
YAML.load(YAML.dump(v), permitted_classes: [Time])and ActiveSupport
changeandadvancereturn a plainTime. SoTomlRB.dumpwrites the
result as an offset datetime. TomlRB.dumptruncates a UTC offset with seconds to whole minutes. For
example, the local mean time offset+00:19:32becomes+00:19.- The TOML 1.0.0 skip-list has 9 tests. toml-rb accepts TOML 1.1.0 syntax and
has no option to select the spec version, so it does not reject these TOML
1.0.0 documents. - Very deep arrays or inline tables raise
SystemStackError, not a
TomlRB::Error. On Ruby 3.4.1 with the default stack size, 500 nested levels
raise it.
- Ruby
Published by emancu about 2 months ago
https://github.com/emancu/toml-rb - v4.2.2
- Security: the regular expressions for strings and comments backtracked in
exponential or quadratic time. A short document could cause a denial of
service. The rules now match in linear time. See
GHSA-v667-mm43-5q7r.
(#195) - Some documents parsed wrongly and now follow the spec:
a="x\"and
a='x\'y'raiseTomlRB::ParseError,a=['C:\', 'D:\']parses, and
a='C:\' # 'gives"C:\\"and a comment. (#195)
- Ruby
Published by emancu about 2 months ago
https://github.com/emancu/toml-rb - v4.2.1
What's Changed
- Wire toml-test conformance suite (v5.0.0 prep) by @emancu in https://github.com/emancu/toml-rb/pull/166
- Dump special floats as inf/-inf/nan instead of Ruby inspect output by @gaoflow in https://github.com/emancu/toml-rb/pull/179
- Emit valid TOML escapes when dumping strings and keys by @gaoflow in https://github.com/emancu/toml-rb/pull/178
New Contributors
- @gaoflow made their first contribution in https://github.com/emancu/toml-rb/pull/179
Full Changelog: https://github.com/emancu/toml-rb/compare/v4.2.0...v4.2.1
- Ruby
Published by emancu 4 months ago
https://github.com/emancu/toml-rb - v4.2.0
What's Changed
- Bunch of updates and maintenance by @emancu in https://github.com/emancu/toml-rb/pull/162
- Fix ValueOverwriteError on quoted keys containing dots (#160) by @emancu in https://github.com/emancu/toml-rb/pull/163
- Remove Ruby warnings from encoding tests by @emancu in https://github.com/emancu/toml-rb/pull/164
- Support multi-line inline tables and trailing commas (#161) by @emancu in https://github.com/emancu/toml-rb/pull/165
Full Changelog: https://github.com/emancu/toml-rb/compare/v4.1.0...v4.2.0
- Ruby
Published by emancu 7 months ago
https://github.com/emancu/toml-rb - v4.1.0
What's Changed
- #155 First working solution to verify we are not overriding dotted keys by @emancu in https://github.com/emancu/toml-rb/pull/157
- #149 Undetected key conflict error by @emancu in https://github.com/emancu/toml-rb/pull/158
- #150 Fix encoding error by @emancu in https://github.com/emancu/toml-rb/pull/159
Full Changelog: https://github.com/emancu/toml-rb/compare/v4.0.0...v4.1.0
- Ruby
Published by emancu about 1 year ago
https://github.com/emancu/toml-rb - v4.0.0
What's Changed
- Support array with mixed types by @emancu in https://github.com/emancu/toml-rb/pull/153
- Update tests by @emancu in https://github.com/emancu/toml-rb/pull/154
Full Changelog: https://github.com/emancu/toml-rb/compare/v3.0.1...v4.0.0
- Ruby
Published by emancu over 1 year ago
https://github.com/emancu/toml-rb - v3.0.1
What's Changed
- Support empty keys by quoting them. Fixes #147 by @dreid in https://github.com/emancu/toml-rb/pull/148
New Contributors
- @dreid made their first contribution in https://github.com/emancu/toml-rb/pull/148
Full Changelog: https://github.com/emancu/toml-rb/compare/v3.0.0...v3.0.1
- Ruby
Published by emancu almost 3 years ago
https://github.com/emancu/toml-rb - v3.0.0
The reason for releasing a major version is the fix on #146; even if it's an error, it breaks the previous behaviour that worked for a really long time and I don't want to cause unexpected issues to existing users.
What's Changed
- Add Ruby 3.2 to CI pipeline by @igor-drozdov in https://github.com/emancu/toml-rb/pull/140
- Add ruby 3.3 to testing matrix by @timon in https://github.com/emancu/toml-rb/pull/145
- [147] Dump backslashed keys by @emancu in https://github.com/emancu/toml-rb/pull/146
New Contributors
- @igor-drozdov made their first contribution in https://github.com/emancu/toml-rb/pull/140
- @timon made their first contribution in https://github.com/emancu/toml-rb/pull/145
Full Changelog: https://github.com/emancu/toml-rb/compare/v2.2.0...v3.0.0
- Ruby
Published by emancu almost 3 years ago
https://github.com/emancu/toml-rb - Fix failure to parse arrays with newline before comma
Thank you @jakecoffman for https://github.com/emancu/toml-rb/pull/138
- Ruby
Published by emancu over 4 years ago
https://github.com/emancu/toml-rb - Fix Dumper when there are #$ in array elements.
There are special treatments to #$ when dumping string values, but this does not work properly for arrays.
Thanks @shanyungyang
https://github.com/emancu/toml-rb/pull/136
- Ruby
Published by emancu almost 5 years ago
https://github.com/emancu/toml-rb - Fixing errors caused by frozen-strings
Thanks to @bastelfreak and @ekohl for fixing this.
- Ruby
Published by emancu almost 5 years ago
https://github.com/emancu/toml-rb - Replace generic options hash with specific option.
In the past, we were supporting Ruby versions without named parameters and
we didn't know how many options will use for loading/parsing TOML.
Years have passed, and the interface is stable, so we are simplifying it.
This change will be useful for the adoption of Steep or defining types in Ruby 3 π
It shouldn't break to most users, but just in case it does, I released a patch version (v2.0.2) with the fix for trailing spaces, so anyone can use the fix without dealing with the incompatibility of this version may introduce.
- Ruby
Published by emancu about 5 years ago
https://github.com/emancu/toml-rb - Fix trailing whitespace at the end of the document
Thanks @rodzhers for fixing the error.
https://github.com/emancu/toml-rb/pull/128
- Ruby
Published by emancu about 5 years ago
https://github.com/emancu/toml-rb - Fix TomlRB::Dumper
Dumping '#$' produces invalid TOML as '#$'.inspect introduces a single backslash before #.
https://github.com/emancu/toml-rb/pull/124
- Ruby
Published by emancu almost 7 years ago
https://github.com/emancu/toml-rb - TOML 0.5 support
I'm increasing the Major version number because it contains a breaking change explained here
Big news are we fully support TOML 0.5 + some fixes on different data types.
At the same time, we are adding support for ruby 2.6 and dropping support for ruby 2.2.
- Ruby
Published by emancu about 7 years ago
https://github.com/emancu/toml-rb - Fix comment parsing
Thanks to @greysteil for fixing the comment parsing.
- Ruby
Published by emancu over 8 years ago
https://github.com/emancu/toml-rb - Move requires inside `lib` to fix ubuntu packages
- Ruby
Published by emancu almost 9 years ago
https://github.com/emancu/toml-rb - Fixed Symbolized Table Arrays and old ruby deprecations
Several ruby versions were deprecated for some dependencies, so I took the same path.
Versions unsupported are 1.93, 2.0 and 2.1
On the other hand, I added the newest versions 2.3, 2.4 and 2.4.2 to the supported list
- Ruby
Published by emancu about 9 years ago
https://github.com/emancu/toml-rb - No more namespace conflicts
- Ruby
Published by emancu over 9 years ago
https://github.com/emancu/toml-rb - Multiline strings into arrays
- Ruby
Published by emancu about 10 years ago
https://github.com/emancu/toml-rb - Accept float arrays with exponent parts
- Ruby
Published by emancu over 10 years ago
https://github.com/emancu/toml-rb - Table arrays fixed
Includes issues #91 #90 #89
- Ruby
Published by emancu over 10 years ago
https://github.com/emancu/toml-rb - Accept numbers as keys
Fixes the issue #79
- Ruby
Published by emancu over 10 years ago
https://github.com/emancu/toml-rb - Accept white spaces between brackets and set defaults to datetimes
Bump to 0.3.11
This version includes the fixes for #84 and #85
- Ruby
Published by emancu over 10 years ago
https://github.com/emancu/toml-rb - Fix parsing of escaped sequences
- Ruby
Published by emancu over 10 years ago
https://github.com/emancu/toml-rb - Uninitialized Constant Error Fixed!
- Ruby
Published by emancu over 11 years ago
https://github.com/emancu/toml-rb - New error class to encapsulate all the errors
Pull Request #71
Thanks @timcolonel !
- Ruby
Published by emancu over 11 years ago
https://github.com/emancu/toml-rb - Fix Invalid parse result for empty inline array
Related issue #64
- Ruby
Published by emancu over 11 years ago
https://github.com/emancu/toml-rb - Multiline comments fixed and value overwrite error
Closed issues #60 #59
- Ruby
Published by emancu over 11 years ago
https://github.com/emancu/toml-rb - Symbolize keys issue fixed for inline tables
Something went wrong with rubygems so I had to skip a few minor version numbers.
- Ruby
Published by emancu over 11 years ago
https://github.com/emancu/toml-rb - TOML v0.4.0 specs fully supported
This new version supports
- Inline Tables
- Array of Inline Tables
- Underscore numbers
- Ruby
Published by emancu over 11 years ago
https://github.com/emancu/toml-rb - TOML specs v0.3.1 - Stable
The previous version added support for Array of Tables, a nice structure into TOML.
After a week of been released a few bugs were discovered and fixed.
This new release makes toml-rb more stable =)
- Ruby
Published by emancu almost 12 years ago
https://github.com/emancu/toml-rb - TOML v0.3.1 specs fully supported
Full v0.3.1 specs support.
This includes:
- Array of Tables
- Quoted keys
- Multiline Arrays
- Multiline Strings and Literals
- Datetime RFC 3339
- Ruby
Published by emancu almost 12 years ago