ws-cleanup: merge ws/cleanup-types (type annotations)
This commit is contained in:
commit
5d7c223ab8
115 files changed
+583
-515
No files matched your search
@@ -60,7 +60,7 @@ local function bigText(s: string): string
|
||||
end
|
||||
-- text + 1 for a decimal string
|
||||
local function incText(s: string): string
|
||||
local digits = table.create(#s)
|
||||
local digits: { number } = table.create(#s) :: { number }
|
||||
for i = 1, #s do
|
||||
digits[i] = string.byte(s, i) - 48
|
||||
end
|
||||
@@ -73,7 +73,7 @@ local function incText(s: string): string
|
||||
digits[i] = 0
|
||||
i -= 1
|
||||
end
|
||||
local out = table.create(#digits)
|
||||
local out: { string } = table.create(#digits) :: { string }
|
||||
for k, d in digits do
|
||||
out[k] = string.char(48 + d)
|
||||
end
|
||||
@@ -296,11 +296,11 @@ function item(st: St, depth: number): (any, string?)
|
||||
table.insert(t, v)
|
||||
end
|
||||
end
|
||||
if n > r:remaining() then
|
||||
if (n :: number) > r:remaining() then
|
||||
return nil, "array count past the end"
|
||||
end
|
||||
local t = table.create(n)
|
||||
for k = 1, n do
|
||||
local t = table.create(n :: number)
|
||||
for k = 1, n :: number do
|
||||
local v, ve = item(st, depth + 1)
|
||||
if ve then
|
||||
return nil, ve
|
||||
|
||||
@@ -57,7 +57,7 @@ function Csv.sniff(r: Bytes.Reader): number
|
||||
end
|
||||
for _, d in { ",", "\t", ";" } do
|
||||
local _, c1 = gsub(l1, d, "")
|
||||
local _, c2 = gsub(l2, d, "")
|
||||
local _, c2 = gsub(l2 :: string, d, "")
|
||||
if c1 > 0 and c1 == c2 then
|
||||
return 0.15
|
||||
end
|
||||
|
||||
@@ -137,11 +137,11 @@ function Ini.decode(r: Bytes.Reader, opts: DecodeOptions?): (any, Err.Err?)
|
||||
seenKeys[cur] = seen
|
||||
end
|
||||
if seen[key :: string] and o.strict then
|
||||
return nil, Err.new(Err.CORRUPT, "duplicate key " .. key, lineStart)
|
||||
return nil, Err.new(Err.CORRUPT, "duplicate key " .. (key :: string), lineStart)
|
||||
end
|
||||
seen[key :: string] = true
|
||||
if cur == root and type(root[key]) == "table" then
|
||||
return nil, Err.new(Err.CORRUPT, "top-level key " .. key .. " has the name of a section", lineStart)
|
||||
return nil, Err.new(Err.CORRUPT, "top-level key " .. (key :: string) .. " has the name of a section", lineStart)
|
||||
end
|
||||
Types.set(cur, key, value)
|
||||
lastKey, lastIndent, lastTable = key, indent, cur
|
||||
|
||||
@@ -206,7 +206,7 @@ function Decode.decode(s: string, opts: Options?): (any, any, number?)
|
||||
|
||||
-- a (dotted) key: { parts }, next | nil
|
||||
local function key(i: number): ({ string }?, number)
|
||||
local keys = {}
|
||||
local keys: { string } = {}
|
||||
while true do
|
||||
i = ws(i)
|
||||
local c = byte(s, i)
|
||||
@@ -232,7 +232,7 @@ function Decode.decode(s: string, opts: Options?): (any, any, number?)
|
||||
if k == nil then
|
||||
return nil, 0
|
||||
end
|
||||
table.insert(keys, k)
|
||||
table.insert(keys, k :: string)
|
||||
i = ws(i)
|
||||
if byte(s, i) == 46 then
|
||||
i += 1
|
||||
@@ -305,7 +305,7 @@ function Decode.decode(s: string, opts: Options?): (any, any, number?)
|
||||
end
|
||||
return if sign == "-" then -v else v, nexti
|
||||
end
|
||||
local text = sign .. digits
|
||||
local text: string = (sign :: string) .. digits
|
||||
local frac, r2 = match(rest :: string, "^%.([%d_]*)(.*)$")
|
||||
if frac then
|
||||
if not digitsOk(frac, "%d") then
|
||||
@@ -316,10 +316,10 @@ function Decode.decode(s: string, opts: Options?): (any, any, number?)
|
||||
end
|
||||
if rest ~= "" then
|
||||
local es, ed = match(rest :: string, "^[eE]([%+%-]?)([%d_]*)$")
|
||||
if not es or not digitsOk(ed, "%d") then
|
||||
if not es or not digitsOk(ed :: string, "%d") then
|
||||
return fail("bad float", i), 0
|
||||
end
|
||||
text ..= "e" .. es .. gsub(ed, "_", "")
|
||||
text ..= "e" .. es .. gsub(ed :: string, "_", "")
|
||||
end
|
||||
local v = tonumber(text)
|
||||
if v == nil then
|
||||
|
||||
Reference in new issue
Block a user