[Spell components and school parsers clinton@unknownlamer.org**20080416020025 * Minor improvements to spell level parser ] { hunk ./src/srd-import.lisp 15 +(defparameter *spell-components-scanner* + (cl-ppcre:create-scanner + '(:greedy-repetition 1 nil + (:register (:greedy-repetition 1 2 :word-char-class))))) + +(defparameter *spell-school-scanner* + (cl-ppcre:create-scanner + '(:sequence + (:register (:greedy-repetition 1 nil :word-char-class)) + (:alternation + (:sequence #\space + #\( + (:register (:greedy-repetition 1 nil :word-char-class)) + #\)) + :end-anchor) + (:alternation + (:sequence #\space + #\[ + (:register (:greedy-repetition 1 nil (:char-class + #\- + :word-char-class))) + #\]) + :end-anchor)))) + hunk ./src/srd-import.lisp 47 - (push (cons class (parse-integer level)) levels)))) + (push (list class (parse-integer level)) levels)))) hunk ./src/srd-import.lisp 54 - (mapcar (lambda (level-entry) - (cons (cdr - (assoc (car level-entry) srd-abbreviations :test #'string=)) - (cdr level-entry))) - caster-levels))) + (mapcar (lambda (spell-level) + (cons (cdr (assoc (car spell-level) srd-abbreviations :test #'string=)) + (cdr spell-level))) + caster-levels))) + +(defun parse-spell-components (spell-components-string) + (let ((spell-components + (let ((components (list))) + (ppcre:do-register-groups (component) (*spell-components-scanner* + spell-components-string + (nreverse components)) + (push component components)))) + (srd-abbreviations '(("V" . verbal) + ("S" . somatic) + ("M" . material) + ("F" . focus) + ("DF" . divine-focus) + ("XP" . xp-cost)))) + (mapcar (lambda (component) + (cdr (assoc component srd-abbreviations :test #'string=))) + spell-components))) + +(defun parse-spell-school (spell-school-string) + (cl-ppcre:register-groups-bind (school subschool type) + (*spell-school-scanner* spell-school-string) + (mapcar (lambda (string) (if string (intern (string-upcase string)))) + (list school subschool type)))) hunk ./src/srd-import.lisp 118 + }