aboutsummaryrefslogtreecommitdiff
path: root/game2.moon
diff options
context:
space:
mode:
authorBruce Hill <bitbucket@bruce-hill.com>2017-08-20 01:30:04 -0700
committerBruce Hill <bitbucket@bruce-hill.com>2017-08-20 01:30:04 -0700
commit19c42887bce39b9607e9358d7c31484c263e26b0 (patch)
tree3e5471bb744e6bb09959251ba80bd9d5e712c1a1 /game2.moon
parenta5d58146706c7468a4b3353e653aa70546160e2e (diff)
In-progress working whitespace stuff.
Diffstat (limited to 'game2.moon')
-rwxr-xr-xgame2.moon93
1 files changed, 93 insertions, 0 deletions
diff --git a/game2.moon b/game2.moon
new file mode 100755
index 0000000..df411b0
--- /dev/null
+++ b/game2.moon
@@ -0,0 +1,93 @@
+#!/usr/bin/env moon
+utils = require 'utils'
+Game = require 'nomic_whitespace'
+g = Game()
+
+g\def "rule %spec %body", (vars)=>
+ self\def vars.spec, vars.body
+ print "Defined rule: #{vars.spec}"
+
+g\defmacro("lua %code", ((args)->
+ print("entering macro...: #{utils.repr(args)}")
+ return args[1].value
+), true)
+
+g\defmacro("macro %spec %body", ((spec,body)->
+ print("entering macro...: #{utils.repr(spec,true)} / #{utils.repr(body,true)}")
+ -- TODO: parse better
+ lua_thunk, err = loadstring("return "..spec)
+ if not lua_thunk
+ error("Failed to compile")
+ spec = lua_thunk!
+ print"SPEC IS NOW #{utils.repr(spec,true)}"
+ g\defmacro spec, (args,blargs)->
+ print("entering macro...: #{utils.repr(spec,true)} / #{utils.repr(body,true)}")
+ return body
+ return "nil"
+), false)
+
+g\def "say %x", (vars)=>
+ print(utils.repr(vars.x))
+
+g\def "return %x", (vars)=>
+ return vars.x
+
+g\run_debug[[
+say "hello world!"
+
+say (lua "23 + 42")
+
+macro "print %y": say %y
+
+macro "%x + %y":
+ lua (join ["(",%x," + ",%y,")"])
+ lua "(#{%x} + #{%y})"
+
+(five) + 4
+
+print "done"
+]]
+[[
+
+rule "fart": say "poot"
+rule "doublefart":
+ say "poot"
+ say "poot"
+
+fart
+doublefart
+
+rule "say both %x and %y":
+ say %x
+ say %y
+
+say both "vars" and "work!"
+
+say ( return "subexpressions work" )
+
+say "goodbye"
+
+say [1,2,3]
+
+say [..]
+ 1, 2, 3
+ 4, 5
+
+say both [..]
+ 1,2,3
+..and [..]
+ 4,5,6
+
+say both..
+ "hello"
+ and "world"
+
+
+rule "four": return 4
+say both..
+ "a list:"
+ and [..]
+ 1,2,3,(four),(5)
+
+say "done"
+]]