aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorBruce Hill <bitbucket@bruce-hill.com>2017-09-19 00:29:31 -0700
committerBruce Hill <bitbucket@bruce-hill.com>2017-09-19 00:29:31 -0700
commit0ee5b5888208dff29881869d9dc3595025b515c0 (patch)
tree22ea59b41a77f36afeec52633029d12ebcb772fd /lib
parent2c4acdfe67e05fba88d4c48509c8767d2dce358b (diff)
Buncha updates to the sample code and core lib.
Diffstat (limited to 'lib')
-rw-r--r--lib/plurals.nom34
-rw-r--r--lib/secrets.nom39
2 files changed, 73 insertions, 0 deletions
diff --git a/lib/plurals.nom b/lib/plurals.nom
new file mode 100644
index 0000000..f25536b
--- /dev/null
+++ b/lib/plurals.nom
@@ -0,0 +1,34 @@
+run file "lib/secrets.nom"
+
+# Plurals
+with secrets:
+ lua block ".."
+ |local endings = setmetatable({x="es",c="es",s="es"}, {__index=function() return "s" end})
+ |secrets.plurals = setmetatable({}, {__index=function(self,key)
+ | return key..endings[key:sub(-1)]
+ |end})
+ |secrets.singulars = setmetatable({}, {__index=function(self,key)
+ | if key:sub(-2) == "es" and rawget(endings, key:sub(-3,-3)) then return key:sub(1,-3) end
+ | if key:sub(-1) == "s" then return key:sub(1,-2) end
+ | return key
+ |end})
+ |secrets.canonicals = setmetatable({}, {__index=function(self,key)
+ | if key:sub(-1) == "s" then return secrets.singulars[key] end
+ | return key
+ |end})
+
+ rule: the plural of %singular is %plural ..=:
+ (secret %plurals)->%singular =: %plural
+ (secret %singulars)->%plural =: %singular
+ (secret %canonicals)->%plural =: %singular
+
+ rule: singular %plural ..=:
+ %plural in (secret %singulars)
+
+ rule: plural %singular ..=:
+ %singular in (secret %plurals)
+
+ rule: canonicalize %item-name ..=:
+ %item-name in (secret %canonicals)
+
+ rule: rules that change plurals ..=: ["the plural of % is %"]
diff --git a/lib/secrets.nom b/lib/secrets.nom
new file mode 100644
index 0000000..da6942e
--- /dev/null
+++ b/lib/secrets.nom
@@ -0,0 +1,39 @@
+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