This is a simple wrapper around `error' for mandatory delimiters. If it
doesn't find the delimiter, it reports the error and continues, possibly
producing a default value.
define-indicator function
cl:error function class parser
lexer-error function
+ must parser
scan-comment function
skip-until function parser
sod-token-scanner class
list-parser (eql cl:type) t
token-parser-context (eql token) t
token-scanner-context (eql cl:error) t
+ token-scanner-context (eql sod:must) t
token-scanner-context (eql sod:skip-until) t
expand-parser-spec
t (eql :eof)
@<sub-parser> @<recover-parser>}
\end{describe}
+\begin{describe}{parseform}{must @<sub-parser> @[@<default>@]}
+\end{describe}
+
\begin{describe}{fun}
{scan-comment @<char-scanner>
@> @<result> @<success-flag> @<consumed-flag>}
:ignore-unconsumed ,ignore-unconsumed
:force-progress ,force-progress))
+(export 'must)
+(defparse must (:context (context token-scanner-context)
+ sub &optional default)
+ "Try to parse SUB; if it fails, report an error, and return DEFAULT.
+
+ This parser can't actually fail."
+ `(parse (error () ,sub (t ,default))))
+
;;;--------------------------------------------------------------------------
;;; Lexical analysis utilities.