X-Git-Url: https://jxself.org/git/?p=mudsync.git;a=blobdiff_plain;f=mudsync%2Fparser.scm;h=3ad5b73fe757905cce8f12de2da968a0c05a68f8;hp=51e07c899b888d1bb89e9cd9036489d30002a3cc;hb=d13325f5f6eba20c808636948432dcdff4e138f6;hpb=20660ae0821d01f38105617ea3114b3251b8fd3a diff --git a/mudsync/parser.scm b/mudsync/parser.scm index 51e07c8..3ad5b73 100644 --- a/mudsync/parser.scm +++ b/mudsync/parser.scm @@ -16,8 +16,10 @@ ;;; You should have received a copy of the GNU General Public License ;;; along with Mudsync. If not, see . -(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) @@ -60,14 +62,29 @@ (? (: ,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 + (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) +