Permalink
Browse files

Return context front from top level functions.

  • Loading branch information...
1 parent 151dffa commit d0f2c849062f81951dc1c6e32c9f96589ff9afcb @Ramarren committed Nov 15, 2009
Showing with 31 additions and 22 deletions.
  1. +28 −21 basic.lisp
  2. +3 −1 package.lisp
View
@@ -107,28 +107,35 @@
(defun parse-string (parser string)
"Parse a string, return a PARSE-RESULT object. All returned values may share structure."
(let ((*memo-table* (make-hash-table))
- (*curtail-table* (make-hash-table)))
- (make-parse-result (funcall parser (make-context string)))))
+ (*curtail-table* (make-hash-table))
+ (context (make-context string)))
+ (values (make-parse-result (funcall parser context))
+ (front-of context))))
(defun parse-string* (parser string &key (complete nil))
- "Parse a string and return the first result, whether the parse was incomplete, and whether it was
-successfull as multiple values. If COMPLETE is T, return the first parse to consume the input
+ "Parse a string and return the first result, whether the parse was incomplete, whether it was
+successfull, and the context front as multiple values. The context front is an object containg the
+context latest in the input and a list of lists of parser tags which were current at that point,
+which allows approximate error reporting.
+
+ If COMPLETE is T, return the first parse to consume the input
completely. If COMPLETE is :FIRST return the first result only when it the whole input was consumed,
or immediately return nil."
- (ecase complete
- ((nil :first)
- (let ((result
- (current-result (parse-string parser string))))
- (cond ((or (null result)
- (and (eql complete :first)
- (not (end-context-p (suffix-of result)))))
- (values nil nil nil))
- ((not (end-context-p (suffix-of result)))
- (values (tree-of result) (suffix-of result) t))
- (t (values (tree-of result) nil t)))))
- (t (iter (with results = (parse-string parser string))
- (for result = (next-result results))
- (while result)
- (when (end-context-p (suffix-of result))
- (return (values (tree-of result) nil t)))
- (finally (return (values nil nil nil)))))))
+ (multiple-value-bind (parse-result front) (parse-string parser string)
+ (ecase complete
+ ((nil :first)
+ (let ((result
+ (current-result parse-result)))
+ (cond ((or (null result)
+ (and (eql complete :first)
+ (not (end-context-p (suffix-of result)))))
+ (values nil nil nil))
+ ((not (end-context-p (suffix-of result)))
+ (values (tree-of result) (suffix-of result) t))
+ (t (values (tree-of result) nil t)))))
+ (t (iter (with results = parse-result)
+ (for result = (next-result results))
+ (while result)
+ (when (end-context-p (suffix-of result))
+ (return (values (tree-of result) nil t)))
+ (finally (return (values nil nil nil))))))))
View
@@ -82,4 +82,6 @@
#:parse-string*
#:find-before?
#:find-before*
- #:end?))
+ #:end?
+ #:context-of
+ #:tags-of))

0 comments on commit d0f2c84

Please sign in to comment.