Starting refactoring

This commit is contained in:
perro tuerto 2023-03-27 11:48:03 -07:00
parent 781a7920f6
commit 879abd7b84
3 changed files with 99 additions and 0 deletions

32
dist/lin.lua vendored
View File

@ -6491,6 +6491,37 @@ lit.metastruct = {
},
}
-- TODO
function lit.stringify(content)
if pandoc.utils.type(content) == "Inlines" then
return pandoc.utils.stringify(content:walk {
Quoted = function(quoted)
local quote = (quoted.quotetype == SingleQuoted and '"' or "'")
quoted = pandoc.utils.stringify(quoted.content)
return pandoc.Str(quote .. quoted .. quote)
end,
Inline = function(inline)
return pandoc.utils.stringify(inline)
end,
})
else
return pandoc.utils.stringify(content)
end
end
function lit.meta2table(meta)
for k, v in pairs(meta) do
if pandoc.utils.type(v) == "table" then
lit.meta2table(v)
else
v = lit.stringify(v)
-- print(k, v)
end
end
return meta
end
lit.test = lit.meta2table(pandoc.read(("src/locate.yaml"):read_text()).meta)
-- Messages for the user
lit.msg = {
["INFO"] = {
@ -6613,6 +6644,7 @@ function lit.checkmetatype(type, meta, key)
end
end
-- TODO: has bug
function lit.checkmetatable(table, meta, key)
local mval = lit.getmetaval(meta, key)
for _, pattern in pairs(table) do

View File

@ -28,6 +28,37 @@ lit.metastruct = {
},
}
-- TODO
function lit.stringify(content)
if pandoc.utils.type(content) == "Inlines" then
return pandoc.utils.stringify(content:walk {
Quoted = function(quoted)
local quote = (quoted.quotetype == SingleQuoted and '"' or "'")
quoted = pandoc.utils.stringify(quoted.content)
return pandoc.Str(quote .. quoted .. quote)
end,
Inline = function(inline)
return pandoc.utils.stringify(inline)
end,
})
else
return pandoc.utils.stringify(content)
end
end
function lit.meta2table(meta)
for k, v in pairs(meta) do
if pandoc.utils.type(v) == "table" then
lit.meta2table(v)
else
v = lit.stringify(v)
-- print(k, v)
end
end
return meta
end
lit.test = lit.meta2table(pandoc.read(("src/locate.yaml"):read_text()).meta)
-- Messages for the user
lit.msg = {
["INFO"] = {
@ -150,6 +181,7 @@ function lit.checkmetatype(type, meta, key)
end
end
-- TODO: has bug
function lit.checkmetatable(table, meta, key)
local mval = lit.getmetaval(meta, key)
for _, pattern in pairs(table) do

35
src/locate.yaml Normal file
View File

@ -0,0 +1,35 @@
---
INFO:
parsing:
en: Parsing:\n#1
es: Realizando análisis sintáctico:\n#1
WARNING:
foo:
en: true
es: 1
ERROR:
invalid_key:
en: Invalid key '#1' with value '#2'
es: Clave '#1' inválida con valor '#2'
invalid_path:
en: Invalid path '#1' in key '#2'
es: Ruta '#1' inválida en clave '#2'
invalid_type:
en: Invalid type '#1' in key '#2'
es: Tipo '#1' inválido en clave '#2'
invalid_value:
en: Invalid value '#1' in key '#2'
es: Valor '#1' inválido en clave '#2'
no_key:
en: Key '#1' not found
es: Clave '#1' no encontrada
aborted:
en: Aborted due previous errors
es: Abortado debido a previos errores
yaml_empty:
en: Empty YAML
es: YAML vacío
yaml_invalid:
en: Invalid YAML
es: YAML inválido
...