nomsu/lib/secrets.nom
2017-09-19 00:35:37 -07:00

42 lines
1.3 KiB
Plaintext

require "lib/core.nom"
macro block: with secrets %block
..=: ".."
|local secrets = {}
|\((%block's "value")'s "value") as lua block\
macro block: with secrets as %secret_name %block
..=: ".."
|local \%secret_name as value\ = {}
|\((%block's "value")'s "value") as lua block\
macro: secrets
..=: "secrets"
macro:
secret %key
secret value of %key
secret value for %key
..=:
if (((%key ->"value")->"type") != "Var"):
error ".."
|Wrong type, expected Var, but got: \(%key ->"value")->"type"\
".."|secrets[\repr ((%key -> "value")->"value")\]
macro block: secret %key = %value
..=:
lua block ".."
|if vars.key.value.type ~= "Var" then
| compiler:error("Assignment operation has the wrong type for the left hand side. "
| .."Expected Var, but got: "..vars.key.value.type)
|end
|if vars.value.value.type ~= "Thunk" then
| compiler:error("Assignment operation has the wrong type for the right hand side. "
| .."Expected Thunk, but got: "..vars.value.value.type.."\\nMaybe you used '=' instead of '=:'?")
|end
".."|do
| local ret
| \lua expr "compiler:tree_to_lua(vars.value.value.value, 'Statement')"\
| secrets[\repr ((%key -> "value")->"value")\] = ret
|end