;;; Mudsync --- Live hackable MUD ;;; Copyright © 2016 Christopher Allan Webber ;;; ;;; 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 . (use-modules (rx irregex) (ice-9 match)) (define (match-to-kwargs irx string) (let ((rx-match (irregex-match irx string))) (if rx-match (map (match-lambda ((match-part . idx) (cons match-part (irregex-match-substring rx-match idx)))) (irregex-match-names rx-match)) #f))) (define (split-verb-and-rest string) (let* ((trimmed (string-trim-both string)) (first-space (string-index trimmed #\space))) (if first-space `((verb . ,(substring trimmed 0 first-space)) (rest . ,(substring trimmed (+ 1 first-space)))) `((verb . ,trimmed) (rest . ""))))) ;; @@: Not currently used ;; Borrowed from irregex.scm (define match-string '(seq #\" (* (or (~ #\\ #\") (seq #\\ any))) #\")) ;; definite and indefinite, but not partitive articles (define article '(or "the" "a" "an")) (define preposition '(or "with" "in" "on" "out of" "at")) (define indirect-irx (sre->irregex `(: (? (: ,preposition (+ space))) ; possibly a preposition (ignored) (? (: ,article (+ space))) ; possibly an article (ignored) (=> direct-object (* any)) ; direct object (kept) (+ space) (=> preposition ,preposition) ; main preposition (kept) (+ space) (? (: ,article (+ space))) ; possibly an article (ignored) (=> indirect-object (+ any))))) ; indirect object (kept) (define direct-irx (sre->irregex `(: (? (: ,preposition (+ space))) ; possibly a preposition (ignored) (? (: ,article (+ space))) ; possibly an article (ignored) (=> direct-object (* any))))) ; direct object (kept) (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")