mirror of
https://github.com/Reuh/anselme.git
synced 2025-10-28 00:59:31 +00:00
[doc] standard library documentation first draft
This commit is contained in:
parent
41dede808e
commit
0195913dcc
29 changed files with 2045 additions and 67 deletions
|
|
@ -1,8 +1,14 @@
|
|||
--- # Typed values
|
||||
-- @titlelevel 3
|
||||
|
||||
local ast = require("anselme.ast")
|
||||
local ArgumentTuple, String, Typed, Boolean = ast.ArgumentTuple, ast.String, ast.Typed, ast.Boolean
|
||||
|
||||
return {
|
||||
{
|
||||
--- Call `check(value)` and error if it returns a false value.
|
||||
-- This can be used to ensure a value checking function is verified on a value.
|
||||
-- @defer value checking
|
||||
"_::_", "(value, check)",
|
||||
function(state, value, check)
|
||||
local r = check:call(state, ArgumentTuple:new(value))
|
||||
|
|
@ -15,12 +21,17 @@ return {
|
|||
},
|
||||
|
||||
{
|
||||
--- Returns true if `value` is a typed value, false otherwise.
|
||||
"is typed", "(value)",
|
||||
function(state, v)
|
||||
return Boolean:new(v.type == "typed")
|
||||
end,
|
||||
},
|
||||
{
|
||||
--- Returns the type of `value`.
|
||||
--
|
||||
-- If `value` is a typed value, returns its associated type.
|
||||
-- Otherwise, returns a string of its type (`"string"`, `"number"`, etc.).
|
||||
"type", "(value)",
|
||||
function(state, v)
|
||||
if v.type == "typed" then
|
||||
|
|
@ -31,12 +42,17 @@ return {
|
|||
end
|
||||
},
|
||||
{
|
||||
--- Returns a new typed value with value `value` and type `type`.
|
||||
"type", "(value, type)",
|
||||
function(state, v, t)
|
||||
return Typed:new(v, t)
|
||||
end
|
||||
},
|
||||
{
|
||||
--- Returns the value of `value`.
|
||||
--
|
||||
-- If `value` is a typed value, returns its associated value.
|
||||
-- Otherwise, returns a `value` directly.
|
||||
"value", "(value)",
|
||||
function(state, v)
|
||||
if v.type == "typed" then
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue