diff --git a/dist/lin.lua b/dist/lin.lua index 3d37d5b..5c5a311 100644 --- a/dist/lin.lua +++ b/dist/lin.lua @@ -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 diff --git a/opt/fennel.lua b/opt/fennel/fennel.lua similarity index 100% rename from opt/fennel.lua rename to opt/fennel/fennel.lua diff --git a/src/extensions.lua b/opt/lua-extensions/extensions.lua similarity index 100% rename from src/extensions.lua rename to opt/lua-extensions/extensions.lua diff --git a/scripts/get_fennel.sh b/scripts/get_fennel.sh index f4852de..c8fe7a7 100644 --- a/scripts/get_fennel.sh +++ b/scripts/get_fennel.sh @@ -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* diff --git a/scripts/make_dist.lua b/scripts/make_dist.lua index 4e4b453..75c54b1 100644 --- a/scripts/make_dist.lua +++ b/scripts/make_dist.lua @@ -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 diff --git a/scripts/make_jsons.lua b/scripts/make_jsons.lua index e2ce0d0..2aeafc3 100644 --- a/scripts/make_jsons.lua +++ b/scripts/make_jsons.lua @@ -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" diff --git a/scripts/test.lua b/scripts/test.lua index 012be66..4b6f275 100644 --- a/scripts/test.lua +++ b/scripts/test.lua @@ -1,7 +1,7 @@ -- Makes tests -- Adds Lua custom extensions -require "src.extensions" +require "opt.lua-extensions.extensions" require "scripts.make_dist" -- Variables diff --git a/src/literate.lua b/src/literate.lua index 031d467..e8557ba 100644 --- a/src/literate.lua +++ b/src/literate.lua @@ -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 diff --git a/src/locate.yaml b/src/locale.yaml similarity index 97% rename from src/locate.yaml rename to src/locale.yaml index 13d7a92..e8eacb3 100644 --- a/src/locate.yaml +++ b/src/locale.yaml @@ -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'