Fennel is now embeded
This commit is contained in:
parent
a36006cee2
commit
ab643376b1
|
@ -1,11 +1,11 @@
|
|||
# Variables
|
||||
NAME="fennel-1.3.0"
|
||||
URL="https://fennel-lang.org/downloads/$NAME"
|
||||
ASC="https://fennel-lang.org/downloads/$NAME.asc"
|
||||
DIR=$(git rev-parse --show-toplevel)
|
||||
ROOT=$(git rev-parse --show-toplevel)
|
||||
URL="https://fennel-lang.org/downloads/$NAME.tar.gz"
|
||||
|
||||
# Copies Fennel from release tarball
|
||||
cd $DIR/src
|
||||
curl -o fennel $URL
|
||||
chmod +x fennel
|
||||
|
||||
cd $ROOT/src
|
||||
curl -O $URL
|
||||
tar -xvzf $NAME.tar.gz
|
||||
mv $NAME/fennel.lua .
|
||||
rm -rf $NAME*
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -4,11 +4,14 @@ literate.lua
|
|||
Code under GPLv3 <https://www.gnu.org/licenses/gpl-3.0.en.html>
|
||||
]]
|
||||
|
||||
-- Gets source root directory and Fennel path
|
||||
-- This will allow to use Lisp inside Lua
|
||||
-- Cfr. https://fennel-lang.org
|
||||
-- Initial setup
|
||||
-- 1. Gets 'src' dir path
|
||||
-- 2. Enables Fennel for Lisp-Lua embeded compatibility
|
||||
-- Cfr. https://fennel-lang.org
|
||||
local src_root = pandoc.path.directory(PANDOC_SCRIPT_FILE)
|
||||
local fennel = pandoc.path.join({src_root, "fennel"})
|
||||
local fennel_lua = pandoc.path.join({src_root, "fennel.lua"})
|
||||
package.path = package.path .. ";" .. fennel_lua
|
||||
local fennel = require("fennel")
|
||||
|
||||
--[[
|
||||
-- Lua LPeg shortcuts
|
||||
|
@ -38,16 +41,19 @@ G = P{
|
|||
|
||||
-- Evals Lisp code
|
||||
-- @param code string: code to evaluate
|
||||
-- @return table: code evaluated as a table of lines
|
||||
-- @return table: evaluation result as {bool, string, string, string}
|
||||
local function eval(code)
|
||||
local res = {}
|
||||
local cmd = fennel .. " -e '" .. code .. "' 2>&1"
|
||||
local handle = io.popen(cmd)
|
||||
for line in handle:lines() do
|
||||
table.insert(res, line)
|
||||
is_passed, out = pcall (
|
||||
function () return fennel.eval(code) end,
|
||||
function (e) return e end
|
||||
)
|
||||
lua = ""
|
||||
out = tostring(out)
|
||||
preview = out:gsub("\n.*", "")
|
||||
if is_passed then
|
||||
lua = fennel.compileString(code)
|
||||
end
|
||||
handle:close()
|
||||
return res
|
||||
return {is_passed = is_passed, preview = preview, out = out, lua = lua}
|
||||
end
|
||||
|
||||
return {
|
||||
|
@ -57,9 +63,9 @@ return {
|
|||
local raw = block.text
|
||||
print("⚙️ ", raw)
|
||||
local res = eval(raw)
|
||||
print("", "=>", res[1])
|
||||
print("", res["is_passed"], "→", res["preview"])
|
||||
if block.classes:includes("replace") then
|
||||
return pandoc.CodeBlock(table.concat(res, "\n"), {code=raw})
|
||||
return pandoc.CodeBlock(res["out"], {code=raw})
|
||||
end
|
||||
end
|
||||
end,
|
||||
|
|
|
@ -7,7 +7,7 @@ Evals:
|
|||
(+ 7 8 9)
|
||||
#+end_src
|
||||
|
||||
Fails:
|
||||
Doesn't eval:
|
||||
|
||||
#+begin_src eval replace
|
||||
(+ 7 8 9)
|
||||
|
|
Loading…
Reference in New Issue