chiark / gitweb /
src/lexer-proto.lisp: New parser `must'.
[sod] / src / lexer-proto.lisp
index 122da753d99051275570d4f62ac457c32eefd169..b045be75589e8e243b011bcf92673eae7fa39f8b 100644 (file)
@@ -141,6 +141,14 @@ (defparse error (:context (context token-scanner-context)
                        :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.