chiark / gitweb /
src/lexer-{proto,impl}.lisp: Add explicit recovery action to `error'.
[sod] / doc / parsing.tex
index 58959c0b81bea73d976b28cf0c5775931beab769..8ed8d65d5a302a7a49558ca7b86de5280da490ed 100644 (file)
@@ -7,7 +7,7 @@
 
 %%%----- Licensing notice ---------------------------------------------------
 %%%
-%%% This file is part of the Sensble Object Design, an object system for C.
+%%% This file is part of the Sensible Object Design, an object system for C.
 %%%
 %%% SOD is free software; you can redistribute it and/or modify
 %%% it under the terms of the GNU General Public License as published by
@@ -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}
 
@@ -82,33 +89,48 @@ consumed any input items.
 \begin{describe*}
     {\quad\=\quad\=\kill
      \dhead{cls}
-      {error-with-location (condition-with-location error) \\ \>
-        \&key :location}
-    \dhead{cls}
-      {warning-with-location (condition-with-location warning) \\ \>
-        \&key :location}
-    \dhead{cls}
-      {enclosing-error-with-location
-          (enclosing-error-with-location error) \\ \>
-        \&key :condition :location}
-    \dhead{cls}
-      {enclosing-warning-with-location
-          (enclosing-condition-with-location warning) \\ \>
-        \&key :condition :location}
+       {error-with-location (condition-with-location error)     \\ \>
+         \&key :location}
+     \dhead{cls}
+       {warning-with-location (condition-with-location warning) \\ \>
+         \&key :location}
+     \dhead{cls}
+       {information-with-location (condition-with-location information) \\ \>
+         \&key :location}
+     \dhead{cls}
+       {enclosing-error-with-location
+           (enclosing-error-with-location error)                \\ \>
+         \&key :condition :location}
+     \dhead{cls}
+       {enclosing-warning-with-location
+           (enclosing-condition-with-location warning)          \\ \>
+         \&key :condition :location}
+     \dhead{cls}
+       {enclosing-information-with-location
+           (enclosing-condition-with-location information)      \\ \>
+         \&key :condition :location}
      \dhead{cls}
-      {simple-condition-with-location
-          (condition-with-location simple-condition) \\ \>
-        \&key :format-control :format-arguments :location}
+       {simple-condition-with-location
+           (condition-with-location simple-condition)           \\ \>
+         \&key :format-control :format-arguments :location}
      \dhead{cls}
-      {simple-error-with-location
-          (error-with-location simple-error) \\ \>
-        \&key :format-control :format-arguments :location}
-    \dhead{cls}
-      {simple-warning-with-location
-          (warning-with-location simple-warning) \\ \>
-        \&key :format-control :format-arguments :location}}
+       {simple-error-with-location
+           (error-with-location simple-error)                   \\ \>
+         \&key :format-control :format-arguments :location}
+     \dhead{cls}
+       {simple-warning-with-location
+           (warning-with-location simple-warning)               \\ \>
+         \&key :format-control :format-arguments :location}
+     \dhead{cls}
+       {simple-information-with-location
+           (information-with-location simple-information)       \\ \>
+         \&key :format-control :format-arguments :location}}
 \end{describe*}
 
+\begin{describe}{gf}
+    {enclosing-condition-with-location-type @<condition> @> @<symbol>}
+\end{describe}
+
 \begin{describe}{fun}
     {make-condition-with-location @<default-type> @<floc>
                                   @<datum> \&rest @<arguments>
@@ -123,12 +145,49 @@ consumed any input items.
      \dhead{fun}{warn-with-location @<floc> @<datum> \&rest @<arguments>}}
 \end{describe*}
 
+\begin{describe*}
+    {\dhead{cls}{parser-error (error) \\ \ind
+                    \&key :expected :found \-}
+     \dhead{gf}{parser-error-expected @<condition> @> @<list>}
+     \dhead{gf}{parser-error-found @<condition> @> @<value>}}
+\end{describe*}
+
+\begin{describe}{fun}
+    {report-parser-error @<error> @<stream> @<show-expected> @<show-found>}
+\end{describe}
+
+\begin{describe*}
+    {\quad\=\kill
+     \dhead{cls}{base-lexer-error (error-with-location) \&key :location}
+     \dhead{cls}{simple-lexer-error
+                      (base-lexer-error simple-error-with-location) \\\>
+                    \&key :format-control :format-arguments :location}
+     \dhead{cls}{base-syntax-error (error-with-location) \&key :location}
+     \dhead{cls}{simple-syntax-error
+                      (base-syntax-error simple-error-with-location) \\\>
+                    \&key :format-control :format-arguments :location}}
+\end{describe*}
+
 \begin{describe}{mac}
-    {with-default-error-location (@<floc>) @<body-form>^* @> @<value>^*}
+    {with-default-error-location (@<floc>) @<declaration>^* @<form>^*
+      @> @<value>^*}
+\end{describe}
+
+\begin{describe}{gf}{classify-condition @<condition> @> @<string>}
+  \begin{describe*}
+      {\dhead{meth}{classify-condition (@<condition> error) @> @<string>}
+       \dhead{meth}{classify-condition (@<condition> warning) @> @<string>}
+       \dhead{meth}{classify-condition (@<condition> information)
+                       @> @<string>}
+       \dhead{meth}{classify-condition (@<condition> base-lexer-error)
+                       @> @<string>}
+       \dhead{meth}{classify-condition (@<condition> base-syntax-error)
+                       @> @<string>}}
+  \end{describe*}
 \end{describe}
 
 \begin{describe}{mac}
-    {count-and-report-errors () @<body-form>^*
+    {count-and-report-errors () @<declaration>^* @<form>^*
       @> @<value> @<n-errors> @<n-warnings>}
 \end{describe}
 
@@ -209,11 +268,12 @@ the scanner and read that data again.  Therefore it's possible to
 \end{describe}
 
 \begin{describe}{mac}
-    {with-scanner-place (@<place> @<scanner>) @<body-form>^* @> @<value>^*}
-  Capture the @<scanner>'s current position as a place, evaluate the
-  @<body-form>s as an implicit progn with the variable @<place> bound to the captured
-  place.  When control leaves the @<body-form>s, the place is released.  The return
-  values are the values of the final @<body-form>.
+    {with-scanner-place (@<place> @<scanner>) @<declarations>^* @<form>^*
+      @> @<value>^*}
+  Capture the @<scanner>'s current position as a place, evaluate the @<form>s
+  as an implicit progn with the variable @<place> bound to the captured
+  place.  When control leaves the @<form>s, the place is released.  The
+  return values are the values of the final @<form>.
 \end{describe}
 
 \subsection{Scanner file-location protocol} \label{sec:parsing.scanner.floc}
@@ -368,8 +428,8 @@ file-location protocols.
   characters from a scanner in bulk.  The function @<func> is invoked
   repeatedly, as if by
   \begin{prog}
-    (multiple-value-bind (@<donep> @<used>) \\ \ind\ind
-        (funcall @<func> @<buf> @<start> @<end>) \- \\
+    (multiple-value-bind (@<donep> @<used>)                     \\ \ind\ind
+        (funcall @<func> @<buf> @<start> @<end>)              \-\\
       \textrm\ldots)
   \end{prog}
   The argument @<buf> is a simple string; @<start> and @<end> are two
@@ -385,8 +445,8 @@ file-location protocols.
   fails: the @<fail> function is called with no arguments, and is expected to
   return two values.  If omitted, @<fail> defaults to
   \begin{prog}
-    (lambda () \\ \ind
-      (values nil nil))%
+    (lambda ()                                                  \\ \ind
+      (values nil nil))
   \end{prog}
 
   The @|charbuf-scanner-map| function returns three values.  The first value
@@ -445,22 +505,31 @@ file-location protocols.
 
 \begin{describe}{mac}
     {defparse @<name> (@[[ :context (@<var> @<context-class>) @]]
-                       @<destructuring-lambda-list-item>^*) \\ \ind
-      @<body-form>^* \-
-     \nlret @<name>}
+                       @<destructuring-lambda-list-item>^*)     \\ \ind
+      @[[ @<declaration>^* @! @<doc-string> @]]                 \\
+      @<form>^*
+     \-\nlret @<name>}
 \end{describe}
 
 \begin{describe}{mac}
     {with-parser-context
-        (@<context-class> @{ @<init-keyword> @<value> @}^*) \\ \ind
-      @<body-form>^* \-
-     \nlret @<value>^*}
+        (@<context-class> @{ @<init-keyword> @<value> @}^*)     \\ \ind
+      @<declaration>^*                                          \\
+      @<form>^*
+     \-\nlret @<value>^*}
 \end{describe}
 
 \begin{describe}{lmac}
     {parse @<parser> @> @<result> @<success-flag> @<consumed-flag>}
 \end{describe}
 
+\begin{describe}{mac}
+    {parser @<lambda-list>
+      @[[ @<declaration>^* @! @<doc-string> @]]
+      @<parser>
+      @> @<function>}
+\end{describe}
+
 \begin{describe}{gf}{parser-at-eof-p @<context> @> @<form>}
 \end{describe}
 
@@ -472,26 +541,26 @@ file-location protocols.
 
 \begin{describe}{mac}
     {if-parse (@[[ \=:result @<result-var> @!
-                     :expected @<expected-var> @! \+ \\
-                     :consumedp @<consumed-var> @]]) \- \\ \ind\ind
-        @<parser> \- \\
-      @<consequent> \\
-      @[@<alternatve>@] \-
-     \nlret @<value>^*}
+                     :expected @<expected-var> @!             \+\\
+                     :consumedp @<consumed-var> @]])          \-\\ \ind\ind
+        @<parser>                                             \-\\
+      @<consequent>                                             \\
+      @[@<alternatve>@]
+     \-\nlret @<value>^*}
 \end{describe}
 
 \begin{describe}{mac}
-    {when-parse (@[@<result-var>@]) @<parser> \\ \ind
-      @<body-form>^* \-
-     \nlret @<value>^*}
+    {when-parse (@[@<result-var>@]) @<parser>                   \\ \ind
+      @<form>^*
+     \-\nlret @<value>^*}
 \end{describe}
 
 \begin{describe}{mac}
     {cond-parse (@[[ \=:result @<result-var> @!
-                       :expected @<expected-var> @! \+ \\
-                       :consumedp @<consumed-var> @]]) \- \\ \ind
-      @{ (@<parser> @<form>^*) @}^* \-
-     \nlret @<value>^*}
+                       :expected @<expected-var> @!           \+\\
+                       :consumedp @<consumed-var> @]])        \-\\ \ind
+      @{ (@<parser> @<form>^*) @}^*
+     \-\nlret @<value>^*}
 \end{describe}
 
 \begin{describe}{parse}{:eof}
@@ -519,8 +588,9 @@ file-location protocols.
 \end{describe}
 
 \begin{describe}{parseform}
-    {seq (@{ @<atomic-parser-spec> @! (@[@<var>@] @<parser>) @}^*) \\ \ind
-      @<body-form>^*}
+    {seq (@{ @<atomic-parser-spec> @!
+             (@[@<var>@] @<parser>) @}^*)                       \\ \ind
+      @<form>^*}
 \end{describe}
 
 \begin{describe}{parseform}{and @<parser>^*}
@@ -533,22 +603,22 @@ file-location protocols.
 \end{describe}
 
 \begin{describe}{parseform}
-    {many (\=@<accumulator-var> @<init-form> @<update-form> \+ \\
-           @[[ \=:new @<new-var> @! :final @<final-form> @! \+ \\
-                 :min @<minimum> @! :max @<maximum> @! \\
-                 :commitp @<commitp> @]]) \-\- \\ \ind
+    {many (\=@<accumulator-var> @<init-form> @<update-form>   \+\\
+           @[[ \=:new @<new-var> @! :final @<final-form> @!   \+\\
+                 :min @<minimum> @! :max @<maximum> @!          \\
+                 :commitp @<commitp> @]])                   \-\-\\ \ind
       @<item-parser> @[@<sep-parser>@]}
 \end{describe}
 
 \begin{describe}{parseform}
     {list (@[[ :min @<minimum> @! :max @<maximum> @!
-               :commitp @<commitp> @]])\\ \ind
+               :commitp @<commitp> @]])                         \\ \ind
       @<item-parser> @[@<sep-parser>@]}
 \end{describe}
 
 \begin{describe}{parseform}
     {skip-many (@[[ :min @<minimum> @! :max @<maximum> @!
-                    :commitp @<commitp> @]])\\ \ind
+                    :commitp @<commitp> @]])                    \\ \ind
       @<item-parser> @[@<sep-parser>@]}
 \end{describe}
 
@@ -563,7 +633,9 @@ file-location protocols.
 \end{describe}
 
 \begin{describe}{mac}
-    {define-pluggable-parser @<symbol> @<tag> @<lambda-list> @<body-form>^*}
+    {define-pluggable-parser @<symbol> @<tag> @<lambda-list>
+      @[[ @<declaration>^* @! @<doc-string> @]]
+      @<form>^*}
 \end{describe}
 
 \begin{describe}{gf}{parser-capture-place @<context> @> @<form>}
@@ -580,12 +652,17 @@ file-location protocols.
 \end{describe}
 
 \begin{describe}{mac}
-    {with-parser-place (@<place-var> @<context>) @<body-form>^*}
+    {with-parser-place (@<place-var> @<context>)
+      @[[ @<declaration>^* @! @<doc-string> @]]
+      @<form>^*}
 \end{describe}
 
 \begin{describe}{parseform}{peek @<parser>}
 \end{describe}
 
+\begin{describe}{parseform}{commit}
+\end{describe}
+
 \begin{describe}{cls}{character-parser-context () \&key}
 \end{describe}
 
@@ -667,7 +744,7 @@ file-location protocols.
 \end{describe}
 
 \begin{describe}{parseform}
-    {expr \=(@[[ :nestedp @<nestedp-var> @]]) \+ \\
+    {expr \=(@[[ :nestedp @<nestedp-var> @]])                 \+\\
             @<operand-parser> @<binop-parser>
             @<preop-parser> @<postop-parser>}
 \end{describe}
@@ -693,25 +770,26 @@ file-location protocols.
 
 \begin{describe*}
     {\quad\=\kill
-     \dhead{cls}{simple-binary-operator (simple-operator) \\ \>
-                  \&key :name :function :lprec :rprec :associativity}
+     \dhead{cls}{simple-binary-operator (simple-operator)       \\ \>
+                  \&key :name :function
+                        :lprec :rprec :associativity}
      \dhead{cls}{simple-postfix-operator (simple-unary-operator) \\ \>
                   \&key :name :function :lprec :rprec}
      \dhead{cls}{simple-prefix-operator
-                    (prefix-operator simple-unary-operator) \\ \>
+                    (prefix-operator simple-unary-operator)     \\ \>
                   \&key :name :function :rprec}}
 \end{describe*}
 
 \begin{describe*}
     {\dhead{mac}{preop @<name> (@<operand-var> @<lprec>)
-                  @<body-form>^*
+                  @<declaration>^* @<form>^*
                   @> @<prefix-operator>}
      \dhead{mac}{postop @<name>
                      (@<operand-var> @<lprec> @[[ :rprec @<rprec> @]])
-                  @<body-form>^*
-                  @> @<postfix-operator>}
+                  @<declaration>^* @<form>^*
+                  \nlret @<postfix-operator>}
      \dhead{mac}{binop @<name> (@<operand-var> @<lprec> @<rprec> @<assoc>)
-                  @<body-form>^*
+                  @<declaration>^*@<form>^*
                   @> @<binary-operator>}}
 \end{describe*}
 
@@ -737,18 +815,34 @@ file-location protocols.
 \begin{describe}{fun}{define-indicator @<indicator> @<description>}
 \end{describe}
 
-\begin{describe}{fun}{syntax-error @<scanner> @<expected> \&key :continuep}
+\begin{describe*}
+    {\dhead{cls}{lexer-error (parser-error base-lexer-error) \\ \ind
+                    \&key :expected :found :location \-}
+     \dhead{cls}{syntax-error (parser-error base-syntax-error) \\ \ind
+                    \&key :expected :found :location \-}}
+\end{describe*}
+
+\begin{describe}{fun}
+    {syntax-error @<scanner> @<expected> \&key :continuep :location}
 \end{describe}
 
 \begin{describe}{fun}
-    {lexer-error @<char-scanner> @<expected> @<consumed-flag>}
+    {lexer-error @<char-scanner> @<expected> \&key :location}
 \end{describe}
 
 \begin{describe}{parseform}
     {skip-until (@[[ :keep-end @<keep-end-flag> @]]) @<token-type>^*}
 \end{describe}
 
-\begin{describe}{parseform}{error () @<sub-parser> @<recover-parser>}
+\begin{describe}{parseform}
+    {error (@[[ :ignore-unconsumed @<flag> @!
+                :force-process @<flag> @]])                     \\ \ind\ind
+        @<sub-parser> @<recover-parser>                       \-\\
+      @<declaration>^*                                          \\
+      @<form>^*}
+\end{describe}
+
+\begin{describe}{parseform}{must @<sub-parser> @[@<default>@]}
 \end{describe}
 
 \begin{describe}{fun}