diff options
author | Juan Manuel Tomás <jtomas1815@gmail.com> | 2025-06-10 13:57:22 -0300 |
---|---|---|
committer | Juan Manuel Tomás <jtomas1815@gmail.com> | 2025-06-10 13:57:22 -0300 |
commit | da008e637b5bff56fed8dfbacc2adabc4bca18b1 (patch) | |
tree | 0d0207034812652c5d7d6c90d45334c918e87e4d /core.lisp | |
parent | dcff69e9d6334c57faa5a690c449f12969a6526f (diff) | |
download | monparser-da008e637b5bff56fed8dfbacc2adabc4bca18b1.tar.gz monparser-da008e637b5bff56fed8dfbacc2adabc4bca18b1.zip |
Add better reporting and new features
Units report expected results on end of input.
Opposite parser helps with the complexity explosion
on unit parsers.
Input and error printing has context.
Diffstat (limited to 'core.lisp')
-rw-r--r-- | core.lisp | 15 |
1 files changed, 12 insertions, 3 deletions
@@ -1,5 +1,14 @@ (in-package #:monparser) +(defun opposite (p) + (lambda (input &key lazy) + (let ((result (funcall p input))) + (cond ((parsing-p result) + (make-failure :place input :message "Unexpected match.")) + ((failure-p result) + (make-parsing :tree nil :left input)) + (t (error "Unexpected result type.")))))) + (defun fail (message) (lambda (input &key lazy) (make-failure :place input :message message))) @@ -28,7 +37,8 @@ (make-parsing :tree it :left (advance input)) (make-failure :place input :message (format nil "Expected: ~a, Got: ~a" ',predicate it)))) - (make-failure :place input :message "Reached end of input.")))) + (make-failure :place input + :message (format nil "Reached end of input. Expected: ~a" ',predicate))))) (defun lazily-select-parser (input parsers) (let ((intermediate-parsers '()) @@ -46,8 +56,7 @@ (input-cursor (parsing-left result)))) (setf result r))) ((failure-p r) - (when (or (failure-p result) - (= (length parsers) 1)) + (when (failure-p result) (setf result r))) (t (error (format nil "Invalid return value: ~a" r)))))) (if intermediate-parsers |