Skip to content

Commit bb76d06

Browse files
Adding Teal files to LuaRocks (#5)
* Adding tl files to LuaRocks * switching to latest v2.1 branch instead of rolling tag (which is out of date)
1 parent 9062921 commit bb76d06

File tree

6 files changed

+110
-112
lines changed

6 files changed

+110
-112
lines changed

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,13 @@ on:
44
push:
55
branches: [ main ]
66
pull_request:
7-
types: [review_requested, ready_for_review]
87

98
jobs:
109
test:
1110
runs-on: ubuntu-latest
1211
strategy:
1312
matrix:
14-
lua: [lua=5.1, lua=5.2, lua=5.3, lua=5.4, luajit=2.0, [email protected].ROLLING]
13+
lua: [lua=5.1, lua=5.2, lua=5.3, lua=5.4, luajit=2.0, [email protected]]
1514
steps:
1615
- name: Fail on Draft PRs
1716
if: github.event.pull_request.draft == true

tinytoml-0.0.1-1.rockspec

Lines changed: 0 additions & 29 deletions
This file was deleted.

tinytoml-0.0.2-1.rockspec

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package = "tinytoml"
2+
version = "0.0.2-1"
3+
4+
source = {
5+
url = "git://github.com/FourierTransformer/tinytoml.git",
6+
tag = "0.0.2"
7+
}
8+
9+
description = {
10+
summary = "A pure Lua TOML parser",
11+
detailed = [[
12+
tinytoml is an easy to use TOML parser library for Lua. It can read in TOML files or load them from a string.
13+
It supports all TOML 1.0.0 features including parsing strings, numbers, datetimes, arrays, inline-tables and even validating UTF-8 with good error messages if anything fails!
14+
]],
15+
homepage = "https://github.com/FourierTransformer/tinytoml",
16+
maintainer = "Fourier Transformer <[email protected]>",
17+
license = "MIT"
18+
}
19+
20+
dependencies = {
21+
"lua >= 5.1",
22+
}
23+
24+
build = {
25+
type = "builtin",
26+
modules = {
27+
["tinytoml"] = "tinytoml.lua"
28+
},
29+
install = {
30+
lua = {
31+
["tinytoml"] = "tinytoml.tl"
32+
}
33+
}
34+
}

tinytoml.lua

Lines changed: 33 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -162,32 +162,27 @@ end
162162

163163

164164
local _unpack = unpack or table.unpack
165-
local utf8char
165+
local _tointeger = math.tointeger or tonumber
166166

167-
if (tonumber((_VERSION or ''):match('[%d.]*$')) or 0) < 5.3 then
168-
169-
utf8char = function(cp)
170-
if cp < 128 then
171-
return string.char(cp)
172-
end
173-
local suffix = cp % 64
174-
local c4 = 128 + suffix
175-
cp = (cp - suffix) / 64
176-
if cp < 32 then
177-
return string.char(192 + (cp), (c4))
178-
end
179-
suffix = cp % 64
180-
local c3 = 128 + suffix
181-
cp = (cp - suffix) / 64
182-
if cp < 16 then
183-
return string.char(224 + (cp), c3, c4)
184-
end
185-
suffix = cp % 64
186-
cp = (cp - suffix) / 64
187-
return string.char(240 + (cp), 128 + (suffix), c3, c4)
167+
local _utf8char = utf8 and utf8.char or function(cp)
168+
if cp < 128 then
169+
return string.char(cp)
188170
end
189-
else
190-
utf8char = utf8.char
171+
local suffix = cp % 64
172+
local c4 = 128 + suffix
173+
cp = (cp - suffix) / 64
174+
if cp < 32 then
175+
return string.char(192 + (cp), (c4))
176+
end
177+
suffix = cp % 64
178+
local c3 = 128 + suffix
179+
cp = (cp - suffix) / 64
180+
if cp < 16 then
181+
return string.char(224 + (cp), c3, c4)
182+
end
183+
suffix = cp % 64
184+
cp = (cp - suffix) / 64
185+
return string.char(240 + (cp), 128 + (suffix), c3, c4)
191186
end
192187

193188
local function validate_utf8(input, toml_sub)
@@ -307,7 +302,7 @@ local function handle_backslash_escape(sm)
307302

308303
if (sm.match == "u" and #sm.ext == 4) or
309304
(sm.match == "U" and #sm.ext == 8) then
310-
local codepoint_to_insert = utf8char(tonumber(sm.ext, 16))
305+
local codepoint_to_insert = _utf8char(tonumber(sm.ext, 16))
311306
if not validate_utf8(codepoint_to_insert) then
312307
_error(sm, "Escaped UTF-8 sequence not valid UTF-8 character: \\" .. sm.match .. sm.ext, "string")
313308
end
@@ -505,7 +500,7 @@ local function validate_integer(sm, value)
505500
if sm.match then
506501
if sm.match:find("^[-+]?0[%d_]") then _error(sm, "Integers can't start with a leading 0. Found integer: " .. sm.match, "integer") end
507502
sm.match = remove_underscores_number(sm, sm.match, "integer")
508-
sm.value = tonumber(sm.match)
503+
sm.value = _tointeger(sm.match)
509504
sm.value_type = "integer"
510505
return true
511506
end
@@ -558,9 +553,9 @@ local function validate_datetime(sm, value)
558553
local hour, min, sec
559554
sm._, sm._, sm.match, hour, min, sec, sm.ext = value:find("^((%d%d):(%d%d):(%d%d))(.*)$")
560555
if sm.match then
561-
if tonumber(hour) > 23 then _error(sm, "Hours must be less than 24. Found hour: " .. hour .. "in: " .. sm.match, "local-time") end
562-
if tonumber(min) > 59 then _error(sm, "Minutes must be less than 60. Found minute: " .. min .. "in: " .. sm.match, "local-time") end
563-
if tonumber(sec) > 60 then _error(sm, "Seconds must be less than 61. Found second: " .. sec .. "in: " .. sm.match, "local-time") end
556+
if _tointeger(hour) > 23 then _error(sm, "Hours must be less than 24. Found hour: " .. hour .. "in: " .. sm.match, "local-time") end
557+
if _tointeger(min) > 59 then _error(sm, "Minutes must be less than 60. Found minute: " .. min .. "in: " .. sm.match, "local-time") end
558+
if _tointeger(sec) > 60 then _error(sm, "Seconds must be less than 61. Found second: " .. sec .. "in: " .. sm.match, "local-time") end
564559
if sm.ext ~= "" then
565560
if sm.ext:find("^%.%d+$") then
566561
sm.value_type = "time-local"
@@ -578,7 +573,7 @@ local function validate_datetime(sm, value)
578573
local year, month, day
579574
sm._, sm._, sm.match, year_s, month_s, day_s = value:find("^((%d%d%d%d)%-(%d%d)%-(%d%d))$")
580575
if sm.match then
581-
year, month, day = tonumber(year_s), tonumber(month_s), tonumber(day_s)
576+
year, month, day = _tointeger(year_s), _tointeger(month_s), _tointeger(day_s)
582577
if month == 0 or month > 12 then _error(sm, "Month must be between 01-12. Found month: " .. month .. "in: " .. sm.match, "local-date") end
583578
if day == 0 or day > max_days_in_month[month] then _error(sm, "Too many days in the month. Found " .. day .. " days in month " .. month .. ", which only has " .. max_days_in_month[month] .. " days in: " .. sm.match, "local-date") end
584579
if month == 2 then
@@ -607,10 +602,10 @@ local function validate_datetime(sm, value)
607602
value:find("^((%d%d%d%d)%-(%d%d)%-(%d%d)[Tt ](%d%d):(%d%d):(%d%d))(.*)$")
608603

609604
if sm.match then
610-
if tonumber(hour) > 23 then _error(sm, "Hours must be less than 24. Found hour: " .. hour .. "in: " .. sm.match, "") end
611-
if tonumber(min) > 59 then _error(sm, "Minutes must be less than 60. Found minute: " .. min .. "in: " .. sm.match) end
612-
if tonumber(sec) > 60 then _error(sm, "Seconds must be less than 61. Found second: " .. sec .. "in: " .. sm.match) end
613-
year, month, day = tonumber(year_s), tonumber(month_s), tonumber(day_s)
605+
if _tointeger(hour) > 23 then _error(sm, "Hours must be less than 24. Found hour: " .. hour .. "in: " .. sm.match, "") end
606+
if _tointeger(min) > 59 then _error(sm, "Minutes must be less than 60. Found minute: " .. min .. "in: " .. sm.match) end
607+
if _tointeger(sec) > 60 then _error(sm, "Seconds must be less than 61. Found second: " .. sec .. "in: " .. sm.match) end
608+
year, month, day = _tointeger(year_s), _tointeger(month_s), _tointeger(day_s)
614609
if month == 0 or month > 12 then _error(sm, "Month must be between 01-12. Found month: " .. month .. "in: " .. sm.match) end
615610
if day == 0 or day > max_days_in_month[month] then _error(sm, "Too many days in the month. Found " .. day .. " days in month " .. month .. ", which only has " .. max_days_in_month[month] .. " days in: " .. sm.match, "local-datetime") end
616611
if month == 2 then
@@ -632,8 +627,8 @@ local function validate_datetime(sm, value)
632627
return true
633628
elseif sm.ext:find("^%.%d+[+-]%d%d:%d%d$") then
634629
sm._, sm.end_seq, hour, min = sm.ext:find("^%.%d+[+-](%d%d):(%d%d)$")
635-
if tonumber(hour) > 23 then _error(sm, "Hours must be less than 24. Found hour: " .. hour .. "in: " .. sm.match, "offset-date-time") end
636-
if tonumber(min) > 59 then _error(sm, "Minutes must be less than 60. Found minute: " .. min .. "in: " .. sm.match, "offset-date-time") end
630+
if _tointeger(hour) > 23 then _error(sm, "Hours must be less than 24. Found hour: " .. hour .. "in: " .. sm.match, "offset-date-time") end
631+
if _tointeger(min) > 59 then _error(sm, "Minutes must be less than 60. Found minute: " .. min .. "in: " .. sm.match, "offset-date-time") end
637632
sm.value_type = "datetime"
638633
sm.value = sm.type_conversion[sm.value_type](sm.match .. sm.ext:sub(1, 4))
639634
return true
@@ -643,8 +638,8 @@ local function validate_datetime(sm, value)
643638
return true
644639
elseif sm.ext:find("^[+-]%d%d:%d%d$") then
645640
sm._, sm.end_seq, hour, min = sm.ext:find("^[+-](%d%d):(%d%d)$")
646-
if tonumber(hour) > 23 then _error(sm, "Hours must be less than 24. Found hour: " .. hour .. "in: " .. sm.match, "offset-date-time") end
647-
if tonumber(min) > 59 then _error(sm, "Minutes must be less than 60. Found minute: " .. min .. "in: " .. sm.match, "offset-date-time") end
641+
if _tointeger(hour) > 23 then _error(sm, "Hours must be less than 24. Found hour: " .. hour .. "in: " .. sm.match, "offset-date-time") end
642+
if _tointeger(min) > 59 then _error(sm, "Minutes must be less than 60. Found minute: " .. min .. "in: " .. sm.match, "offset-date-time") end
648643
sm.value_type = "datetime"
649644
sm.value = sm.type_conversion[sm.value_type](sm.match .. sm.ext)
650645
return true

tinytoml.tl

Lines changed: 38 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -162,32 +162,27 @@ end
162162

163163
global unpack: function
164164
local _unpack = unpack or table.unpack
165-
local utf8char: function(number): string
166-
167-
if (tonumber((_VERSION or ''):match('[%d.]*$')) or 0) < 5.3 then
168-
-- from https://stackoverflow.com/a/26237757
169-
utf8char = function(cp: number): string
170-
if cp < 128 then
171-
return string.char(cp as integer)
172-
end
173-
local suffix = cp % 64
174-
local c4 = 128 + suffix
175-
cp = (cp - suffix) / 64
176-
if cp < 32 then
177-
return string.char(192 + (cp as integer), (c4 as integer))
178-
end
179-
suffix = cp % 64
180-
local c3 = 128 + suffix
181-
cp = (cp - suffix) / 64
182-
if cp < 16 then
183-
return string.char(224 + (cp as integer), c3 as integer, c4 as integer)
184-
end
185-
suffix = cp % 64
186-
cp = (cp - suffix) / 64
187-
return string.char(240 + (cp as integer), 128 + (suffix as integer), c3 as integer, c4 as integer)
188-
end
189-
else
190-
utf8char = utf8.char
165+
local _tointeger = math.tointeger or tonumber as function(string): integer
166+
-- function from https://stackoverflow.com/a/26237757
167+
local _utf8char = utf8 and utf8.char or function(cp: number): string
168+
if cp < 128 then
169+
return string.char(cp as integer)
170+
end
171+
local suffix = cp % 64
172+
local c4 = 128 + suffix
173+
cp = (cp - suffix) / 64
174+
if cp < 32 then
175+
return string.char(192 + (cp as integer), (c4 as integer))
176+
end
177+
suffix = cp % 64
178+
local c3 = 128 + suffix
179+
cp = (cp - suffix) / 64
180+
if cp < 16 then
181+
return string.char(224 + (cp as integer), c3 as integer, c4 as integer)
182+
end
183+
suffix = cp % 64
184+
cp = (cp - suffix) / 64
185+
return string.char(240 + (cp as integer), 128 + (suffix as integer), c3 as integer, c4 as integer)
191186
end
192187

193188
local function validate_utf8(input: string, toml_sub?: boolean): boolean, integer
@@ -307,7 +302,7 @@ local function handle_backslash_escape(sm: StateMachine): string, boolean
307302
--if (sm.match == "x" and #sm.ext == 2) or -- hex escapes coming in toml 1.1.0, will need to update pattern in :find above as well
308303
if (sm.match == "u" and #sm.ext == 4) or
309304
(sm.match == "U" and #sm.ext == 8) then
310-
local codepoint_to_insert = utf8char(tonumber(sm.ext, 16))
305+
local codepoint_to_insert = _utf8char(tonumber(sm.ext, 16))
311306
if not validate_utf8(codepoint_to_insert) then
312307
_error(sm, "Escaped UTF-8 sequence not valid UTF-8 character: \\" .. sm.match .. sm.ext, "string")
313308
end
@@ -505,7 +500,7 @@ local function validate_integer(sm: StateMachine, value: string): boolean
505500
if sm.match then
506501
if sm.match:find("^[-+]?0[%d_]") then _error(sm, "Integers can't start with a leading 0. Found integer: " .. sm.match, "integer") end
507502
sm.match = remove_underscores_number(sm, sm.match, "integer")
508-
sm.value = tonumber(sm.match)
503+
sm.value = _tointeger(sm.match)
509504
sm.value_type = "integer"
510505
return true
511506
end
@@ -558,9 +553,9 @@ local function validate_datetime(sm: StateMachine, value: string): boolean
558553
local hour, min, sec: string, string, string
559554
sm._, sm._, sm.match, hour, min, sec, sm.ext = value:find("^((%d%d):(%d%d):(%d%d))(.*)$") as (integer, integer, string, string, string, string, string)
560555
if sm.match then
561-
if tonumber(hour) > 23 then _error(sm, "Hours must be less than 24. Found hour: " .. hour .. "in: " .. sm.match, "local-time") end
562-
if tonumber(min) > 59 then _error(sm, "Minutes must be less than 60. Found minute: " .. min .. "in: " .. sm.match, "local-time") end
563-
if tonumber(sec) > 60 then _error(sm, "Seconds must be less than 61. Found second: " .. sec .. "in: " .. sm.match, "local-time") end
556+
if _tointeger(hour) > 23 then _error(sm, "Hours must be less than 24. Found hour: " .. hour .. "in: " .. sm.match, "local-time") end
557+
if _tointeger(min) > 59 then _error(sm, "Minutes must be less than 60. Found minute: " .. min .. "in: " .. sm.match, "local-time") end
558+
if _tointeger(sec) > 60 then _error(sm, "Seconds must be less than 61. Found second: " .. sec .. "in: " .. sm.match, "local-time") end
564559
if sm.ext ~= "" then
565560
if sm.ext:find("^%.%d+$") then
566561
sm.value_type = "time-local"
@@ -575,12 +570,12 @@ local function validate_datetime(sm: StateMachine, value: string): boolean
575570
end
576571

577572
local year_s, month_s, day_s: string, string, string
578-
local year, month, day: number, number, number
573+
local year, month, day: integer, integer, integer
579574
sm._, sm._, sm.match, year_s, month_s, day_s = value:find("^((%d%d%d%d)%-(%d%d)%-(%d%d))$") as (integer, integer, string, string, string, string)
580575
if sm.match then
581-
year, month, day = tonumber(year_s), tonumber(month_s), tonumber(day_s)
576+
year, month, day = _tointeger(year_s), _tointeger(month_s), _tointeger(day_s)
582577
if month == 0 or month > 12 then _error(sm, "Month must be between 01-12. Found month: " .. month .. "in: " .. sm.match, "local-date") end
583-
if day == 0 or day > max_days_in_month[month as integer] then _error(sm, "Too many days in the month. Found " .. day .. " days in month " .. month .. ", which only has " .. max_days_in_month[month as integer] .. " days in: " .. sm.match, "local-date") end
578+
if day == 0 or day > max_days_in_month[month] then _error(sm, "Too many days in the month. Found " .. day .. " days in month " .. month .. ", which only has " .. max_days_in_month[month as integer] .. " days in: " .. sm.match, "local-date") end
584579
if month == 2 then
585580
local leap_year = (year % 4 == 0) and not(year % 100 == 0) or (year % 400 == 0)
586581
if leap_year == false then
@@ -607,12 +602,12 @@ local function validate_datetime(sm: StateMachine, value: string): boolean
607602
value:find("^((%d%d%d%d)%-(%d%d)%-(%d%d)[Tt ](%d%d):(%d%d):(%d%d))(.*)$")
608603
as (integer, integer, string, string, string, string, string, string, string, string)
609604
if sm.match then
610-
if tonumber(hour) > 23 then _error(sm, "Hours must be less than 24. Found hour: " .. hour .. "in: " .. sm.match, "") end
611-
if tonumber(min) > 59 then _error(sm, "Minutes must be less than 60. Found minute: " .. min .. "in: " .. sm.match) end
612-
if tonumber(sec) > 60 then _error(sm, "Seconds must be less than 61. Found second: " .. sec .. "in: " .. sm.match) end
613-
year, month, day = tonumber(year_s), tonumber(month_s), tonumber(day_s)
605+
if _tointeger(hour) > 23 then _error(sm, "Hours must be less than 24. Found hour: " .. hour .. "in: " .. sm.match, "") end
606+
if _tointeger(min) > 59 then _error(sm, "Minutes must be less than 60. Found minute: " .. min .. "in: " .. sm.match) end
607+
if _tointeger(sec) > 60 then _error(sm, "Seconds must be less than 61. Found second: " .. sec .. "in: " .. sm.match) end
608+
year, month, day = _tointeger(year_s), _tointeger(month_s), _tointeger(day_s)
614609
if month == 0 or month > 12 then _error(sm, "Month must be between 01-12. Found month: " .. month .. "in: " .. sm.match) end
615-
if day == 0 or day > max_days_in_month[month as integer] then _error(sm, "Too many days in the month. Found " .. day .. " days in month " .. month .. ", which only has " .. max_days_in_month[month as integer] .. " days in: " .. sm.match, "local-datetime") end
610+
if day == 0 or day > max_days_in_month[month] then _error(sm, "Too many days in the month. Found " .. day .. " days in month " .. month .. ", which only has " .. max_days_in_month[month as integer] .. " days in: " .. sm.match, "local-datetime") end
616611
if month == 2 then
617612
local leap_year = (year % 4 == 0) and not(year % 100 == 0) or (year % 400 == 0)
618613
if leap_year == false then
@@ -632,8 +627,8 @@ local function validate_datetime(sm: StateMachine, value: string): boolean
632627
return true
633628
elseif sm.ext:find("^%.%d+[+-]%d%d:%d%d$") then
634629
sm._, sm.end_seq, hour, min = sm.ext:find("^%.%d+[+-](%d%d):(%d%d)$") as (integer, integer, string, string)
635-
if tonumber(hour) > 23 then _error(sm, "Hours must be less than 24. Found hour: " .. hour .. "in: " .. sm.match, "offset-date-time") end
636-
if tonumber(min) > 59 then _error(sm, "Minutes must be less than 60. Found minute: " .. min .. "in: " .. sm.match, "offset-date-time") end
630+
if _tointeger(hour) > 23 then _error(sm, "Hours must be less than 24. Found hour: " .. hour .. "in: " .. sm.match, "offset-date-time") end
631+
if _tointeger(min) > 59 then _error(sm, "Minutes must be less than 60. Found minute: " .. min .. "in: " .. sm.match, "offset-date-time") end
637632
sm.value_type = "datetime"
638633
sm.value = sm.type_conversion[sm.value_type](sm.match .. sm.ext:sub(1, 4))
639634
return true
@@ -643,8 +638,8 @@ local function validate_datetime(sm: StateMachine, value: string): boolean
643638
return true
644639
elseif sm.ext:find("^[+-]%d%d:%d%d$") then
645640
sm._, sm.end_seq, hour, min = sm.ext:find("^[+-](%d%d):(%d%d)$") as (integer, integer, string, string)
646-
if tonumber(hour) > 23 then _error(sm, "Hours must be less than 24. Found hour: " .. hour .. "in: " .. sm.match, "offset-date-time") end
647-
if tonumber(min) > 59 then _error(sm, "Minutes must be less than 60. Found minute: " .. min .. "in: " .. sm.match, "offset-date-time") end
641+
if _tointeger(hour) > 23 then _error(sm, "Hours must be less than 24. Found hour: " .. hour .. "in: " .. sm.match, "offset-date-time") end
642+
if _tointeger(min) > 59 then _error(sm, "Minutes must be less than 60. Found minute: " .. min .. "in: " .. sm.match, "offset-date-time") end
648643
sm.value_type = "datetime"
649644
sm.value = sm.type_conversion[sm.value_type](sm.match .. sm.ext)
650645
return true

tlconfig.lua

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
return {
2+
gen_target = "5.1",
3+
gen_compat = "off"
4+
}

0 commit comments

Comments
 (0)