chiark / gitweb /
src/lexer-{proto,impl}.lisp: Add explicit recovery action to `error'.
authorMark Wooding <mdw@distorted.org.uk>
Sun, 26 Mar 2017 14:16:18 +0000 (15:16 +0100)
committerMark Wooding <mdw@distorted.org.uk>
Fri, 8 Jun 2018 18:58:28 +0000 (19:58 +0100)
This ends up being an `:action' keyword argument to
`parse-error-recover', and a macro body to the `error' parser macro.

doc/parsing.tex
src/lexer-impl.lisp
src/lexer-proto.lisp

index c91c74b2dafa72962ab7f0e6f91305cfab01d319..8ed8d65d5a302a7a49558ca7b86de5280da490ed 100644 (file)
@@ -836,8 +836,10 @@ file-location protocols.
 
 \begin{describe}{parseform}
     {error (@[[ :ignore-unconsumed @<flag> @!
-                :force-process @<flag> @]])                     \\ \ind
-      @<sub-parser> @<recover-parser>}
+                :force-process @<flag> @]])                     \\ \ind\ind
+        @<sub-parser> @<recover-parser>                       \-\\
+      @<declaration>^*                                          \\
+      @<form>^*}
 \end{describe}
 
 \begin{describe}{parseform}{must @<sub-parser> @[@<default>@]}
index 16861793b9a269cb027a2b91d9ee6aae38ee9940..de763712353260a26d72ddd82f918582775e5bfc 100644 (file)
@@ -67,7 +67,7 @@ (defun %skip-until (scanner token-types
     (scanner-step scanner)))
 
 (defun parse-error-recover (scanner parser recover
-                           &key ignore-unconsumed force-progress)
+                           &key ignore-unconsumed force-progress action)
   "This is the implementation of the `error' parser."
   (multiple-value-bind (result win consumedp) (funcall parser)
     (cond ((or win
@@ -93,6 +93,7 @@ (defun parse-error-recover (scanner parser recover
           ;; simply to propagate the current failure back to the caller, but
           ;; we handled that case above.
           (syntax-error scanner result)
+          (when action (funcall action))
           (when (and force-progress (not consumedp)) (scanner-step scanner))
           (funcall recover)))))
 
index 60235ff7f0934f75c00746ca05e3b8413355cd3b..a811298759a08868bdb4c8c2be3ef2093f0a7fe5 100644 (file)
@@ -129,7 +129,7 @@ (defparse skip-until (:context (context token-scanner-context)
 (export 'error)
 (defparse error (:context (context token-scanner-context)
                 (&key ignore-unconsumed force-progress)
-                sub &optional (recover t))
+                sub &optional (recover t) &body body)
   "Try to parse SUB; if it fails then report an error, and parse RECOVER.
 
    This is the main way to recover from errors and continue parsing.  Even
@@ -148,7 +148,8 @@ (defparse error (:context (context token-scanner-context)
                        (parser () ,sub)
                        (parser () ,recover)
                        :ignore-unconsumed ,ignore-unconsumed
-                       :force-progress ,force-progress))
+                       :force-progress ,force-progress
+                       :action ,(and body `(lambda () ,@body))))
 
 (export 'must)
 (defparse must (:context (context token-scanner-context)