src/pset-parse.lisp: Bring `dispatch' within `parse-expression'.
authorMark Wooding <mdw@distorted.org.uk>
Mon, 19 Aug 2019 19:44:32 +0000 (20:44 +0100)
committerMark Wooding <mdw@distorted.org.uk>
Mon, 19 Aug 2019 19:44:32 +0000 (20:44 +0100)
There's nothing to be gained from keeping it outside: the `expr' parser
caching works on entry to the parser, rather than once only.

src/pset-parse.lisp

index 7091016..0f3e482 100644 (file)
 ;;;--------------------------------------------------------------------------
 ;;; The expression parser.
 
-(flet ((dispatch (name args &rest spec)
-        (acond ((find :invalid args :key #'car)
-                (cons :invalid nil))
-               ((find-if (lambda (item)
-                           (every (lambda (type arg)
-                                    (eql type (car arg)))
-                                  (cddr item)
-                                  args))
-                         spec)
-                (cons (car it) (apply (cadr it)
-                                      (mapcar #'cdr args))))
-               (t
-                (cerror* "Type mismatch: operator `~A' applied to ~
-                              types ~{~(~A~)~#[~; and ~;, ~]~}"
-                         name
-                         (mapcar #'car args))
-                (cons :invalid nil)))))
-
-  (defun parse-expression (scanner)
-    "Parse and evaluate a simple expression.
+(defun parse-expression (scanner)
+  "Parse and evaluate a simple expression.
 
    The result is a pair (TYPE . VALUE).  Currently, type types are `:id',
    `:int', `:string', `:char', `:fragment', `:type'.  If an error prevented a
      | `<' declspec+ declarator[empty] `>' | `?' lisp-expression
 
    Only operators for dealing with integers are provided."
+
+  (flet ((dispatch (name args &rest spec)
+          (acond ((find :invalid args :key #'car)
+                  (cons :invalid nil))
+                 ((find-if (lambda (item)
+                             (every (lambda (type arg)
+                                      (eql type (car arg)))
+                                    (cddr item)
+                                    args))
+                           spec)
+                  (cons (car it) (apply (cadr it)
+                                        (mapcar #'cdr args))))
+                 (t
+                  (cerror* "Type mismatch: operator `~A' applied to ~
+                                types ~{~(~A~)~#[~; and ~;, ~]~}"
+                           name
+                           (mapcar #'car args))
+                  (cons :invalid nil)))))
+
     (with-parser-context (token-scanner-context :scanner scanner)
       (parse (expr (:nestedp nestedp)
               (lisp (flet ((prop (type value)