Refactoring continue

This commit is contained in:
perro tuerto 2023-03-28 12:23:26 -07:00
parent 879abd7b84
commit 80892f0f28
9 changed files with 72 additions and 107 deletions

97
dist/lin.lua vendored
View File

@ -6491,7 +6491,6 @@ lit.metastruct = {
},
}
-- TODO
function lit.stringify(content)
if pandoc.utils.type(content) == "Inlines" then
return pandoc.utils.stringify(content:walk {
@ -6500,6 +6499,9 @@ function lit.stringify(content)
quoted = pandoc.utils.stringify(quoted.content)
return pandoc.Str(quote .. quoted .. quote)
end,
RawInline = function(rawinline)
return pandoc.Str(rawinline.text:gsub("\\n", "\n"):gsub("\\t", "\t"))
end,
Inline = function(inline)
return pandoc.utils.stringify(inline)
end,
@ -6512,62 +6514,59 @@ end
function lit.meta2table(meta)
for k, v in pairs(meta) do
if pandoc.utils.type(v) == "table" then
lit.meta2table(v)
meta[k] = lit.meta2table(v)
else
v = lit.stringify(v)
-- print(k, v)
print(v)
if v == "true" or v == "false" then
v = v == "true"
-- WARN!!
elseif tonumber(v) then
v = tonumber(v)
end
meta[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"] = {
["parsing"] = {
["en"] = "Parsing:\n#1",
["es"] = "Realizando análisis sintáctico:\n#1",
},
},
["WARNING"] = {
},
["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",
},
},
}
lit.msg = lit.meta2table(pandoc.read([[---
INFO:
parsing:
en: Parsing:\n#1
es: Realizando análisis sintáctico:\n#1
WARNING:
foo:
en: bar
es: baz
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
...
]]).meta)
function lit.debuglevel(str)
if str == "ERROR" then

View File

@ -7,5 +7,5 @@ URL="https://fennel-lang.org/downloads/$NAME.tar.gz"
# Copies Fennel from release tarball
curl -O $URL
tar -xvzf $NAME.tar.gz
mv $NAME/fennel.lua opt/
mv $NAME/fennel.lua opt/fennel/
rm -rf $NAME*

View File

@ -1,7 +1,7 @@
-- Makes bundle distribution
-- Adds Lua custom extensions
require "src.extensions"
require "opt.lua-extensions.extensions"
-- Makes distribution
local function make_dist()
@ -19,11 +19,12 @@ local function make_dist()
-- Variables
local name = "lin.lua"
local dist = pandoc.path.join({"dist", name})
local ext = chomp("src/extensions.lua")
local ext = chomp("opt/lua-extensions/extensions.lua")
local fnl = chomp("opt/fennel/fennel.lua", true)
local pan = chomp("src/pandoc.lua")
local fnl = chomp("opt/fennel.lua", true)
local nat = chomp("src/natural.lua", true)
local lit = chomp("src/literate.lua", true)
local msg = ("src/locale.yaml"):read_text()
local license = string.strip([[
Computable Pandoc & Fennel Bundle:
A Pandoc filter for literate and natural programming
@ -41,7 +42,8 @@ Fennel:
-- Bundles Fennel and Computable Pandoc
file = io.open(dist, "w")
file:write("--[[\n", license, "\n]]--\n")
file:write(fnl, "\nlocal fnl = mod\n", ext, nat, lit, pan)
file:write(fnl, "\nlocal fnl = mod\n", ext, nat)
file:write(lit:gsub("#locale%(%)", msg), pan)
file:close()
end

View File

@ -1,7 +1,7 @@
-- Makes JSON test files
-- Adds Lua custom extensions
require "src.extensions"
require "opt.lua-extensions.extensions"
-- Variables
local filter = "dist/lin.lua"

View File

@ -1,7 +1,7 @@
-- Makes tests
-- Adds Lua custom extensions
require "src.extensions"
require "opt.lua-extensions.extensions"
require "scripts.make_dist"
-- Variables

View File

@ -28,7 +28,6 @@ lit.metastruct = {
},
}
-- TODO
function lit.stringify(content)
if pandoc.utils.type(content) == "Inlines" then
return pandoc.utils.stringify(content:walk {
@ -37,6 +36,9 @@ function lit.stringify(content)
quoted = pandoc.utils.stringify(quoted.content)
return pandoc.Str(quote .. quoted .. quote)
end,
RawInline = function(rawinline)
return pandoc.Str(rawinline.text:gsub("\\n", "\n"):gsub("\\t", "\t"))
end,
Inline = function(inline)
return pandoc.utils.stringify(inline)
end,
@ -49,62 +51,24 @@ end
function lit.meta2table(meta)
for k, v in pairs(meta) do
if pandoc.utils.type(v) == "table" then
lit.meta2table(v)
meta[k] = lit.meta2table(v)
else
v = lit.stringify(v)
-- print(k, v)
print(v)
if v == "true" or v == "false" then
v = v == "true"
-- WARN!!
elseif tonumber(v) then
v = tonumber(v)
end
meta[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"] = {
["parsing"] = {
["en"] = "Parsing:\n#1",
["es"] = "Realizando análisis sintáctico:\n#1",
},
},
["WARNING"] = {
},
["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",
},
},
}
lit.msg = lit.meta2table(pandoc.read([[#locale()]]).meta)
function lit.debuglevel(str)
if str == "ERROR" then

View File

@ -5,8 +5,8 @@ INFO:
es: Realizando análisis sintáctico:\n#1
WARNING:
foo:
en: true
es: 1
en: bar
es: baz
ERROR:
invalid_key:
en: Invalid key '#1' with value '#2'