aboutsummaryrefslogtreecommitdiff
path: root/nomic.moon
diff options
context:
space:
mode:
authorBruce Hill <bitbucket@bruce-hill.com>2017-08-18 21:21:24 -0700
committerBruce Hill <bitbucket@bruce-hill.com>2017-08-18 21:21:24 -0700
commita5d58146706c7468a4b3353e653aa70546160e2e (patch)
treec19472dc8a776934d6641a3f1cb02858561745aa /nomic.moon
parentdc152f88b6ff1d778a8106ee49b8c4e3d902404a (diff)
Pulled out some utils.
Diffstat (limited to 'nomic.moon')
-rw-r--r--nomic.moon25
1 files changed, 4 insertions, 21 deletions
diff --git a/nomic.moon b/nomic.moon
index 0eb9879..12bfb08 100644
--- a/nomic.moon
+++ b/nomic.moon
@@ -1,24 +1,9 @@
re = require 're'
lpeg = require 'lpeg'
+utils = require 'utils'
moon = require 'moon'
type = moon.type
-is_list = (t)->
- i = 1
- for _ in pairs(t)
- if t[i] == nil then return false
- i += 1
- return true
-
-repr = (x)->
- if type(x) == 'table'
- if is_list x
- "[#{table.concat([repr(i) for i in *x], ", ")}]"
- else
- "{#{table.concat(["#{k}: #{v}" for k,v in pairs x], ", ")}}"
- else
- tostring(x)
-
currently_parsing = nil
macros = nil
indentation = 0
@@ -86,7 +71,7 @@ FunctionCall = (tokens)->
args = [t for t in *tokens when t.type != 'word']
rule_name = table.concat(words, " ")
if rule_name == "$"
- error("Empty rule: #{repr(tokens)}")
+ error("Empty rule: #{utils.repr(tokens)}")
if macros[rule_name]
return macros[rule_name](unpack(args))
@@ -219,7 +204,7 @@ class Game
return [c for c in pairs canonicals]
set_whitelist: (actions, whitelist)=>
- if is_list whitelist then whitelist = {w,true for w in *whitelist}
+ if utils.is_list whitelist then whitelist = {w,true for w in *whitelist}
for action in *@all_aliases(actions)
@authorized[action] = whitelist
@@ -256,7 +241,7 @@ class Game
if not @rules[invocation]
error "Could not find rule: '#{invocation}'"
if not @\check_authorization invocation
- print "Not authorized to #{invocation} from callstack: #{repr(@callstack)}"
+ print "Not authorized to #{invocation} from callstack: #{utils.repr(@callstack)}"
return
table.insert @callstack, invocation
arg_names = @arg_names[invocation]
@@ -281,6 +266,4 @@ class Game
break
@\run buf
- repr: repr
-
return Game