chiark / gitweb /
src/parser/parse-expr-{proto,impl}.lisp: Fully hide the parser state.
authorMark Wooding <mdw@distorted.org.uk>
Thu, 8 Aug 2019 10:17:14 +0000 (11:17 +0100)
committerMark Wooding <mdw@distorted.org.uk>
Thu, 8 Aug 2019 10:24:05 +0000 (11:24 +0100)
We didn't publish the ability to pop things, so external implementers
are rather limited in their options.  Withdraw this entirely.

The `push-operator' and `apply-operator' generic functions are now
internal.  The `push-value' function is gone entirely: the only caller
was `parse-expression', and that now simply pushes the value onto the
stack directly.

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

index 4de08601f23e2da34a28983bd42a20a0957ac483..33d4b9549a9aba2230dfa524479951b686d767eb 100644 (file)
@@ -1706,7 +1706,6 @@ floc-proto.lisp
   with-default-error-location                   macro
 
 parser-expr-proto.lisp
   with-default-error-location                   macro
 
 parser-expr-proto.lisp
-  apply-operator                                generic
   binop                                         macro
   close-parenthesis                             class
   expr                                          parser-form
   binop                                         macro
   close-parenthesis                             class
   expr                                          parser-form
@@ -1719,8 +1718,6 @@ parser-expr-proto.lisp
   postop                                        macro
   prefix-operator                               class
   preop                                         macro
   postop                                        macro
   prefix-operator                               class
   preop                                         macro
-  push-operator                                 generic
-  push-value                                    generic
   rparen                                        function
   simple-binary-operator                        class
   simple-operator                               class
   rparen                                        function
   simple-binary-operator                        class
   simple-operator                               class
@@ -1996,10 +1993,6 @@ cl:t
             position-aware-input-stream [position-aware-stream]
 
 Methods:
             position-aware-input-stream [position-aware-stream]
 
 Methods:
-apply-operator
-  open-parenthesis sod-parser::expression-parse-state
-  simple-binary-operator sod-parser::expression-parse-state
-  simple-unary-operator sod-parser::expression-parse-state
 charbuf-scanner-map
   charbuf-scanner t
 classify-condition
 charbuf-scanner-map
   charbuf-scanner t
 classify-condition
@@ -2148,13 +2141,6 @@ position-aware-stream-line
 cl:print-object
   file-location t
   simple-operator t
 cl:print-object
   file-location t
   simple-operator t
-push-operator
-  t sod-parser::expression-parse-state
-  close-parenthesis sod-parser::expression-parse-state
-  open-parenthesis sod-parser::expression-parse-state [:after]
-  prefix-operator sod-parser::expression-parse-state
-push-value
-  t sod-parser::expression-parse-state
 scanner-at-eof-p
   charbuf-scanner
   list-scanner
 scanner-at-eof-p
   charbuf-scanner
   list-scanner
index 0d9bf0470f581ccd2a5299977afc2e0ef7e510b9..22960ee8877772ef059fbcdf5c6b7e02443ecd8e 100644 (file)
@@ -819,15 +819,6 @@ file-location protocols.
 
 \subsection{Expression parsing} \label{sec:parsing.syntax.expression}
 
 
 \subsection{Expression parsing} \label{sec:parsing.syntax.expression}
 
-\begin{describe}{gf}{push-operator @<operator> @<state>}
-\end{describe}
-
-\begin{describe}{gf}{push-value @<value> @<state>}
-\end{describe}
-
-\begin{describe}{gf}{apply-operator @<operator> @<state>}
-\end{describe}
-
 \begin{describe}{gf}{operator-push-action @<left> @<right>}
 \end{describe}
 
 \begin{describe}{gf}{operator-push-action @<left> @<right>}
 \end{describe}
 
index 16e0c5331864f9ab1d6fe1ebb19fe63d48fbe0e4..d4bc3a09ca0059e101d84a5369e72a0cd902eb3b 100644 (file)
@@ -26,7 +26,7 @@
 (cl:in-package #:sod-parser)
 
 ;;;--------------------------------------------------------------------------
 (cl:in-package #:sod-parser)
 
 ;;;--------------------------------------------------------------------------
-;;; Basic protocol implementation.
+;;; Basic protocol.
 
 (defclass expression-parse-state ()
   ((opstack :initform nil :type list)
 
 (defclass expression-parse-state ()
   ((opstack :initform nil :type list)
@@ -35,9 +35,18 @@ (defclass expression-parse-state ()
   (:documentation
    "State for the expression parser.  Largely passive."))
 
   (:documentation
    "State for the expression parser.  Largely passive."))
 
-(defmethod push-value (value (state expression-parse-state))
-  (with-slots (valstack) state
-    (push value valstack)))
+(defgeneric push-operator (operator state)
+  (:documentation
+   "Push an OPERATOR onto the STATE's operator stack.
+
+   This should apply existing stacked operators as necessary to obey the
+   language's precedence rules."))
+
+(defgeneric apply-operator (operator state)
+  (:documentation
+   "Apply the OPERATOR to arguments on the STATE's value stack.
+
+   This should pop any necessary arguments, and push the result."))
 
 (defmethod push-operator (operator (state expression-parse-state))
   (with-slots (opstack) state
 
 (defmethod push-operator (operator (state expression-parse-state))
   (with-slots (opstack) state
@@ -204,7 +213,7 @@ (defun parse-expression (p-operand p-binop p-preop p-postop)
                       (push-operator value state)))
               (multiple-value-bind (value winp) (parse p-operand)
                 (unless winp (fail value))
                       (push-operator value state)))
               (multiple-value-bind (value winp) (parse p-operand)
                 (unless winp (fail value))
-                (push-value value state))
+                (push value (slot-value state 'valstack)))
               (loop (multiple-value-bind (value winp) (parse p-postop)
                       (unless winp (return))
                       (push-operator value state)))))
               (loop (multiple-value-bind (value winp) (parse p-postop)
                       (unless winp (return))
                       (push-operator value state)))))
index 326f3e5714d5066ddd5ad452ed0ee736d02d3828..9052e54a65277cb58eec25e3e4fa7264ef9776f5 100644 (file)
@@ -28,29 +28,6 @@ (cl:in-package #:sod-parser)
 ;;;--------------------------------------------------------------------------
 ;;; Basic protocol.
 
 ;;;--------------------------------------------------------------------------
 ;;; Basic protocol.
 
-(export 'push-operator)
-(defgeneric push-operator (operator state)
-  (:documentation
-   "Push an OPERATOR onto the STATE's operator stack.
-
-   This should apply existing stacked operators as necessary to obey the
-   language's precedence rules."))
-
-(export 'push-value)
-(defgeneric push-value (value state)
-  (:documentation
-   "Push VALUE onto the STATE's value stack.
-
-   The default method just does that without any fuss.  It's unlikely that
-   this will need changing unless you invent some really weird values."))
-
-(export 'apply-operator)
-(defgeneric apply-operator (operator state)
-  (:documentation
-   "Apply the OPERATOR to argument on the STATE's value stack.
-
-   This should pop any necessary arguments, and push the result."))
-
 (export 'operator-push-action)
 (defgeneric operator-push-action (left right)
   (:documentation
 (export 'operator-push-action)
 (defgeneric operator-push-action (left right)
   (:documentation
@@ -149,9 +126,7 @@ (defclass prefix-operator ()
    Prefix operators are special because they are pushed at a time when the
    existing topmost operator on the stack may not have its operand
    available.  It is therefore incorrect to attempt to apply any existing
    Prefix operators are special because they are pushed at a time when the
    existing topmost operator on the stack may not have its operand
    available.  It is therefore incorrect to attempt to apply any existing
-   operators without careful checking.  This class provides a method on
-   `push-operator' which immediately pushes the new operator without
-   inspecting the existing stack."))
+   operators without careful checking."))
 
 (export 'simple-operator)
 (defclass simple-operator ()
 
 (export 'simple-operator)
 (defclass simple-operator ()