mirror of
https://github.com/Reuh/anselme.git
synced 2025-10-27 08:39:30 +00:00
Add stdlib functions from anselme v1
This commit is contained in:
parent
581c60048d
commit
dac5b74fa6
30 changed files with 272 additions and 14 deletions
7
test/results/error.ans
Normal file
7
test/results/error.ans
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
--# run #--
|
||||
--- error ---
|
||||
[0m[31m[0m[31mnope[0m
|
||||
↳ from [4mtest/tests/error.ans:1:6[0m in call: [2merror("nope")[0m[0m
|
||||
↳ from [4m?[0m in block: [2merror("nope")[0m
|
||||
--# saved #--
|
||||
{}
|
||||
13
test/results/floor ceil round.ans
Normal file
13
test/results/floor ceil round.ans
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
--# run #--
|
||||
--- text ---
|
||||
| {}"" {}"3" {}"" |
|
||||
--- text ---
|
||||
| {}"" {}"4" {}"" |
|
||||
--- text ---
|
||||
| {}"" {}"3" {}"" |
|
||||
--- text ---
|
||||
| {}"" {}"3.142" {}"" |
|
||||
--- return ---
|
||||
()
|
||||
--# saved #--
|
||||
{}
|
||||
9
test/results/list find.ans
Normal file
9
test/results/list find.ans
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
--# run #--
|
||||
--- text ---
|
||||
| {}"" {}"3" {}"" |
|
||||
--- text ---
|
||||
| {}"" {}"3" {}"" |
|
||||
--- return ---
|
||||
()
|
||||
--# saved #--
|
||||
{}
|
||||
11
test/results/list insert.ans
Normal file
11
test/results/list insert.ans
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
--# run #--
|
||||
--- text ---
|
||||
| {}"" {}"*[1, 2, 3]" {}"" |
|
||||
--- text ---
|
||||
| {}"" {}"*[1, 2, 3, 4]" {}"" |
|
||||
--- text ---
|
||||
| {}"" {}"*[1, 5, 2, 3, 4]" {}"" |
|
||||
--- return ---
|
||||
()
|
||||
--# saved #--
|
||||
{}
|
||||
9
test/results/list len.ans
Normal file
9
test/results/list len.ans
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
--# run #--
|
||||
--- text ---
|
||||
| {}"" {}"4" {}"" |
|
||||
--- text ---
|
||||
| {}"" {}"4" {}"" |
|
||||
--- return ---
|
||||
()
|
||||
--# saved #--
|
||||
{}
|
||||
11
test/results/list remove.ans
Normal file
11
test/results/list remove.ans
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
--# run #--
|
||||
--- text ---
|
||||
| {}"" {}"*[1, 2, 3, 4, 5]" {}"" |
|
||||
--- text ---
|
||||
| {}"" {}"*[1, 2, 3, 4]" {}"" |
|
||||
--- text ---
|
||||
| {}"" {}"*[1, 3, 4]" {}"" |
|
||||
--- return ---
|
||||
()
|
||||
--# saved #--
|
||||
{}
|
||||
9
test/results/pair name value.ans
Normal file
9
test/results/pair name value.ans
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
--# run #--
|
||||
--- text ---
|
||||
| {}"" {}"foo" {}"" |
|
||||
--- text ---
|
||||
| {}"" {}"barr" {}"" |
|
||||
--- return ---
|
||||
()
|
||||
--# saved #--
|
||||
{}
|
||||
7
test/results/string len.ans
Normal file
7
test/results/string len.ans
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
--# run #--
|
||||
--- text ---
|
||||
| {}"" {}"5" {}"" |
|
||||
--- return ---
|
||||
()
|
||||
--# saved #--
|
||||
{}
|
||||
7
test/results/text concat.ans
Normal file
7
test/results/text concat.ans
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
--# run #--
|
||||
--- text ---
|
||||
| {"a":"b"}"hello" {"b":"c"}"world and " {"b":"c", "x":"y"}"friends" {"b":"c"}"" |
|
||||
--- return ---
|
||||
()
|
||||
--# saved #--
|
||||
{}
|
||||
|
|
@ -77,7 +77,6 @@ local function run(path, interactive)
|
|||
local state = anselme:new()
|
||||
state:load_stdlib()
|
||||
|
||||
state:define("error", "(message=\"error\")", function(message) error(message, 0) end)
|
||||
state:define("interrupt", "(code::string)", function(state, code) state:interrupt(code:to_lua(state), "interrupt") return ast.Nil:new() end, true)
|
||||
state:define("interrupt", "()", function(state) state:interrupt() return ast.Nil:new() end, true)
|
||||
state:define("wait", "(duration::number)", function(duration) coroutine.yield("wait", duration) end)
|
||||
|
|
|
|||
1
test/tests/error.ans
Normal file
1
test/tests/error.ans
Normal file
|
|
@ -0,0 +1 @@
|
|||
error("nope")
|
||||
9
test/tests/floor ceil round.ans
Normal file
9
test/tests/floor ceil round.ans
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
:x = pi
|
||||
|
||||
|{floor(x)}
|
||||
|
||||
|{ceil(x)}
|
||||
|
||||
|{round(x)}
|
||||
|
||||
|{round(x, 0.001)}
|
||||
5
test/tests/list find.ans
Normal file
5
test/tests/list find.ans
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
:l = [5,4,2,1]
|
||||
|
||||
|{l!find(2)}
|
||||
|
||||
|{(*l)!find(2)}
|
||||
11
test/tests/list insert.ans
Normal file
11
test/tests/list insert.ans
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
:l = *[1,2,3]
|
||||
|
||||
|{l}
|
||||
|
||||
l!insert(4)
|
||||
|
||||
|{l}
|
||||
|
||||
l!insert(2, 5)
|
||||
|
||||
|{l}
|
||||
5
test/tests/list len.ans
Normal file
5
test/tests/list len.ans
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
:l = [5,4,2,1]
|
||||
|
||||
|{l!len}
|
||||
|
||||
|{(*l)!len}
|
||||
11
test/tests/list remove.ans
Normal file
11
test/tests/list remove.ans
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
:l = *[1,2,3,4,5]
|
||||
|
||||
|{l}
|
||||
|
||||
l!remove()
|
||||
|
||||
|{l}
|
||||
|
||||
l!remove(2)
|
||||
|
||||
|{l}
|
||||
5
test/tests/pair name value.ans
Normal file
5
test/tests/pair name value.ans
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
:a = "foo":"barr"
|
||||
|
||||
|{a!name}
|
||||
|
||||
|{a!value}
|
||||
3
test/tests/string len.ans
Normal file
3
test/tests/string len.ans
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
:x = "hÉllo"
|
||||
|
||||
|{x!len}
|
||||
5
test/tests/text concat.ans
Normal file
5
test/tests/text concat.ans
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
:a = ("a":"b" # | hello)
|
||||
|
||||
:b = ("b":"c" # | world and { "x":"y" # |friends })
|
||||
|
||||
a+b
|
||||
Loading…
Add table
Add a link
Reference in a new issue