chiark / gitweb /
src/parser/parser-proto.lisp: Add functions returning standard parsers.
authorMark Wooding <mdw@distorted.org.uk>
Thu, 26 May 2016 08:26:09 +0000 (09:26 +0100)
committerMark Wooding <mdw@distorted.org.uk>
Sun, 29 May 2016 14:08:43 +0000 (15:08 +0100)
Return always-successful and always-failing parsers, with tunable
output.

doc/SYMBOLS
doc/parsing.tex
src/parser/parser-proto.lisp

index 9df1bd916692c8a6f26069f70462ed33f239d5cc..86ef28da957eacf5b7bdb3591706620dffc85c47 100644 (file)
@@ -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
index ec1667fba4f065f107d2c7bb6e11e4933ee800ef..c04ab562657ca18220723bded6a9eb79c86e6871 100644 (file)
@@ -43,6 +43,13 @@ consumed any input items.
 \begin{describe}{fun}{combine-parser-failures @<failures> @> @<list>}
 \end{describe}
 
+\begin{describe}{fun}{parse-empty \&optional @<value> @> @<function>}
+\end{describe}
+
+\begin{describe}{fun}
+    {parse-fail @<indicator> \&optional @<consumedp> @> @<function>}
+\end{describe}
+
 %%%--------------------------------------------------------------------------
 \section{File locations} \label{sec:parsing.floc}
 
index 189e503fb40fee0a6d6e726f8d4f9573c31fd30c..7aafe45ef3e2dd26aad24224055b7057abbcfe4c 100644 (file)
@@ -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.