1
0
Fork 0
mirror of https://github.com/Reuh/anselme.git synced 2025-10-27 08:39:30 +00:00

Prefix type checkers with "is", stdlib cleanup

This commit is contained in:
Étienne Fildadut 2024-01-06 15:00:08 +01:00
parent 98917c2ca4
commit 7f71569e07
25 changed files with 163 additions and 160 deletions

View file

@ -76,9 +76,9 @@ local function run(path, interactive)
local state = anselme:new()
state:load_stdlib()
state:define("interrupt", "(code::string)", function(state, code) state:interrupt(code:to_lua(state), "interrupt") return ast.Nil:new() end, true)
state:define("interrupt", "(code::is 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)
state:define("wait", "(duration::is number)", function(duration) coroutine.yield("wait", duration) end)
state:define("run in new branch", "(code)", function(code)
local parallel_state = state:branch()
write_output("--# parallel script #--")
@ -87,7 +87,7 @@ local function run(path, interactive)
write_output("--# main script #--")
end)
state:define("serialize", "(value)", function(state, value) return ast.String:new(value:serialize(state)) end, true)
state:define("deserialize", "(str::string)", function(state, str) return ast.abstract.Node:deserialize(state, str.string) end, true)
state:define("deserialize", "(str::is string)", function(state, str) return ast.abstract.Node:deserialize(state, str.string) end, true)
local run_state = state:branch()
@ -123,7 +123,7 @@ end
if not arg[1] or arg[1] == "update" then
-- display an animated loading indicator
local loading = {
loop = { "", "", "", "", "", "", "", "" },
loop = { "", "", "", "", "", "", "", "" },
loop_pos = 1,
erase_code = "",

View file

@ -1,7 +1,7 @@
:$ a - b
return("generic minus")
:$ a::string - b::string
:$ a::is string - b::is string
return(a + " minus " + b)
| {2-5}

View file

@ -7,7 +7,7 @@
|v={v}
a = v
:$ f(p) = v::string
:$ f(p) = v::is string
|v2={v}
a = p

View file

@ -1,8 +1,8 @@
:$ a(x::number)
:$ a(x::is number)
return(x + 2)
:$ x
:$ a(x::string)
:$ a(x::is string)
return(x + "heh")
|{a("plop")}

View file

@ -1,7 +1,7 @@
:$ fn(x::number)
:$ fn(x::is number)
|x
:$ fn(a::number)
:$ fn(a::is number)
|a
fn(5)

View file

@ -1,7 +1,7 @@
:$ fn(x::number)
:$ fn(x::is number)
|x
:$ fn(a::string="o")
:$ fn(a::is string="o")
|a
fn("s")
@ -10,10 +10,10 @@ fn(5)
fn()
:$ g(n="s", a::number=5)
:$ g(n="s", a::is number=5)
return("gn")
:$ g(n="s", a::string="lol")
:$ g(n="s", a::is string="lol")
return("gs")
|{g(n="k", a="l")}

View file

@ -1,7 +1,7 @@
:$ fn(x::number)
:$ fn(x::is number)
|x
:$ fn(a::string)
:$ fn(a::is string)
|a
fn("s")

View file

@ -1,6 +1,6 @@
:f = ()
_
:$_+_(a::string, b)
:$_+_(a::is string, b)
"{a}{b}"
:a=1

View file

@ -1,7 +1,7 @@
:$ -f
return("generic minus")
:$ -f::string
:$ -f::is string
return("minus "+f)
|{-5}