;;; -*- mode: Lisp; Syntax: Common-Lisp; -*- ;;; ;;; Copyright (c) 2009 by the authors. ;;; ;;; See LICENCE for details. (in-package :hu.dwim.excosy) ;;;;;; ;;; Reader (def (function e) read-excosy (machine input) (if (stringp input) (with-input-from-string (stream input) (read-excosy machine stream)) (labels ((read-name () (iter (for character = (read-char input #f input #f)) (until (or (eq character input) (whitespace? character))) (when (or (char= character #\() (char= character #\))) (unread-char character input) (finish)) (collect character :result-type simple-string))) (read-list (toplevel) (iter (for character = (read-char input #f input #f)) (when (eq character input) (if toplevel (finish) (error "End of stream reached"))) (collect (cond ((char= character #\() (read-list #f)) ((char= character #\)) (finish)) ((whitespace? character) (next-iteration)) (t (unread-char character input) (read-name))))))) (read-list #t))))