summaryrefslogtreecommitdiff
path: root/extra.lisp
blob: 11e32f87ad0b08cdf2bcb0c0f284ed849a4d89bb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
(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)))))