From 3b18a171cd5b6e6a253a96210aac5d92d71a991b Mon Sep 17 00:00:00 2001 From: FourierTransformer Date: Thu, 31 Oct 2024 11:15:14 -0500 Subject: [PATCH 1/8] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 841478a..8950641 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,2 @@ # tinytoml -[![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) +[![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) From 71d6e4ab5951c2b6514adc82cc13da3c327ed4ec Mon Sep 17 00:00:00 2001 From: FourierTransformer Date: Thu, 31 Oct 2024 12:07:06 -0500 Subject: [PATCH 2/8] Update test-and-coverage.yml --- .github/workflows/test-and-coverage.yml | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test-and-coverage.yml b/.github/workflows/test-and-coverage.yml index 73a1677..5af0091 100644 --- a/.github/workflows/test-and-coverage.yml +++ b/.github/workflows/test-and-coverage.yml @@ -6,7 +6,14 @@ on: pull_request: jobs: - test: + fail_if_pull_request_is_draft: + if: github.event.pull_request.draft == true + runs-on: ... + steps: + - name: Fails in order to indicate that pull request needs to be marked as ready to review and unit tests workflow needs to pass. + run: exit 1 + + test: runs-on: ubuntu-latest strategy: matrix: From 46534bc6e0513f5364eb6fcbc246b509d564d3f4 Mon Sep 17 00:00:00 2001 From: FourierTransformer Date: Thu, 31 Oct 2024 12:09:25 -0500 Subject: [PATCH 3/8] Update test-and-coverage.yml --- .github/workflows/test-and-coverage.yml | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/.github/workflows/test-and-coverage.yml b/.github/workflows/test-and-coverage.yml index 5af0091..3e9543e 100644 --- a/.github/workflows/test-and-coverage.yml +++ b/.github/workflows/test-and-coverage.yml @@ -6,19 +6,16 @@ on: pull_request: jobs: - fail_if_pull_request_is_draft: - if: github.event.pull_request.draft == true - runs-on: ... - steps: - - name: Fails in order to indicate that pull request needs to be marked as ready to review and unit tests workflow needs to pass. - run: exit 1 - test: runs-on: ubuntu-latest strategy: matrix: lua: [lua=5.1, lua=5.2, lua=5.3, lua=5.4, luajit=2.0, luajit=@v2.1.ROLLING] steps: + - name: Fail on Draft PRs + if: github.event.pull_request.draft == true + run: exit 1 + # Checks-out the repository under $GITHUB_WORKSPACE. - uses: actions/checkout@v4 - uses: actions/setup-go@v5 From 39336810e6f325f3bb6c6edb2ed42d88cd8e0e86 Mon Sep 17 00:00:00 2001 From: FourierTransformer Date: Thu, 31 Oct 2024 12:56:19 -0500 Subject: [PATCH 4/8] Update README.md --- README.md | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) diff --git a/README.md b/README.md index 8950641..c4bd2b7 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,65 @@ # tinytoml [![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) + +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 _by default_ represented by strings, but can be configured to use a custom type if desired. + +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: +- Lua doesn't differentiate between an array or a dictionary, so tests involving _empty_ arrays fail. +- Some Lua versions have differences in how numbers are represented +- tinytoml currently support trailing commas in arrays/inline-tables. This is coming in TOML 1.1.0. + +Current Supported TOML Version: 1.0.0 + +## Installing +You can grab the `tinytoml.lua` file from this repo (or the `tinytoml.tl` file if using Teal) + +## Parsing TOML + +### `tinytoml.parse(filename [, options])` +With no options, tinytoml will load the file and parse it directly into a Lua table. + +```lua +local tinytoml = require("tinytoml") +tinytoml.parse("filename.toml") +``` +It will throw an `error()` if unable to parse the file. + +### Options +There are a few parsing options available that are passed in the the `options` parameter as a table. + +- `load_from_string` + + allows loading the TOML data from a string rather than a file: + ```lua + tinytoml.parse("fruit=banana\nvegetable=carrot", {load_from_string=true}) + ``` + +- `type_conversion` + + 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` options currently supports the various datetime types. + - `datetime` - includes TZ + - `datetime-local` - no TZ + - `date-local` - Just the date (2024-10-31) + - `time-local` - Just the time (12:49) + + For example, if you wanted to use [luatz](https://github.com/daurnimator/luatz) for handling datetimes: + ```lua + local luatz = require("luatz") + local type_conversion = { + ["datetime"] = luatz.parse.rfc_3339, -- realistically you would want to handle errors from whatever module + ["datetime-local"] = luatz.parse.rfc_3339 + } + tinytoml.parse("a=2024-10-31T12:49Z", {type_conversion=type_conversion}) + ``` + + or just use your own method: + ```lua + local function my_custom_datetime(raw_string) + return {["now_in_a_table"] = raw_string} + end + local type_conversion = { + ["datetime"] = my_custom_date, + ["datetime-local"] = my_custom_date + } + tinytoml.parse("a=2024-10-31T12:49Z", {type_conversion=type_conversion}) + ``` From f3f17ffe77e83ecf394e39c997f1cce7196ca6f2 Mon Sep 17 00:00:00 2001 From: FourierTransformer Date: Thu, 31 Oct 2024 13:17:32 -0500 Subject: [PATCH 5/8] Update README.md --- README.md | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index c4bd2b7..4ab793b 100644 --- a/README.md +++ b/README.md @@ -36,9 +36,9 @@ There are a few parsing options available that are passed in the the `options` p - `type_conversion` - 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` options currently supports the various datetime types. - - `datetime` - includes TZ - - `datetime-local` - no TZ + 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: + - `datetime` - includes TZ (2024-10-31T12:49Z) + - `datetime-local` - no TZ (2024-10-31T12:49) - `date-local` - Just the date (2024-10-31) - `time-local` - Just the time (12:49) @@ -46,13 +46,13 @@ There are a few parsing options available that are passed in the the `options` p ```lua local luatz = require("luatz") local type_conversion = { - ["datetime"] = luatz.parse.rfc_3339, -- realistically you would want to handle errors from whatever module + ["datetime"] = luatz.parse.rfc_3339, -- realistically you would want to handle errors accordingly ["datetime-local"] = luatz.parse.rfc_3339 } tinytoml.parse("a=2024-10-31T12:49Z", {type_conversion=type_conversion}) ``` - or just use your own method: + or just use your own function: ```lua local function my_custom_datetime(raw_string) return {["now_in_a_table"] = raw_string} @@ -63,3 +63,4 @@ There are a few parsing options available that are passed in the the `options` p } tinytoml.parse("a=2024-10-31T12:49Z", {type_conversion=type_conversion}) ``` + From 18a43c18168c1940296f6695a3133480ce00c1de Mon Sep 17 00:00:00 2001 From: FourierTransformer Date: Thu, 31 Oct 2024 16:40:15 -0500 Subject: [PATCH 6/8] Update README.md tested the readme examples --- README.md | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 4ab793b..aa937bd 100644 --- a/README.md +++ b/README.md @@ -31,16 +31,16 @@ There are a few parsing options available that are passed in the the `options` p allows loading the TOML data from a string rather than a file: ```lua - tinytoml.parse("fruit=banana\nvegetable=carrot", {load_from_string=true}) + tinytoml.parse("fruit='banana\'nvegetable='carrot'", {load_from_string=true}) ``` - `type_conversion` 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: - - `datetime` - includes TZ (2024-10-31T12:49Z) - - `datetime-local` - no TZ (2024-10-31T12:49) - - `date-local` - Just the date (2024-10-31) - - `time-local` - Just the time (12:49) + - `datetime` - includes TZ (`2024-10-31T12:49:00Z`) + - `datetime-local` - no TZ (`2024-10-31T12:49:00`) + - `date-local` - Just the date (`2024-10-31`) + - `time-local` - Just the time (`12:49:00`) For example, if you wanted to use [luatz](https://github.com/daurnimator/luatz) for handling datetimes: ```lua @@ -49,7 +49,7 @@ There are a few parsing options available that are passed in the the `options` p ["datetime"] = luatz.parse.rfc_3339, -- realistically you would want to handle errors accordingly ["datetime-local"] = luatz.parse.rfc_3339 } - tinytoml.parse("a=2024-10-31T12:49Z", {type_conversion=type_conversion}) + tinytoml.parse("a=2024-10-31T12:49:00Z", {load_from_string=true, type_conversion=type_conversion}) ``` or just use your own function: @@ -58,9 +58,11 @@ There are a few parsing options available that are passed in the the `options` p return {["now_in_a_table"] = raw_string} end local type_conversion = { - ["datetime"] = my_custom_date, - ["datetime-local"] = my_custom_date + ["datetime"] = my_custom_datetime, + ["datetime-local"] = my_custom_datetime } - tinytoml.parse("a=2024-10-31T12:49Z", {type_conversion=type_conversion}) + tinytoml.parse("a=2024-10-31T12:49:00Z", {load_from_string=true, type_conversion=type_conversion}) ``` +- `assign_value_function` + 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. From 52d9572a4d8c82ec61ba75fae91a72b2bdffadf2 Mon Sep 17 00:00:00 2001 From: FourierTransformer Date: Thu, 31 Oct 2024 16:49:21 -0500 Subject: [PATCH 7/8] Update README.md --- README.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index aa937bd..370d57b 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # tinytoml [![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) -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 _by default_ represented by strings, but can be configured to use a custom type if desired. +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. 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: - Lua doesn't differentiate between an array or a dictionary, so tests involving _empty_ arrays fail. @@ -10,6 +10,11 @@ tinytoml passes all the [toml-test](https://github.com/toml-lang/toml-test) use Current Supported TOML Version: 1.0.0 +## Implemented and Missing Features +- TOML Parsing in Pure Lua, just grab the tinytoml.lua file and go! +- Does not keep track of comments +- Cannot encode a table to TOML + ## Installing You can grab the `tinytoml.lua` file from this repo (or the `tinytoml.tl` file if using Teal) From fdca4c8bbe23bcffa69ff4e5951826e5546ec78c Mon Sep 17 00:00:00 2001 From: FourierTransformer Date: Thu, 31 Oct 2024 16:54:03 -0500 Subject: [PATCH 8/8] Update test-and-coverage.yml --- .github/workflows/test-and-coverage.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/test-and-coverage.yml b/.github/workflows/test-and-coverage.yml index 3e9543e..5ad3d31 100644 --- a/.github/workflows/test-and-coverage.yml +++ b/.github/workflows/test-and-coverage.yml @@ -4,6 +4,7 @@ on: push: branches: [ main ] pull_request: + types: [review_requested, ready_for_review] jobs: test: