aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/core.nom1
-rw-r--r--lib/permissions.nom16
-rw-r--r--lib/utils.nom3
-rw-r--r--lib/utils2.nom10
-rw-r--r--nomsu.lua11
-rwxr-xr-xnomsu.moon9
6 files changed, 35 insertions, 15 deletions
diff --git a/lib/core.nom b/lib/core.nom
index f00bd22..d5517f2 100644
--- a/lib/core.nom
+++ b/lib/core.nom
@@ -3,4 +3,5 @@ require "lib/utils.nom"
require "lib/operators.nom"
require "lib/control_flow.nom"
require "lib/collections.nom"
+require "lib/utils2.nom"
require "lib/permissions.nom"
diff --git a/lib/permissions.nom b/lib/permissions.nom
index c60471e..543938f 100644
--- a/lib/permissions.nom
+++ b/lib/permissions.nom
@@ -6,14 +6,14 @@ require "lib/collections.nom"
# Permission functions
rule [standardize rules %rules] =:
if ((type of %rules) == "string"): %rules = [%rules]
- (nomsu "get_stub" [%]) for all %rules
+ %stubs = (nomsu "get_stubs" [%rules])
%result = []
- for %rule in %rules:
- %stub = (nomsu "get_stub" [%rule])
+ for %stub in %stubs:
%def = ((nomsu's "defs")->%stub)
- assert %def "Undefined rule: \(%stub)"
- %aliases = (%def's "aliases")
- for all %aliases: add % to %result
+ if %def:
+ %aliases = (%def's "aliases")
+ for all %aliases: add % to %result
+ ..else: add %def to %result
unique %result
rule [restrict %rules to within %elite_rules] =:
@@ -52,3 +52,7 @@ rule [forbid %pleb_rules to use %rules] =:
|Cannot individually restrict permissions for \(%) because it is currently
|available to everyone. Perhaps you meant to use "restrict % to within %" instead?
for all %pleb_rules: %whiteset's % = (nil)
+
+parse [rule %spec = %body restricted to %elite_rules] as:
+ rule %spec = %body
+ restrict (nomsu "get_stubs" [\%spec]) to within %elite_rules
diff --git a/lib/utils.nom b/lib/utils.nom
index b398827..965d338 100644
--- a/lib/utils.nom
+++ b/lib/utils.nom
@@ -27,9 +27,6 @@ compile [%str with %patt replaced with %sub, %str s/%patt/%sub] to:
compile [%str with %patt replaced with %sub %n times, %str s/%patt/%sub/%n] to:
"((\(%str as lua)):gsub(\(%patt as lua), \(%sub as lua), \(%n as lua)))"
-compile [say %str] to: ".."
- |nomsu:writeln(nomsu:stringify(\(%str as lua)))
-
# Number ranges
compile [%start to %stop by %step, %start to %stop via %step] to: ".."
|nomsu.utils.range(\(%start as lua), \(%stop as lua), \(%step as lua))
diff --git a/lib/utils2.nom b/lib/utils2.nom
new file mode 100644
index 0000000..2562471
--- /dev/null
+++ b/lib/utils2.nom
@@ -0,0 +1,10 @@
+require "lib/metaprogramming.nom"
+require "lib/utils.nom"
+require "lib/control_flow.nom"
+require "lib/operators.nom"
+
+compile [say %str] to:
+ if ((%str's "type") == "String"):
+ "nomsu:writeln(\(%str as lua))"
+ ..else:
+ "nomsu:writeln(nomsu:stringify(\(%str as lua)))"
diff --git a/nomsu.lua b/nomsu.lua
index da0c699..f7182ba 100644
--- a/nomsu.lua
+++ b/nomsu.lua
@@ -479,7 +479,12 @@ end);]]):format(statements or "", expr or "ret")
self:errorln(debug.traceback())
self:error(ret)
end
- insert(buffer, tostring(statements or '') .. "\n" .. tostring(expr and "ret = " .. tostring(expr) .. ";" or ''))
+ if statements then
+ insert(buffer, statements)
+ end
+ if expr then
+ insert(buffer, "ret = " .. tostring(expr) .. ";")
+ end
end
if max_operations then
debug.sethook()
@@ -488,7 +493,7 @@ end);]]):format(statements or "", expr or "ret")
local ret;
%s
return ret;
-end);]]):format(concat(buffer, ""))
+end);]]):format(concat(buffer, "\n"))
return return_value, lua_code, vars
end,
tree_to_value = function(self, tree, vars)
@@ -911,7 +916,7 @@ end)]]):format(concat(lua_bits, "\n"))
end
return concat(stub, " "), arg_names
else
- return self:error("Unsupported get stub type: " .. tostring(x.type))
+ return self:error("Unsupported get stub type: " .. tostring(x.type) .. " for " .. tostring(repr(x)))
end
end,
get_stubs = function(self, x)
diff --git a/nomsu.moon b/nomsu.moon
index eb376fc..e57954d 100755
--- a/nomsu.moon
+++ b/nomsu.moon
@@ -365,7 +365,10 @@ end);]])\format(statements or "", expr or "ret")
@errorln "#{colored.red "Error occurred in statement:"}\n#{colored.yellow statement.src}"
@errorln debug.traceback!
@error(ret)
- insert buffer, "#{statements or ''}\n#{expr and "ret = #{expr};" or ''}"
+ if statements
+ insert buffer, statements
+ if expr
+ insert buffer, "ret = #{expr};"
if max_operations
debug.sethook!
@@ -374,7 +377,7 @@ return (function(nomsu, vars)
local ret;
%s
return ret;
-end);]])\format(concat(buffer, ""))
+end);]])\format(concat(buffer, "\n"))
return return_value, lua_code, vars
tree_to_value: (tree, vars)=>
@@ -675,7 +678,7 @@ end)]])\format(concat(lua_bits, "\n"))
insert stub, "%"
arg_names = nil
return concat(stub," "), arg_names
- else @error "Unsupported get stub type: #{x.type}"
+ else @error "Unsupported get stub type: #{x.type} for #{repr x}"
get_stubs: (x)=>
if type(x) != 'table' then return {{@get_stub(x)}}