From: Mark Wooding Date: Thu, 26 May 2016 08:26:09 +0000 (+0100) Subject: src/parser/parser-proto.lisp: Add functions returning standard parsers. X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~mdw/git/sod/commitdiff_plain/da901cf29aae60b244bd9fcee72a5a2f59d359f2?ds=inline src/parser/parser-proto.lisp: Add functions returning standard parsers. Return always-successful and always-failing parsers, with tunable output. --- diff --git a/doc/SYMBOLS b/doc/SYMBOLS index 9df1bd9..86ef28d 100644 --- a/doc/SYMBOLS +++ b/doc/SYMBOLS @@ -1484,6 +1484,8 @@ parser-proto.lisp cl:not function parser cl:or macro parser parse + parse-empty function + parse-fail function parser macro parser-at-eof-p generic parser-capture-place generic diff --git a/doc/parsing.tex b/doc/parsing.tex index ec1667f..c04ab56 100644 --- a/doc/parsing.tex +++ b/doc/parsing.tex @@ -43,6 +43,13 @@ consumed any input items. \begin{describe}{fun}{combine-parser-failures @ @> @} \end{describe} +\begin{describe}{fun}{parse-empty \&optional @ @> @} +\end{describe} + +\begin{describe}{fun} + {parse-fail @ \&optional @ @> @} +\end{describe} + %%%-------------------------------------------------------------------------- \section{File locations} \label{sec:parsing.floc} diff --git a/src/parser/parser-proto.lisp b/src/parser/parser-proto.lisp index 189e503..7aafe45 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.