(in-package #:monparser) (defun whitespace? (x) (or (char= x #\Space) (not (graphic-char-p x)))) (defparameter whitespace (many (unit #'whitespace?))) (defmacro literal (word) (when (not (stringp word)) (error "Literal only accepts strings as input.")) (let ((binding-list '()) (name-list '())) (loop :for c :across word :do (when c (let ((name (gensym))) (push name name-list) (push `(,name (unit ,c)) binding-list)))) `(comp ,(reverse binding-list) ,(cons 'list (reverse name-list))))) (defun separated-list (p separator) (many (comp ((v p) (_ (optional separator))) v))) (defun surround (left p &optional right) (comp ((_ left) (value p) (_ (or right nothing)))))