From 9f61e7f90d4729a9afba1c08d6ce45af460e5d8f Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Thu, 19 Oct 2017 18:56:42 -0700 Subject: [PATCH] Misc. cleanups. --- lib/collections.nom | 2 ++ lib/moonscript.nom | 4 ++-- lib/permissions.nom | 13 +++++++------ 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/lib/collections.nom b/lib/collections.nom index 1d22bb6..c58d2f7 100644 --- a/lib/collections.nom +++ b/lib/collections.nom @@ -159,6 +159,8 @@ rule [%items sorted by %key] =: %copy = (% for all %items) sort %copy by %key %copy +rule [unique %items] =: + keys in (dict from entries ([%,yes] for all %items)) # Metatable stuff compile [counter] to: "setmetatable({}, {__index=function() return 0; end})" diff --git a/lib/moonscript.nom b/lib/moonscript.nom index 4610eac..89f5ffb 100644 --- a/lib/moonscript.nom +++ b/lib/moonscript.nom @@ -1,7 +1,7 @@ require "lib/metaprogramming.nom" # Moonscript! -parse [moonscript block %moonscript_code] as: +parse [moonscript do> %moonscript_code] as: lua do> ".." |local parse, compile = require('moonscript.parse'), require('moonscript.compile'); |local moon_code = nomsu:tree_to_value(vars.moonscript_code, vars); @@ -15,7 +15,7 @@ parse [moonscript block %moonscript_code] as: |end; |return "do\\n"..lua_code.."\\nend"; -parse [moonscript %moonscript_code] as: +parse [moonscript> %moonscript_code] as: lua do> ".." |local parse, compile = require('moonscript.parse'), require('moonscript.compile'); |local moon_code = nomsu:tree_to_value(vars.moonscript_code, vars); diff --git a/lib/permissions.nom b/lib/permissions.nom index 5669366..c60471e 100644 --- a/lib/permissions.nom +++ b/lib/permissions.nom @@ -5,15 +5,16 @@ require "lib/collections.nom" # Permission functions rule [standardize rules %rules] =: - if (=lua "type(vars.rules) == 'string'"): %rules = [%rules] + if ((type of %rules) == "string"): %rules = [%rules] (nomsu "get_stub" [%]) for all %rules - %set = [] + %result = [] for %rule in %rules: %stub = (nomsu "get_stub" [%rule]) - %aliases = (((nomsu's "defs")->%stub)->"aliases") - for all %aliases: %set -> % = (yes) - keys in %set - + %def = ((nomsu's "defs")->%stub) + assert %def "Undefined rule: \(%stub)" + %aliases = (%def's "aliases") + for all %aliases: add % to %result + unique %result rule [restrict %rules to within %elite_rules] =: %rules = (standardize rules %rules)