     (let ((result (mpd-match (car token) tokens funcs)))
       (if result (return result)))))
 
-(defun mpd--cons-if (head tail)
-  "Cons only if tail is not nil."
-  (if (mpd-match-p tail)
-      (cons head tail)))
-
 (defun mpd-match-list (list tokens funcs)
+  "Match all patterns in a list."
   (let ((result (mpd-match (car list) tokens funcs)))
     (when result
       (if (null (cdr list))

            (cons result rest)))))))

(defun mpd-match-regex (regex tokens funcs)
  (when (looking-at regex)
    (prog1 (buffer-substring-no-properties (point) (match-end 0))
      (goto-char (match-end 0)))))

(defun mpd-match-token (token tokens funcs)
  (let* ((pattern (cdr (assoc token tokens)))
         (match (mpd-match pattern tokens funcs)))
    (when match (cons token match))))

(defun mpd-match-or (vec tokens funcs)
  (dolist (option (coerce vec 'list))
    (let ((match (mpd-match option tokens funcs)))
      (when match (return match)))))

(defun mpd-match (pattern tokens &optional funcs)
  (search-forward-regexp "[[:space:]]*")
  (let ((start (point))
        (result (etypecase pattern

(with-current-buffer (get-buffer "*example*")
  (goto-char (point-min))
  ;(mpd-parse psl-tokens)
  (mpd-match 'expr psl-tokens psl-token-funcs))

;;; ParselTongue grammar

(defvar psl-tokens
  '((expr      [block defvar deffun number object lambda funcapp id])
