From 33f7721f8d62e448da98828a9330bee369ad76e1 Mon Sep 17 00:00:00 2001 From: Alex Klinkhamer Date: Sun, 6 Jul 2008 18:56:54 -0400 Subject: [PATCH] +Better naming for main parser functions parse-input-from-string now defaults to infix-style, see the optional argument infixp --- src/globals.lisp | 1 - src/infix-parser.lisp | 16 +++++++++++----- src/prefix-parser.lisp | 35 ++++++++++++----------------------- src/save-restore.lisp | 8 ++++---- src/webui/calcupage.lisp | 10 ++++------ 5 files changed, 31 insertions(+), 39 deletions(-) diff --git a/src/globals.lisp b/src/globals.lisp index 962f003..c9fef42 100644 --- a/src/globals.lisp +++ b/src/globals.lisp @@ -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) diff --git a/src/infix-parser.lisp b/src/infix-parser.lisp index 1b1b209..680071e 100644 --- a/src/infix-parser.lisp +++ b/src/infix-parser.lisp @@ -298,8 +298,6 @@ (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)) @@ -332,8 +330,16 @@ 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))) + diff --git a/src/prefix-parser.lisp b/src/prefix-parser.lisp index b6706ff..aac90d7 100644 --- a/src/prefix-parser.lisp +++ b/src/prefix-parser.lisp @@ -22,22 +22,16 @@ (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 @@ -47,14 +41,9 @@ (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.")))) diff --git a/src/save-restore.lisp b/src/save-restore.lisp index 12f1a6b..602e5bd 100644 --- a/src/save-restore.lisp +++ b/src/save-restore.lisp @@ -40,10 +40,10 @@ :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 diff --git a/src/webui/calcupage.lisp b/src/webui/calcupage.lisp index c8e1dd4..4f581bc 100644 --- a/src/webui/calcupage.lisp +++ b/src/webui/calcupage.lisp @@ -11,12 +11,10 @@ (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) -- 2.11.4.GIT