(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))) ;; definite and indefinite, but not partitive articles (define article '(or "the" "a" "an")) (define preposition '(or "with" "in" "on" "out of" "at")) (define split-verb-and-rest-irx (sre->irregex `(: (* space) (=> verb (+ alphanum)) (? (+ space) (=> rest (* any)))))) ;; TODO: we could make this MUCH FASTER if we didn't use irregex ;; for this step! (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))) #\")) (define indirect-irx (sre->irregex `(: (? (: ,article (+ space))) ; possibly an article (ignored) (=> direct-object (* any)) ; direct object (+ space) (=> preposition ,preposition) (+ space) (? (: ,article (+ space))) (=> indirect-object (+ any))))) (define direct-irx `(: (? (: ,article (+ space))) ; possibly an article (ignored) (=> direct-object (* any)))) ; direct object (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")