Dummy ready

This commit is contained in:
perro tuerto 2023-03-10 19:09:31 -08:00
parent 0ba2e10fc6
commit a786c4f227
3 changed files with 57 additions and 30 deletions

View File

@ -1,10 +1,8 @@
# Literate Pandoc # Literate Pandoc
[Pandoc] is a world famous "swiss-army" document converted. This is because Literate Pandoc is a [Pandoc reader] written in [Lua] for [literate] and
Pandoc is also a document parser. Thanks to this capability, this repo is a [natural] programming (LNP), i.e.: "[Programming \[...\] as the process of
[Pandoc reader] written in [Lua] for [literate] and [natural] programming creating works of literature][1]".
(LNP), i.e.: "[Programming \[...\] as the process of creating works of
literature][1]".
## Requirements ## Requirements
@ -68,12 +66,12 @@ Literate Pandoc is under [GPLv3].
Happy hacking :) Happy hacking :)
[Pandoc]: https://pandoc.org/
[Pandoc reader]: https://pandoc.org/custom-readers.html [Pandoc reader]: https://pandoc.org/custom-readers.html
[Lua]: https://www.lua.org/ [Lua]: https://www.lua.org/
[literate]: https://en.wikipedia.org/wiki/Literate_programming [literate]: https://en.wikipedia.org/wiki/Literate_programming
[natural]: https://en.wikipedia.org/wiki/Natural-language_programming [natural]: https://en.wikipedia.org/wiki/Natural-language_programming
[1]: https://web.archive.org/web/20170605163729/http://www.desy.de/user/projects/LitProg/Philosophy.html [1]: https://web.archive.org/web/20170605163729/http://www.desy.de/user/projects/LitProg/Philosophy.html
[Pandoc]: https://pandoc.org/
[Releases]: https://git.cuates.net/perro/literate-pandoc/releases [Releases]: https://git.cuates.net/perro/literate-pandoc/releases
[here]: https://git.cuates.net/perro/literate-pandoc/src/branch/no-masters/man/README.md [here]: https://git.cuates.net/perro/literate-pandoc/src/branch/no-masters/man/README.md
[Fennel]: https://fennel-lang.org [Fennel]: https://fennel-lang.org

View File

@ -22,7 +22,7 @@ if [ -z "$ARGS" ]; then
fi fi
# Does tests # Does tests
echo "🐾 Starting tests" clear && echo "🐾 Starting tests"
for arg in "$ARGS"; do for arg in "$ARGS"; do
echo && echo "⚗️ Test in '$arg' format:" echo && echo "⚗️ Test in '$arg' format:"
mds=$'\n\n'`(pandoc -t markdown tests/*.md)` mds=$'\n\n'`(pandoc -t markdown tests/*.md)`

View File

@ -1,6 +1,6 @@
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
-- IMPORTANT: these lines are for development setup
-- IMPORTANT: these lines are changed to "local fennel = mod" -- IMPORTANT: these lines are changed to "local fennel = mod"
-- IMPORTANT: these line are for development setup
-- Enables Fennel <https://fennel-lang.org> for Lisp-Lua compatibility -- Enables Fennel <https://fennel-lang.org> for Lisp-Lua compatibility
local src_root = pandoc.path.directory(PANDOC_SCRIPT_FILE) local src_root = pandoc.path.directory(PANDOC_SCRIPT_FILE)
local fennel_lua = pandoc.path.join({src_root, "../opt/fennel.lua"}) local fennel_lua = pandoc.path.join({src_root, "../opt/fennel.lua"})
@ -8,30 +8,46 @@ package.path = package.path .. ";" .. fennel_lua
local fennel = require("fennel") local fennel = require("fennel")
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
------------------------------- GRAMMAR related -------------------------------
-- Ordered collection of fn call, fn declarations or literal elements
local collection = {}
-- Lua LPeg shortcuts -- Lua LPeg shortcuts
local P, S, R, Cf, Cc, Ct, V, Cs, Cg, Cb, B, C, Cmt = local P, S, R, Cf, Cc, Ct, V, Cs, Cg, Cb, B, C, Cmt =
lpeg.P, lpeg.S, lpeg.R, lpeg.Cf, lpeg.Cc, lpeg.Ct, lpeg.V, lpeg.P, lpeg.S, lpeg.R, lpeg.Cf, lpeg.Cc, lpeg.Ct, lpeg.V,
lpeg.Cs, lpeg.Cg, lpeg.Cb, lpeg.B, lpeg.C, lpeg.Cmt lpeg.Cs, lpeg.Cg, lpeg.Cb, lpeg.B, lpeg.C, lpeg.Cmt
-- Lexical elements -- Lexical elements
local space = S(" \t\r\n") local space = S" \t\r\n"
local lbracket = P"(" local spot = (1 - space) -- TMP
local rbracket = P")" local t1 = S"()" -- TMP
local word = (1 - (space + lbracket + rbracket)) local t2 = (1 - (t1 + space)) -- TMP
local function add_call(str)
table.insert(collection, {call = str})
end
local function add_declaration(str)
table.insert(collection, {declaration = str})
end
local function add_lit(str)
table.insert(collection, {literal = str})
end
-- Grammar -- Grammar
G = P{ G = P {
"Doc"; "Doc";
Doc = space^0 * Ct(V"SExpr"^0) * space^0 / pandoc.Pandoc; Doc = (V"Call" + V"Declaration" + V"Literal")^0;
SExpr = (V"List" + V"Atom"); Call = t1^1 / add_call;
List = lbracket * V"SExpr"^0 * rbracket; Declaration = t2^1 / add_declaration;
Atom = space + V"Word"; Literal = space^1 / add_lit;
Word = word^1 / pandoc.Str;
} }
--------------------------------- LNP related ---------------------------------
-- Evals Lisp code -- Evals Lisp code
-- @param code string: code to evaluate
-- @return table: evaluation result as {bool, string, string, string}
local function eval(code) local function eval(code)
local is_passed, out = pcall ( local is_passed, out = pcall (
function () return fennel.eval(code) end, function () return fennel.eval(code) end,
@ -46,15 +62,28 @@ local function eval(code)
return {is_passed = is_passed, preview = preview, out = out, lua = lua} return {is_passed = is_passed, preview = preview, out = out, lua = lua}
end end
-- Calls Pandoc Reader. function parse(_)
function Reader(input, options) local doc = ""
--[[ for i, t in ipairs(collection) do
local doc = lpeg.match(G, tostring(input)) for k, v in pairs(t) do
if options.standalone then print(i, k, v)
return exec(doc) doc = doc .. v
else end
return doc
end end
]]-- return doc
return pandoc.Pandoc(tostring(input)) end
function read(sources)
raw = ""
for _, src in ipairs(sources) do
raw = raw .. src.text
end
return raw
end
-- Calls Pandoc Reader.
function Reader(sources, options)
local raw = read(sources)
local doc = parse(lpeg.match(G, raw))
return pandoc.read(doc, FORMAT, options)
end end