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