(in-package :parse)

(defun run-parse (stream &key existing-scope)
  (let
    ((command (read-char stream nil nil)))
    (when (or (not command) *error*)
      (return-from run-parse *active-scope*))
    (execute-command *active-scope* command)
    (run-parse stream :existing-scope *active-scope*)))

(defun parse (stream &key existing-scope)
  (let*
    ((*active-scope*
       (or
         existing-scope
         (make-instance (quote scope))))
     (*root-scope* *active-scope*))
    (run-parse stream :existing-scope *active-scope*)))
