diff options
-rw-r--r-- | notes.md | 7 | ||||
-rw-r--r-- | parser.lisp | 10 |
2 files changed, 13 insertions, 4 deletions
@@ -24,3 +24,10 @@ This will give control to the one-of block to call the next parsing step. # lazy binding ## Problem If defining a parser that surrounds another, the inner parser must know about what the delimiter parser is attempting to parse, specially after the inner parser. + +## Solution +Implement lazy binding. This sweeps the next parser across the input until it finds where it first parses, then takes the distance from the current input and calls the current parser with a limit on how much input to parse equal to said difference. + +# TODO +* Change the parser entry so that it takes streams as input. This will make it easier to interact with other packages. +* Change literal parser into a macro that chains unit parsers. This will take advantage of the BF feature in one-of block. diff --git a/parser.lisp b/parser.lisp index 1c51c33..bfe2614 100644 --- a/parser.lisp +++ b/parser.lisp @@ -111,8 +111,8 @@ (push r intermediate-parsers)) ((parsing-p r) (when (or (not (parsing-p result)) - (> (cursor (parsing-input r)) - (cursor (parsing-input result)))) + (> (cursor (parsing-left r)) + (cursor (parsing-left result)))) (setf result r))) ((failure-p r) (when (or (failure-p result) @@ -164,7 +164,9 @@ (defun many (p) (comp ((x p) - (xs (optional (many p)))) + (xs (if (not x) + (error "Cannot define (many (optional x)). Use (optional (many x)) instead.") + (optional (many p))))) (cons x xs))) (defun repeat (p min &optional (max 0)) @@ -183,7 +185,7 @@ (defparameter whitespace (comp ((_ (optional (many (unit whitespace?))))) - nil)) + :whitespace)) (defun separated-list (p separator &key include-separator) (comp ((v p) |