+Better naming for main parser functions
[lineal.git] / src / webui / calcupage.lisp
blob4f581bc1904313131e994d2bfda501218392fc62
2 (in-package :lineal.webui)
4 ;V URL: /process-infix
5 ;V Receive user's calculation, return result.V
6 (defun receive-and-process
7 (&optional (infixp t)
8 &aux (text (parameter "text"))
9 (log-calcs (load-time-value
10 (boundp 'lineal.devvars::log-calcs))))
11 (when log-calcs (log-message* "parser receives: ~%~A" text))
12 (setq
13 text
14 (with-output-to-string (strm)
15 (over-format
16 (process-input-from-string text infixp)
17 strm)))
18 (when log-calcs (log-message* "parser replies: ~%~A" text))
19 text)
21 ;V URL: /process-prefix
22 (defun receive-and-process-prefix ()
23 (receive-and-process nil))
25 (defmacro htm-expand-known-if
26 (strm infixp s-expr)
27 `(princ
28 (if ,infixp
29 (load-time-value (,@s-expr t))
30 (load-time-value (,@s-expr nil)))
31 ,strm))
33 ;V URL: /calcupage-infix
34 (defun calcupage (&optional (infixp t))
35 (with-html-output-to-string
36 (s nil :prologue t)
37 (:html
38 (:head
39 (:title "Calculate things.")
40 (:link :rel "stylesheet" :href "calcupage.css")
41 (jsfile s "calcupage")
42 (jsfile s "connects"))
43 (:body
44 (:div (:a :href "/input_matrix" "Create and edit")
45 " vectors and matrices" :br
46 "Use "
47 (if infixp
48 (htm (:a :href "/calcupage-prefix" "prefix"))
49 (htm (:a :href "/calcupage-infix" "infix")))
50 " notation instead." :br
51 (:a :href "/" "Main") " Page")
52 (:table
53 :width "100%"
54 (:tr
55 (:th :rowspan "2" :class "linalg-buttons"
56 (htm-expand-known-if
57 s infixp (htm-linalg-buttons)))
58 (:th :rowspan "2" :class "stdmath-buttons"
59 ;V Show operator buttons on left.V
60 (htm-expand-known-if
61 s infixp (htm-standard-math-buttons)))
62 ;V Before variable names, show some easy-access buttons.V
63 (:td :class "quick-buttons"
64 (htm-expand-known-if
65 s infixp (memory-buttons))
66 (princ
67 (load-time-value
68 (concatenate
69 'string "<br/>"
70 (clear-button)
71 (htm-input-button
72 "&quot;" "fn1" "\\\"")
73 (ok-button)))
74 s))
75 ;V Show variables on the top.V
76 (:td
77 (do ((lvpairs-left
78 `(("Numbers: " ,*saved-numbers*)
79 ("Vectors: " ,*saved-tuples*)
80 ("Matrices: " ,*saved-matrices*))))
81 (nil)
82 (princ (caar lvpairs-left) s)
83 (dolist (k (cadar lvpairs-left))
84 (princ (simple-input-button k "varbutton") s))
85 (unless (setq lvpairs-left (cdr lvpairs-left))
86 (return (values)))
87 (princ "<br/>" s))))
88 ;V main textarea V
89 (:tr (:td :colspan "2"
90 (:textarea :id "calcIn" :spellcheck "false"))))
91 ;V Make a place to show results.V
92 (:pre :id "resultPre")
93 (if infixp (ps-tag s (setf process-loc "/process-infix"))
94 (ps-tag s (setf process-loc "/process-prefix")))
95 (ps-tag
96 s (setf calc-in (.get-element-by-id document "calcIn")))))))
98 ;V URL: /calcupage-prefix
99 (defun calcupage-prefix ()
100 (calcupage nil))