diff options
author | monster <monster@ydb.tech> | 2022-07-07 14:41:37 +0300 |
---|---|---|
committer | monster <monster@ydb.tech> | 2022-07-07 14:41:37 +0300 |
commit | 06e5c21a835c0e923506c4ff27929f34e00761c2 (patch) | |
tree | 75efcbc6854ef9bd476eb8bf00cc5c900da436a2 /library/cpp/config/support | |
parent | 03f024c4412e3aa613bb543cf1660176320ba8f4 (diff) | |
download | ydb-06e5c21a835c0e923506c4ff27929f34e00761c2.tar.gz |
fix ya.make
Diffstat (limited to 'library/cpp/config/support')
-rw-r--r-- | library/cpp/config/support/pp.lua | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/library/cpp/config/support/pp.lua b/library/cpp/config/support/pp.lua new file mode 100644 index 0000000000..d6a85653a2 --- /dev/null +++ b/library/cpp/config/support/pp.lua @@ -0,0 +1,63 @@ +local function off(i) + local ss = '' + local j = 0 + + while j < i do + ss = ss .. ' ' + j = j + 1 + end + + return ss +end + +local function fmtkey(key) + if type(key) == 'string' and key:match('^[_%a][_%w]*$') then + return key + end + + return '[' .. string.format('%q', key) .. ']' +end + +local function pp(v, i) + if type(v) == "string" then + return string.format('%q', v) + end + + if type(v) == "number" then + return tostring(v) + end + + if type(v) == "nil" then + return 'nil' + end + + if type(v) == "boolean" then + return tostring(v) + end + + if type(v) == "table" then + local ret = "{\n" + local curoff = 1 + + for x, y in pairs(v) do + if type(x) == 'number' and x == curoff then + ret = ret .. off(i + 1) .. pp(y, i + 1) .. ';\n' + curoff = curoff + 1 + else + ret = ret .. off(i + 1) .. fmtkey(x) .. " = " .. pp(y, i + 1) .. ';\n' + end + end + + return ret .. off(i) .. "}" + end + + if v == nil then + return 'nil' + end + + return "" +end + +local function prettify(v) + return pp(v, 0) +end |