+Better naming for main parser functions
authorAlex Klinkhamer <grencez@gmail.com>
Sun, 6 Jul 2008 22:56:54 +0000 (6 18:56 -0400)
committerAlex Klinkhamer <grencez@gmail.com>
Sun, 6 Jul 2008 22:56:54 +0000 (6 18:56 -0400)
parse-input-from-string now defaults to infix-style,
see the optional argument infixp

src/globals.lisp
src/infix-parser.lisp
src/prefix-parser.lisp
src/save-restore.lisp
src/webui/calcupage.lisp

index 962f003..c9fef42 100644 (file)
@@ -8,7 +8,6 @@
            recall-vrbl store-vrbl
            process-input-from-stream
            process-input-from-string
-           process-infix-from-string
            save-to-stream restore-from-stream))
 
 (in-package :lineal)
index 1b1b209..680071e 100644 (file)
 
 (defun process-infix-from-stream (strm)
   (let ((*readtable* (copy-readtable))
-        (*read-default-float-format* 'double-float)
-        (*read-eval* nil)
         (*unwind-rank-fn*
           (lambda (op-rank val)
             (declare (ignore op-rank))
           nil "Evaluation flopped, perhaps bad input?~%~
           Debug info: ~A~%" condit)))))
 
-(defun process-infix-from-string (str)
-  (with-input-from-string (strm str)
-    (process-infix-from-stream strm)))
+(defun process-input-from-stream
+  (strm &optional (infixp t))
+  (let ((*read-default-float-format* 'double-float)
+        (*read-eval* nil))
+    (if infixp (process-infix-from-stream strm)
+      (process-prefix-from-stream strm))))
 
+(defun process-input-from-string
+  (text &optional (infixp t))
+  (with-input-from-string (strm text)
+    (process-input-from-stream strm infixp)))
 
+    
index b6706ff..aac90d7 100644 (file)
 (defmethod expr-parse ((expr number)) expr)
 (defmethod expr-parse ((expr string)) expr)
 
-(defun eval-parsed (s-exprs &aux (answer nil))
-  (unwind-protect
-    (setq answer
-          (catch 'over-ex
-                 (with-output-to-string (strm)
-                   (over-format (eval s-exprs) strm))))
-    (return-from
-      eval-parsed
-      (if answer answer
-        (format nil "Something went wrong during eval, ~
-                you probably used a function with bad parameters.")))))
-
-(defun process-input-from-stream (strm)
-  (let ((*readtable* (copy-readtable))
-        (*read-default-float-format* 'double-float)
-        (*read-eval* nil))
+(defun eval-parsed (s-exprs)
+  (handler-case
+    (catch 'over-ex (eval s-exprs))
+    (error (conditn)
+           (declare (ignore conditn))
+           (format nil "Something went wrong during eval, ~
+                   you probably used a function with bad parameters."))))
+
+(defun process-prefix-from-stream (strm)
+  (let ((*readtable* (copy-readtable)))
     (setf (readtable-case *readtable*) :preserve)
     (handler-case
       (catch
           (let ((*package*
                   (find-package :lineal.client-vars)))
             (setq expr (read strm nil nil)))
-          (unless expr (return (values result t)))
+          (unless expr (return result))
           (setq result (eval-parsed (expr-parse expr)))))
       (error (conditn)
              (declare (ignore conditn))
-             (values "You probably forgot to add a closing parenthesis."
-                     nil)))))
-
-(defun process-input-from-string (text)
-  (with-input-from-string (strm text)
-    (process-input-from-stream strm)))
+             "You probably forgot to add a closing parenthesis."))))
 
index 12f1a6b..602e5bd 100644 (file)
         :do (persist-var-to k strm)))
 
 (defun restore-from-stream (strm)
-  (multiple-value-bind
-    (result-msg success-p) (process-input-from-stream strm)
-    (if success-p "Variables successfully restored."
-      (format nil "ERROR  ~A" result-msg))))
+  (let ((result (process-input-from-stream strm nil)))
+    (if (stringp result)
+      (format nil "ERROR  ~A" result)
+      "Variables successfully restored.")))
 
 ;V Save a session capture file.V
 (defun local-capture
index c8e1dd4..4f581bc 100644 (file)
   (when log-calcs (log-message* "parser receives: ~%~A" text))
   (setq
     text
-    (if infixp
-      (with-output-to-string (strm)
-        (over-format
-          (process-infix-from-string text)
-          strm))
-      (process-input-from-string text)))
+    (with-output-to-string (strm)
+      (over-format
+        (process-input-from-string text infixp)
+        strm)))
   (when log-calcs (log-message* "parser replies: ~%~A" text))
   text)