Split mudsync.scm out into multiple files
[mudsync.git] / mudsync / parser.scm
index 51e07c899b888d1bb89e9cd9036489d30002a3cc..3ad5b73fe757905cce8f12de2da968a0c05a68f8 100644 (file)
 ;;; You should have received a copy of the GNU General Public License
 ;;; along with Mudsync.  If not, see <http://www.gnu.org/licenses/>.
 
-(use-modules (rx irregex)
-             (ice-9 match))
+(define-module (mudsync parser)
+  #:use-module (rx irregex)
+  #:use-module (ice-9 match)
+  #:use-module (srfi srfi-9))
 
 
 (define (match-to-kwargs irx string)
        (? (: ,article (+ space)))      ; possibly an article (ignored)
        (=> indirect-object (+ any))))) ; indirect object (kept)
 
+(define (indirect-matcher phrase)
+  (match-to-kwargs indirect-irx phrase))
+
 (define direct-irx
   (sre->irregex
    `(: (? (: ,preposition (+ space)))  ; possibly a preposition (ignored)
        (? (: ,article (+ space)))     ; possibly an article (ignored)
        (=> direct-object (* any)))))  ; direct object (kept)
 
+(define (direct-matcher phrase)
+  (match-to-kwargs direct-irx phrase))
 
 (define say-example "say I really need to get going.")
 (define attack-sword-example "hit goblin with sword")
 (define attack-simple-example "hit goblin")
 (define put-book-on-desk "put the book on the desk")
+
+(define-record-type <command-handler>
+  (make-command-handler matcher should-handle action)
+  command-handler?
+  (matcher command-handler-matcher)
+  (should-handle command-handler-should-handle?)
+  (action command-handler-action))
+
+(define command-handler make-command-handler)
+