1 (use-modules (rx irregex)
5 (define (match-to-kwargs irx string)
6 (let ((rx-match (irregex-match irx string)))
11 (irregex-match-substring
13 (irregex-match-names rx-match))
17 ;; definite and indefinite, but not partitive articles
18 (define article '(or "the" "a" "an"))
19 (define preposition '(or "with" "in" "on" "out of" "at"))
21 (define split-verb-and-rest-irx
23 `(: (* space) (=> verb (+ alphanum))
24 (? (+ space) (=> rest (* any))))))
26 ;; TODO: we could make this MUCH FASTER if we didn't use irregex
28 (define (split-verb-and-rest string)
29 (let* ((trimmed (string-trim-both string))
30 (first-space (string-index trimmed #\space)))
32 `((verb . ,(substring trimmed 0 first-space))
33 (rest . ,(substring trimmed (+ 1 first-space))))
37 ;; @@: Not currently used
38 ;; Borrowed from irregex.scm
40 '(seq #\" (* (or (~ #\\ #\") (seq #\\ any))) #\"))
44 `(: (? (: ,article (+ space))) ; possibly an article (ignored)
45 (=> direct-object (* any)) ; direct object
46 (+ space) (=> preposition ,preposition) (+ space)
47 (? (: ,article (+ space)))
48 (=> indirect-object (+ any)))))
51 `(: (? (: ,article (+ space))) ; possibly an article (ignored)
52 (=> direct-object (* any)))) ; direct object
55 (define say-example "say I really need to get going.")
56 (define attack-sword-example "hit goblin with sword")
57 (define attack-simple-example "hit goblin")
58 (define put-book-on-desk "put the book on the desk")