Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Change parse-string and parse-string* to parse-sequence and parse-seq…

…uence* to indicate that they operate on any object implementing CONTEXT interface. Add parse-string and parse-string* as synonyms for backwards compatibility.
  • Loading branch information...
commit df86968dc42158e5cc2b205200867185dd8b5cb9 1 parent 88f1edf
@Ramarren authored
Showing with 30 additions and 10 deletions.
  1. +27 −9 basic.lisp
  2. +3 −1 package.lisp
View
36 basic.lisp
@@ -103,23 +103,29 @@
(defparameter *memo-table* (make-hash-table))
-(defun parse-string (parser string)
- "Parse a string, return a PARSE-RESULT object. All returned values may share structure."
+(defun parse-sequence (parser sequence)
+ "Parse a sequence (where a sequence is any object which implementes CONTEXT interface), return a
+PARSE-RESULT object. All returned values may share structure."
(let ((*memo-table* (make-hash-table))
- (context (make-context string)))
+ (context (make-context sequence)))
(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, whether it was
-successful, 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. It will be nil if the parse is successful and complete.
+(defun parse-string (parser string)
+ "Synonym for parse-sequence. Parse a string, return a PARSE-RESULT object. All returned values may share structure."
+ (parse-sequence parser string))
+
+(defun parse-sequence* (parser sequence &key (complete nil))
+ "Parse a sequence (where a sequence is any object which implementes CONTEXT interface) and return
+as multiple values the first result, whether the parse was incomplete, whether it was successful,
+and the context front. The context front is an object containg the context which most advances the
+input sequence and a list of lists of parser tags which were current at that point, which allows
+approximate error reporting. It will be nil if the parse is successful and complete.
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."
- (multiple-value-bind (parse-result front) (parse-string (ensure-parser parser) string)
+ (multiple-value-bind (parse-result front) (parse-sequence (ensure-parser parser) sequence)
(ecase complete
((nil :first)
(let ((result
@@ -137,3 +143,15 @@ or immediately return nil."
(when (end-context-p (suffix-of result))
(return (values (tree-of result) nil t nil)))
(finally (return (values nil nil nil front))))))))
+
+(defun parse-string* (parser string &key (complete nil))
+ "Synonym for parse-sequence*. Parse a string and return as multiple values the first result,
+whether the parse was incomplete, whether it was successful, and the context front. The context
+front is an object containg the context which most advances the input sequence and a list of lists
+of parser tags which were current at that point, which allows approximate error reporting. It will
+be nil if the parse is successful and complete.
+
+ 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."
+ (parse-sequence* parser string :complete complete))
View
4 package.lisp
@@ -108,7 +108,9 @@
#:gather-if-not*)
(:export #:string?-using-context
#:gather-if-not*-using-context
- #:validate?)
+ #:validate?
+ #:parse-sequence
+ #:parse-sequence*)
;; some function for creating -using-context parsers from other packages
(:export #:storage-of
#:common-of
Please sign in to comment.
Something went wrong with that request. Please try again.