Implemented luarocks for external modules

This commit is contained in:
perro tuerto 2023-05-12 16:23:33 -07:00
parent 26a62a3f25
commit 86a4be358f
20 changed files with 7120 additions and 217 deletions

View File

@ -46,14 +46,18 @@ For other kind of tests, do:
pandoc lua scripts/test.lua -h
For other scripts, do:
pandoc lua scripts/SCRIPT
For example, do:
For make distribution filter, do:
pandoc lua scripts/make_dist.lua
For make jsons (intented for testing asserts), do:
pandoc lua scripts/make_jsons.lua
For update Lua modules (needs [`luarocks`]), do:
sh scripts/get_rocks.sh
Contribute!
## Acknowledgments
@ -80,6 +84,7 @@ Happy hacking :)
[Pandoc]: https://pandoc.org/
[Releases]: https://git.cuates.net/perro/computable-pandoc/releases
[here]: https://git.cuates.net/perro/computable-pandoc/src/branch/no-masters/man/README.md
[`luarocks`]: https://luarocks.org/
[Fennel]: https://fennel-lang.org
[Lisp]: https://en.wikipedia.org/wiki/Lisp_(programming_language)
[GPLv3]: https://git.cuates.net/perro/computable-pandoc/src/branch/no-masters/LICENSE.txt

15
dist/lin.lua vendored
View File

@ -6259,8 +6259,6 @@ do
end
local fnl = mod
---------------------------------- EXTENSIONS ---------------------------------
-- Tries popen
-- @param ... string: Chunks for popen
-- @return boolean, string: Status and output of popen
@ -6744,13 +6742,15 @@ function lit.exam(doc)
["lisp"] = {["ext"] = "TODO"},
["graphviz"] = {["ext"] = "TODO"},
}
-- Prints error and does not pass the check
local function putserr(...)
lit.puts(...)
ispass = false
end
-- Checks language and command
-- Adds 'eval' key in meta
-- This keys indicates what to eval
local function addeval(meta)
meta["eval"] = {}
if ispass then
@ -6766,7 +6766,6 @@ function lit.exam(doc)
meta["eval"] = {["ext"] = meta["cmd"]}
end
end
print(meta["lang"], meta["eval"]["int"], meta["eval"]["ext"])
return meta
end
@ -6846,7 +6845,6 @@ function lit.exam(doc)
local meta = {}
if isok and not(pandoc.utils.stringify(res.meta):isempty()) then
meta = pandoc.metatotable(res.meta)
-- These 3 checks should
checkmeta(meta, "mandatory")
checkmeta(meta, "optional")
checkextra(meta)
@ -6863,9 +6861,7 @@ function lit.exam(doc)
local meta = parsemeta(parsed[1])
-- TODO:
-- meta["code"] = checkcode(parsed[2], meta)
-- TODO: checks for
-- overrides (warn)
-- return meta
-- NOTE: if not valid code, return meta["eval"] = {}
return meta
end
@ -6873,6 +6869,7 @@ function lit.exam(doc)
local checked = (parsed ~= nil and check(parsed) or parsed)
-- TODO:
-- evaluated = eval(checked)
-- TODO: write evaluated and do overrides with warns
-- return evaluated
return codeblock
end

3
opt/bin/fennel Executable file
View File

@ -0,0 +1,3 @@
#!/bin/sh
LUAROCKS_SYSCONFDIR='/etc/luarocks' exec '/usr/bin/lua5.4' -e 'package.path="/home/perro/Repositorios/computable-pandoc/opt/share/lua/5.4/?.lua;/home/perro/Repositorios/computable-pandoc/opt/share/lua/5.4/?/init.lua;"..package.path;package.cpath="/home/perro/Repositorios/computable-pandoc/opt/lib/lua/5.4/?.so;"..package.cpath;local k,l,_=pcall(require,"luarocks.loader") _=k and l.add_context("fennel","1.3.0-1")' '/home/perro/Repositorios/computable-pandoc/opt/lib/luarocks/rocks-5.4/fennel/1.3.0-1/bin/fennel' "$@"

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,21 @@
MIT License
Copyright © 2016-2022 Calvin Rose and contributors
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View File

@ -0,0 +1,129 @@
# Fennel
[Fennel][1] is a lisp that compiles to Lua. It aims to be easy to use,
expressive, and has almost zero overhead compared to writing Lua directly.
* *Full Lua compatibility* - You can use any function or library from Lua.
* *Zero overhead* - Compiled code should be just as efficient as hand-written Lua.
* *Compile-time macros* - Ship compiled code with no runtime dependency on Fennel.
* *Embeddable* - Fennel is a one-file library as well as an executable. Embed it in other programs to support runtime extensibility and interactive development.
At [https://fennel-lang.org][1] there's a live in-browser repl you can
use without installing anything. At [https://fennel-lang.org/see][3]
you can see what Lua output a given piece of Fennel compiles to, or
what the equivalent Fennel for a given piece of Lua would be.
## Documentation
* The [setup](setup.md) guide is a great place to start
* The [tutorial](tutorial.md) teaches the basics of the language
* The [rationale](rationale.md) explains the reasoning of why Fennel was created
* The [reference](reference.md) describes all Fennel special forms
* The [macro guide](macros.md) explains how to write macros
* The [API listing](api.md) shows how to integrate Fennel into your codebase
* The [style guide](style.md) gives tips on how to write clear and concise code
* The [Lua primer](lua-primer.md) gives a very brief intro to Lua with
pointers to further details
For more examples, see [the cookbook][2] on [the wiki][7].
The [changelog](changelog.md) has a list of user-visible changes for
each release.
## Example
#### Hello World
```Fennel
(print "hello, world!")
```
#### Fibonacci sequence
```Fennel
(fn fib [n]
(if (< n 2)
n
(+ (fib (- n 1)) (fib (- n 2)))))
(print (fib 10))
```
## Building Fennel from source
Building Fennel from source allows you to use versions of Fennel that
haven't been released, and it makes contributing to Fennel easier.
### To build Fennel from source
1. `cd` to a directory in which you want to download Fennel, such as
`~/src`
2. Run `git clone https://git.sr.ht/~technomancy/fennel`
3. Run `cd fennel`
4. Run `make fennel` to create a standalone script called `fennel`
5. Copy or link the `fennel` script to a directory on your `$PATH`, such as `/usr/local/bin`
**Note**: If you copied the `fennel` script to one of the
directories on your `$PATH`, then you can run `fennel filename.fnl` to
run a Fennel file anywhere on your system.
## Differences from Lua
* Syntax is much more regular and predictable (no statements; no operator precedence)
* It's impossible to set *or read* a global by accident
* Pervasive destructuring anywhere locals are introduced
* Clearer syntactic distinction between sequential tables and key/value tables
* Separate looping constructs for numeric loops vs iterators instead of overloading `for`
* Opt-in mutability for local variables
* Opt-in nil checks for function arguments
* Pattern matching
* Ability to extend the syntax with your own macros
## Differences from other lisp languages
* Its VM can be embedded in other programs with only 180 kB
* Access to [excellent FFI][4]
* LuaJIT consistently ranks at the top of performance shootouts
* Inherits aggressively simple semantics from Lua; easy to learn
* Lua VM is already embedded in databases, window managers, games, etc
* Low memory usage
* Readable compiler output resembles input
## Why not Fennel?
Fennel inherits the limitations of the Lua runtime, which does not offer
pre-emptive multitasking or OS-level threads. Libraries for Lua work
great with Fennel, but the selection of libraries is not as extensive
as it is with more popular languages. While LuaJIT has excellent
overall performance, purely-functional algorithms will not be as
efficient as they would be on a VM with generational garbage collection.
Even for cases where the Lua runtime is a good fit, Fennel might not
be a good fit when end-users are expected to write their own code to
extend the program, because the available documentation for learning
Lua is much more readily-available than it is for Fennel.
## Resources
* Join the `#fennel` chat [thru IRC on Libera.Chat][9] or [on Matrix][10]
* The [mailing list][5] has slower-paced discussion and announcements
* Report issues on the mailing list, [Sourcehut todo][11] or [Github issues][12]
* You can browse and edit [the Wiki][7]
* View builds in Fennel's [continuous integration][8]
* Community interactions are subject to the [code of conduct](CODE-OF-CONDUCT.md).
## License
Copyright © 2016-2023 Calvin Rose and contributors
Released under the [MIT license](LICENSE).
[1]: https://fennel-lang.org
[2]: https://wiki.fennel-lang.org/Cookbook
[3]: https://fennel-lang.org/see
[4]: http://luajit.org/ext_ffi_tutorial.html
[5]: https://lists.sr.ht/%7Etechnomancy/fennel
[7]: https://wiki.fennel-lang.org/
[8]: https://builds.sr.ht/~technomancy/fennel
[9]: https://libera.chat
[10]: https://matrix.to/#/!rnpLWzzTijEUDhhtjW:matrix.org?via=matrix.org
[11]: https://todo.sr.ht/~technomancy/fennel
[12]: https://github.com/bakpakin/Fennel/issues

View File

@ -0,0 +1,8 @@
package = "fennel"
local fennel_version = "1.3.0"
version = (fennel_version .. "-1")
source = {url = ("https://fennel-lang.org/downloads/fennel-" .. fennel_version .. ".tar.gz")}
description = {summary = "A lisp that compiles to Lua", detailed = ("Get your parens on--write macros and " .. "homoiconic code on the Lua runtime!"), license = "MIT", homepage = "https://fennel-lang.org/"}
dependencies = {"lua >= 5.1"}
build = {type = "builtin", install = {bin = {fennel = "fennel"}}, modules = {fennel = "fennel.lua"}}
return nil

View File

@ -0,0 +1,13 @@
rock_manifest = {
bin = {
fennel = "18b74a4083bcb33ebf161b339c82bf5f"
},
doc = {
LICENSE = "3e5a2c7152ee8b5c8d34815a16195a52",
["README.md"] = "a7f18dbb5131d2b23aad4fb1b55a31a6"
},
["fennel-1.3.0-1.rockspec"] = "c7300e84d68e04c9c2f900c685458024",
lua = {
["fennel.lua"] = "7e6bcb21700f66be5c027f3994d645de"
}
}

View File

@ -0,0 +1,11 @@
# Lua Dog
Adds functions to Lua Standard Libraries.
## Install
luarocks install lua-dog
## Functions
Check `src`.

View File

@ -0,0 +1,22 @@
package = "lua-dog"
version = "1.0-0"
source = {
url = "https://gitlab.com/perritotuerto/codigo/lua-dog/-/archive/v1.0.0/lua-dog-v1.0.0.tar.gz",
}
description = {
summary = "Lua extensions for lazy dogs",
detailed = [[
Adds functions to Lua Standard Libraries.
]],
homepage = "https://gitlab.com/perritotuerto/codigo/lua-dog/",
license = "GPLv3",
}
dependencies = {
"lua >= 5.4, < 5.5"
}
build = {
type = "builtin",
modules = {
dog = "src/dog.lua"
}
}

View File

@ -0,0 +1,9 @@
rock_manifest = {
doc = {
["README.md"] = "907b5c835edf49975acca8a960917c5a"
},
lua = {
["dog.lua"] = "5796081a406363115798e70935347385"
},
["lua-dog-1.0-0.rockspec"] = "c7c9e3c60f29029838348eb8ecfe3cc9"
}

View File

@ -0,0 +1,79 @@
commands = {
fennel = {
"fennel/1.3.0-1"
}
}
dependencies = {
fennel = {
["1.3.0-1"] = {
{
constraints = {
{
op = ">=",
version = {
5, 1, string = "5.1"
}
}
},
name = "lua"
}
}
},
["lua-dog"] = {
["1.0-0"] = {
{
constraints = {
{
op = ">=",
version = {
5, 4, string = "5.4"
}
},
{
op = "<",
version = {
5, 5, string = "5.5"
}
}
},
name = "lua"
}
}
}
}
modules = {
dog = {
"lua-dog/1.0-0"
},
fennel = {
"fennel/1.3.0-1"
}
}
repository = {
fennel = {
["1.3.0-1"] = {
{
arch = "installed",
commands = {
fennel = "fennel"
},
dependencies = {},
modules = {
fennel = "fennel.lua"
}
}
}
},
["lua-dog"] = {
["1.0-0"] = {
{
arch = "installed",
commands = {},
dependencies = {},
modules = {
dog = "dog.lua"
}
}
}
}
}

View File

@ -1,5 +1,3 @@
---------------------------------- EXTENSIONS ---------------------------------
-- Tries popen
-- @param ... string: Chunks for popen
-- @return boolean, string: Status and output of popen

View File

@ -1,11 +0,0 @@
# Downloads Fennel
# Variables
NAME="fennel-1.3.0"
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/fennel/
rm -rf $NAME*

16
scripts/get_rocks.sh Normal file
View File

@ -0,0 +1,16 @@
# Downloads Lua Modules
# Variables
ROOT=$(dirname $0)/..
# Goes to root directory
cd $ROOT
# Gets modules from luarocks
if type luarocks > /dev/null 2>&1; then
luarocks install fennel --tree opt
luarocks install lua-dog --tree opt
else
echo "ERROR: luarocks is required; see <https://luarocks.org/>"
exit 1
fi

View File

@ -1,7 +1,11 @@
-- Makes bundle distribution
-- Adds local luarocks modules
local optpath = "./opt/share/lua/5.4/"
package.path = optpath .. "?.lua;" .. package.path
-- Adds Lua custom extensions
require "opt.lua-extensions.extensions"
require "dog"
-- Makes distribution
local function make_dist()
@ -19,8 +23,8 @@ local function make_dist()
-- Variables
local name = "lin.lua"
local dist = pandoc.path.join({"dist", name})
local ext = chomp("opt/lua-extensions/extensions.lua")
local fnl = chomp("opt/fennel/fennel.lua", true)
local ext = chomp(optpath .. "dog.lua")
local fnl = chomp(optpath .. "fennel.lua", true)
local pan = chomp("src/pandoc.lua")
local nat = chomp("src/natural.lua", true)
local lit = chomp("src/literate.lua", true)

View File

@ -1,7 +1,10 @@
-- Makes JSON test files
-- Adds local luarocks modules
package.path = "./opt/share/lua/5.4/?.lua;" .. package.path
-- Adds Lua custom extensions
require "opt.lua-extensions.extensions"
require "dog"
-- Variables
local filter = "dist/lin.lua"

View File

@ -1,7 +1,10 @@
-- Makes tests
-- Adds local luarocks modules
package.path = "./opt/share/lua/5.4/?.lua;" .. package.path
-- Adds Lua custom extensions
require "opt.lua-extensions.extensions"
require "dog"
require "scripts.make_dist"
-- Variables

View File

@ -1,185 +0,0 @@
# Inserts Before Blocks
- `fn1()``fn2()`
- `fn3(true)`
- `fn4(2.0, 3.1)`
- `fn3(n: false)`
- `fn4(b: 4, a: 5)`
# Literate Blocks
All literate blocks should be print on `--verbose`.
Minimal (Lua by default):
---
id: fn1
...
1 + 2 + 3
With scape:
---
id: fn2
...
"\#x"
With arg:
---
id: fn3
args:
n: str
...
#n == #n
With lang and args:
---
id: fn4
lang: fennel
args:
a: 1
b: 2
...
(* #a #b)
With cmd (ignores lang):
---
id: fn5
cmd: python -E -X utf8
args:
n: 2
...
#n + #n
With shift:
---
id: fn6
shift: true
...
"The literate block is shifted by its eval result."
With wipe:
---
id: fn7
wipe: true
...
"This evals but it is wipe from doc."
With typed:
---
id: fn4
typed: true
args:
a: 1
b: 2
...
#a * #b
With link and alt:
---
id: fn8
lang: graphviz
link: ./graph.png
alt: A graph.
...
digraph G {
a -> b;
b -> c
c -> a;
}
With img and alt:
---
id: fn9
lang: graphviz
img: ./graph.png
alt: A graph.
...
digraph G {
a -> b;
b -> c
c -> a;
}
With dump and quote:
---
id: fn10
dump: ./dump.txt
quote: true
...
This code is saved into './dump.txt' because of 'dump'.
This code is not evaluated because 'quote' is true.
With inner function:
---
id: fn11
args:
x: 2
...
#fn1() * x
With inner function with args:
---
id: fn12
args:
y: 1
z: 2
...
#y + #fn4(3, 4) + #z
With inner inner function:
---
id: fn13
args:
a: 1
...
#a + #fn4(#a, #fn1())
# Code Blocks
Always ignored:
---
echo "Ignore me!"
# Inserts and Data Types
- `fn3(true)`
- `fn3(false)`
- `fn3([])`
- `fn3([0, 1])`
- `fn3({})`
- `fn3({"k1": 1, "k2": 2})`
- `fn4(3)`
- `fn5(1.0)`
- `fn5("str")`
# Messy Inserts
- `fn1( )`
- `fn3("\"str\"")`
- `fn3( 4)`
- `fn3(5 )`
- `fn3( 6 )`
- `fn3( n: 7)`
- `fn3(n: 8 )`
- `fn3( n: 9 )`
- `fn3(n:10)`
- `fn4( a: 6, b: 7)`
- `fn4( a: 8 , b: 9)`
- `fn4( a: 10 , b: 11)`
- `fn4( a: 12 , b: 13)`
- `fn4( a: 14 , b: 15 )`
- `fn4(a:16,b:17)`