Dummy ready
This commit is contained in:
parent
0ba2e10fc6
commit
a786c4f227
10
README.md
10
README.md
|
@ -1,10 +1,8 @@
|
|||
# Literate Pandoc
|
||||
|
||||
[Pandoc] is a world famous "swiss-army" document converted. This is because
|
||||
Pandoc is also a document parser. Thanks to this capability, this repo is a
|
||||
[Pandoc reader] written in [Lua] for [literate] and [natural] programming
|
||||
(LNP), i.e.: "[Programming \[...\] as the process of creating works of
|
||||
literature][1]".
|
||||
Literate Pandoc is a [Pandoc reader] written in [Lua] for [literate] and
|
||||
[natural] programming (LNP), i.e.: "[Programming \[...\] as the process of
|
||||
creating works of literature][1]".
|
||||
|
||||
## Requirements
|
||||
|
||||
|
@ -68,12 +66,12 @@ Literate Pandoc is under [GPLv3].
|
|||
|
||||
Happy hacking :)
|
||||
|
||||
[Pandoc]: https://pandoc.org/
|
||||
[Pandoc reader]: https://pandoc.org/custom-readers.html
|
||||
[Lua]: https://www.lua.org/
|
||||
[literate]: https://en.wikipedia.org/wiki/Literate_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
|
||||
[Pandoc]: https://pandoc.org/
|
||||
[Releases]: https://git.cuates.net/perro/literate-pandoc/releases
|
||||
[here]: https://git.cuates.net/perro/literate-pandoc/src/branch/no-masters/man/README.md
|
||||
[Fennel]: https://fennel-lang.org
|
||||
|
|
|
@ -22,7 +22,7 @@ if [ -z "$ARGS" ]; then
|
|||
fi
|
||||
|
||||
# Does tests
|
||||
echo "🐾 Starting tests"
|
||||
clear && echo "🐾 Starting tests"
|
||||
for arg in "$ARGS"; do
|
||||
echo && echo "⚗️ Test in '$arg' format:"
|
||||
mds=$'\n\n'`(pandoc -t markdown tests/*.md)`
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
-------------------------------------------------------------------------------
|
||||
-- IMPORTANT: these lines are for development setup
|
||||
-- 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
|
||||
local src_root = pandoc.path.directory(PANDOC_SCRIPT_FILE)
|
||||
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")
|
||||
-------------------------------------------------------------------------------
|
||||
|
||||
------------------------------- GRAMMAR related -------------------------------
|
||||
|
||||
-- Ordered collection of fn call, fn declarations or literal elements
|
||||
local collection = {}
|
||||
|
||||
-- Lua LPeg shortcuts
|
||||
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.Cs, lpeg.Cg, lpeg.Cb, lpeg.B, lpeg.C, lpeg.Cmt
|
||||
|
||||
-- Lexical elements
|
||||
local space = S(" \t\r\n")
|
||||
local lbracket = P"("
|
||||
local rbracket = P")"
|
||||
local word = (1 - (space + lbracket + rbracket))
|
||||
local space = S" \t\r\n"
|
||||
local spot = (1 - space) -- TMP
|
||||
local t1 = S"()" -- TMP
|
||||
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
|
||||
G = P{
|
||||
G = P {
|
||||
"Doc";
|
||||
Doc = space^0 * Ct(V"SExpr"^0) * space^0 / pandoc.Pandoc;
|
||||
SExpr = (V"List" + V"Atom");
|
||||
List = lbracket * V"SExpr"^0 * rbracket;
|
||||
Atom = space + V"Word";
|
||||
Word = word^1 / pandoc.Str;
|
||||
Doc = (V"Call" + V"Declaration" + V"Literal")^0;
|
||||
Call = t1^1 / add_call;
|
||||
Declaration = t2^1 / add_declaration;
|
||||
Literal = space^1 / add_lit;
|
||||
}
|
||||
|
||||
--------------------------------- LNP related ---------------------------------
|
||||
|
||||
-- Evals Lisp code
|
||||
-- @param code string: code to evaluate
|
||||
-- @return table: evaluation result as {bool, string, string, string}
|
||||
local function eval(code)
|
||||
local is_passed, out = pcall (
|
||||
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}
|
||||
end
|
||||
|
||||
-- Calls Pandoc Reader.
|
||||
function Reader(input, options)
|
||||
--[[
|
||||
local doc = lpeg.match(G, tostring(input))
|
||||
if options.standalone then
|
||||
return exec(doc)
|
||||
else
|
||||
return doc
|
||||
function parse(_)
|
||||
local doc = ""
|
||||
for i, t in ipairs(collection) do
|
||||
for k, v in pairs(t) do
|
||||
print(i, k, v)
|
||||
doc = doc .. v
|
||||
end
|
||||
end
|
||||
]]--
|
||||
return pandoc.Pandoc(tostring(input))
|
||||
return doc
|
||||
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
|
||||
|
|
Loading…
Reference in New Issue