1 ;;; Mudsync --- Live hackable MUD
2 ;;; Copyright © 2016 Christopher Allan Webber <cwebber@dustycloud.org>
4 ;;; This file is part of Mudsync.
6 ;;; Mudsync is free software; you can redistribute it and/or modify it
7 ;;; under the terms of the GNU General Public License as published by
8 ;;; the Free Software Foundation; either version 3 of the License, or
9 ;;; (at your option) any later version.
11 ;;; Mudsync is distributed in the hope that it will be useful, but
12 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
13 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 ;;; General Public License for more details.
16 ;;; You should have received a copy of the GNU General Public License
17 ;;; along with Mudsync. If not, see <http://www.gnu.org/licenses/>.
19 (use-modules (rx irregex)
23 (define (match-to-kwargs irx string)
24 (let ((rx-match (irregex-match irx string)))
29 (irregex-match-substring
31 (irregex-match-names rx-match))
34 (define (split-verb-and-rest string)
35 (let* ((trimmed (string-trim-both string))
36 (first-space (string-index trimmed #\space)))
38 `((verb . ,(substring trimmed 0 first-space))
39 (rest . ,(substring trimmed (+ 1 first-space))))
43 ;; @@: Not currently used
44 ;; Borrowed from irregex.scm
46 '(seq #\" (* (or (~ #\\ #\") (seq #\\ any))) #\"))
48 ;; definite and indefinite, but not partitive articles
49 (define article '(or "the" "a" "an"))
50 (define preposition '(or "with" "in" "on" "out of" "at"))
54 `(: (? (: ,preposition (+ space))) ; possibly a preposition (ignored)
55 (? (: ,article (+ space))) ; possibly an article (ignored)
56 (=> direct-object (* any)) ; direct object (kept)
58 (=> preposition ,preposition) ; main preposition (kept)
60 (? (: ,article (+ space))) ; possibly an article (ignored)
61 (=> indirect-object (+ any))))) ; indirect object (kept)
65 `(: (? (: ,preposition (+ space))) ; possibly a preposition (ignored)
66 (? (: ,article (+ space))) ; possibly an article (ignored)
67 (=> direct-object (* any))))) ; direct object (kept)
70 (define say-example "say I really need to get going.")
71 (define attack-sword-example "hit goblin with sword")
72 (define attack-simple-example "hit goblin")
73 (define put-book-on-desk "put the book on the desk")