Skip to content

Commit c1e5deb

Browse files
Update README.md (#2)
* Update README.md
1 parent ab457dc commit c1e5deb

File tree

2 files changed

+78
-2
lines changed

2 files changed

+78
-2
lines changed

.github/workflows/test-and-coverage.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,19 @@ on:
44
push:
55
branches: [ main ]
66
pull_request:
7+
types: [review_requested, ready_for_review]
78

89
jobs:
9-
test:
10+
test:
1011
runs-on: ubuntu-latest
1112
strategy:
1213
matrix:
1314
lua: [lua=5.1, lua=5.2, lua=5.3, lua=5.4, luajit=2.0, [email protected]]
1415
steps:
16+
- name: Fail on Draft PRs
17+
if: github.event.pull_request.draft == true
18+
run: exit 1
19+
1520
# Checks-out the repository under $GITHUB_WORKSPACE.
1621
- uses: actions/checkout@v4
1722
- uses: actions/setup-go@v5

README.md

Lines changed: 72 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,73 @@
11
# tinytoml
2-
[![Run Tests and Code Coverage](https://github.com/FourierTransformer/tinytoml/actions/workflows/test-and-coverage.yml/badge.svg)](https://github.com/FourierTransformer/tinytoml/actions/workflows/test-and-coverage.yml) [![Coverage Status](https://coveralls.io/repos/github/FourierTransformer/tinytoml/badge.svg?branch=refs/pull/1/merge)](https://coveralls.io/github/FourierTransformer/tinytoml?branch=refs/pull/1/merge)
2+
[![Run Tests and Code Coverage](https://github.com/FourierTransformer/tinytoml/actions/workflows/test-and-coverage.yml/badge.svg)](https://github.com/FourierTransformer/tinytoml/actions/workflows/test-and-coverage.yml) [![Coverage Status](https://coveralls.io/repos/github/FourierTransformer/tinytoml/badge.svg?branch=refs/pull/1/merge)](https://coveralls.io/github/FourierTransformer/tinytoml?branch=main)
3+
4+
tinytoml is a pure Lua [TOML](https://toml.io) parsing library. It's written in [Teal](https://github.com/teal-language/tl) and works with Lua 5.1-5.4 and LuaJIT 2.0/2.1. tinytoml parses a TOML document into a standard Lua table using default Lua types. Since TOML supports various datetime types, those are _defaultly_ represented by strings, but can be configured to use a custom type if desired.
5+
6+
tinytoml passes all the [toml-test](https://github.com/toml-lang/toml-test) use cases that Lua can realistically pass (even the UTF-8 ones!). The few that fail are mostly representational:
7+
- Lua doesn't differentiate between an array or a dictionary, so tests involving _empty_ arrays fail.
8+
- Some Lua versions have differences in how numbers are represented
9+
- tinytoml currently support trailing commas in arrays/inline-tables. This is coming in TOML 1.1.0.
10+
11+
Current Supported TOML Version: 1.0.0
12+
13+
## Implemented and Missing Features
14+
- TOML Parsing in Pure Lua, just grab the tinytoml.lua file and go!
15+
- Does not keep track of comments
16+
- Cannot encode a table to TOML
17+
18+
## Installing
19+
You can grab the `tinytoml.lua` file from this repo (or the `tinytoml.tl` file if using Teal)
20+
21+
## Parsing TOML
22+
23+
### `tinytoml.parse(filename [, options])`
24+
With no options, tinytoml will load the file and parse it directly into a Lua table.
25+
26+
```lua
27+
local tinytoml = require("tinytoml")
28+
tinytoml.parse("filename.toml")
29+
```
30+
It will throw an `error()` if unable to parse the file.
31+
32+
### Options
33+
There are a few parsing options available that are passed in the the `options` parameter as a table.
34+
35+
- `load_from_string`
36+
37+
allows loading the TOML data from a string rather than a file:
38+
```lua
39+
tinytoml.parse("fruit='banana\'nvegetable='carrot'", {load_from_string=true})
40+
```
41+
42+
- `type_conversion`
43+
44+
allows registering a function to perform type conversions from the raw string to a custom representation. TOML requires them all the be RFC3339 compliant, and the strings are already verified when this function is called. The `type_conversion` option currently supports the various datetime types:
45+
- `datetime` - includes TZ (`2024-10-31T12:49:00Z`)
46+
- `datetime-local` - no TZ (`2024-10-31T12:49:00`)
47+
- `date-local` - Just the date (`2024-10-31`)
48+
- `time-local` - Just the time (`12:49:00`)
49+
50+
For example, if you wanted to use [luatz](https://github.com/daurnimator/luatz) for handling datetimes:
51+
```lua
52+
local luatz = require("luatz")
53+
local type_conversion = {
54+
["datetime"] = luatz.parse.rfc_3339, -- realistically you would want to handle errors accordingly
55+
["datetime-local"] = luatz.parse.rfc_3339
56+
}
57+
tinytoml.parse("a=2024-10-31T12:49:00Z", {load_from_string=true, type_conversion=type_conversion})
58+
```
59+
60+
or just use your own function:
61+
```lua
62+
local function my_custom_datetime(raw_string)
63+
return {["now_in_a_table"] = raw_string}
64+
end
65+
local type_conversion = {
66+
["datetime"] = my_custom_datetime,
67+
["datetime-local"] = my_custom_datetime
68+
}
69+
tinytoml.parse("a=2024-10-31T12:49:00Z", {load_from_string=true, type_conversion=type_conversion})
70+
```
71+
- `assign_value_function`
72+
73+
this method is called when assigning _every_ value to a table. It's mostly used to help perform the unit testing using [toml-test](https://github.com/toml-lang/toml-test), since they want to see the type and parsed value for comparison purposes. This option is the only one that has potential to change, so we advice against using it. If you need specific functionality that you're implementing through this (or find this function useful in general) - please let us know.

0 commit comments

Comments
 (0)