X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~mdw/git/sod/blobdiff_plain/2b8759bf0239b0a98ac830952ed69572580826c1..3ee33e04477ace9d13587f28253fb8c6d1c7ed6c:/src/parser/parser-proto.lisp diff --git a/src/parser/parser-proto.lisp b/src/parser/parser-proto.lisp index 189e503..ed439f9 100644 --- a/src/parser/parser-proto.lisp +++ b/src/parser/parser-proto.lisp @@ -87,6 +87,21 @@ (defun combine-parser-failures (failures) failures :initial-value nil)) +(export 'parse-empty) +(defun parse-empty (&optional value) + "Return a parser which parses nothing, successfully. + + The parser returns VALUE and consumes nothing." + (lambda () (values value t nil))) + +(export 'parse-fail) +(defun parse-fail (indicator &optional consumedp) + "Return a parser which fails. + + The parser reports the INDICATOR and (falsely) claims to have consumed + input if CONSUMEDP is true." + (lambda () (values indicator nil consumedp))) + ;;;-------------------------------------------------------------------------- ;;; Basic protocol. @@ -591,7 +606,7 @@ (defgeneric parser-capture-place (context) The return value may later be used with `parser-restore-place'. Be careful: all of this is happening at macro-expansion time.") (:method (context) - (error "Parser context ~S doesn't support rewinding." context))) + (error "Parser context ~S doesn't support rewinding" context))) (export 'parser-restore-place) (defgeneric parser-restore-place (context place) @@ -668,7 +683,7 @@ (defparse peek (:context (context t) parser) (defun commit-peeked-place () "Called by `commit' not lexically within `peek'." - (error "`commit' is not within `peek'.")) + (error "`commit' is not within `peek'")) (export 'commit) (defparse commit ()