Make commands use the inheritable rmeta-slot tooling
[mudsync.git] / mudsync / command.scm
index b09873a06f416f8133c6dde8eea37dd8e37f3fdd..a79f50d3e7f878ae24b9a1b6d8d5d98ebaeb0086 100644 (file)
@@ -1,6 +1,25 @@
+;;; Mudsync --- Live hackable MUD
+;;; Copyright © 2016 Christopher Allan Webber <cwebber@dustycloud.org>
+;;;
+;;; This file is part of Mudsync.
+;;;
+;;; Mudsync is free software; you can redistribute it and/or modify it
+;;; under the terms of the GNU General Public License as published by
+;;; the Free Software Foundation; either version 3 of the License, or
+;;; (at your option) any later version.
+;;;
+;;; Mudsync is distributed in the hope that it will be useful, but
+;;; WITHOUT ANY WARRANTY; without even the implied warranty of
+;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+;;; General Public License for more details.
+;;;
+;;; You should have received a copy of the GNU General Public License
+;;; along with Mudsync.  If not, see <http://www.gnu.org/licenses/>.
+
 (define-module (mudsync command)
   #:use-module (mudsync parser)
-  #:use-module (8sync systems actors)
+  #:use-module (8sync actors)
+  #:use-module (8sync rmeta-slot)
   #:use-module (srfi srfi-1)
   #:use-module (srfi srfi-9)
   #:use-module (ice-9 control)
             command-action
             command-priority
 
+            build-commands
+
             direct-command
-            indir-command
+            prep-indir-command
+            prep-direct-command
             loose-direct-command
-            loose-indir-command
+            loose-prep-command
             empty-command
             direct-greedy-command
             greedy-command
   (action command-action)
   (priority command-priority))
 
+(define-syntax %build-command
+  (syntax-rules ()
+    ((_ (verb ...) ((cmd-proc action-sym args ...) ...))
+     (list (cons verb
+                 (list (cmd-proc (list verb ...)
+                                 (quote action-sym)
+                                 args ...)
+                       ...))
+           ...))
+    ((_ verb ((cmd-proc action-sym args ...) ...))
+     (list (cons verb
+                 (list (cmd-proc (list verb)
+                                 (quote action-sym)
+                                 args ...)
+                       ...))))))
+
+(define-syntax-rule (build-commands (verb-or-verbs cmd-defs ...) ...)
+  (wrap-rmeta-slot
+   (append (%build-command verb-or-verbs cmd-defs ...) ...)))
+
 
 (define (direct-command verbs action)
   (make-command verbs
                 %default-priority))
 
 
-(define* (indir-command verbs action #:optional prepositions)
+(define* (prep-indir-command verbs action #:optional prepositions)
   (make-command verbs
                 cmatch-indir-obj
                 (lambda* (goes-by #:key direct-obj indir-obj preposition)
                 action
                 %high-priority))
 
-(define* (loose-indir-command verbs action #:optional prepositions)
+(define* (prep-direct-command verbs action #:optional prepositions)
+  (make-command verbs
+                cmatch-indir-obj
+                (lambda* (goes-by #:key direct-obj indir-obj preposition)
+                  (if prepositions
+                      (and
+                       (member  direct-obj goes-by)
+                       (member preposition prepositions))
+                      (member direct-obj goes-by)))
+                action
+                %high-priority))
+
+(define* (loose-prep-command verbs action #:optional prepositions)
   (make-command verbs
                 cmatch-indir-obj
                 (const #t)