Mercurial > emacs
annotate lisp/calc/calc-lang.el @ 58640:0241e1689d7f
(vc-cvs-state): Handle the case where vc-state is still nil.
author | André Spiegel <spiegel@gnu.org> |
---|---|
date | Tue, 30 Nov 2004 11:02:23 +0000 |
parents | 4ca47d70b075 |
children | 10224395a3c2 |
rev | line source |
---|---|
41271
fcd507927105
Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
1 ;;; calc-lang.el --- calc language functions |
fcd507927105
Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
2 |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
3 ;; Copyright (C) 1990, 1991, 1992, 1993, 2001 Free Software Foundation, Inc. |
41271
fcd507927105
Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
4 |
fcd507927105
Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
5 ;; Author: David Gillespie <daveg@synaptics.com> |
58411
9ceda393e263
(math-read-big-lines): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58134
diff
changeset
|
6 ;; Maintainer: Jay Belanger <belanger@truman.edu> |
40785 | 7 |
8 ;; This file is part of GNU Emacs. | |
9 | |
10 ;; GNU Emacs is distributed in the hope that it will be useful, | |
11 ;; but WITHOUT ANY WARRANTY. No author or distributor | |
12 ;; accepts responsibility to anyone for the consequences of using it | |
13 ;; or for whether it serves any particular purpose or works at all, | |
14 ;; unless he says so in writing. Refer to the GNU Emacs General Public | |
15 ;; License for full details. | |
16 | |
17 ;; Everyone is granted permission to copy, modify and redistribute | |
18 ;; GNU Emacs, but only under the conditions described in the | |
19 ;; GNU Emacs General Public License. A copy of this license is | |
20 ;; supposed to have been given to you along with GNU Emacs so you | |
21 ;; can know your rights and responsibilities. It should be in a | |
22 ;; file named COPYING. Among other things, the copyright notice | |
23 ;; and this notice must be preserved on all copies. | |
24 | |
41271
fcd507927105
Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
25 ;;; Commentary: |
fcd507927105
Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
26 |
fcd507927105
Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
27 ;;; Code: |
40785 | 28 |
29 | |
30 ;; This file is autoloaded from calc-ext.el. | |
31 (require 'calc-ext) | |
32 | |
33 (require 'calc-macs) | |
34 | |
35 (defun calc-Need-calc-lang () nil) | |
36 | |
37 | |
38 ;;; Alternate entry/display languages. | |
39 | |
40 (defun calc-set-language (lang &optional option no-refresh) | |
41 (setq math-expr-opers (or (get lang 'math-oper-table) math-standard-opers) | |
42 math-expr-function-mapping (get lang 'math-function-table) | |
43 math-expr-variable-mapping (get lang 'math-variable-table) | |
44 calc-language-input-filter (get lang 'math-input-filter) | |
45 calc-language-output-filter (get lang 'math-output-filter) | |
46 calc-vector-brackets (or (get lang 'math-vector-brackets) "[]") | |
47 calc-complex-format (get lang 'math-complex-format) | |
48 calc-radix-formatter (get lang 'math-radix-formatter) | |
49 calc-function-open (or (get lang 'math-function-open) "(") | |
50 calc-function-close (or (get lang 'math-function-close) ")")) | |
51 (if no-refresh | |
52 (setq calc-language lang | |
53 calc-language-option option) | |
54 (calc-change-mode '(calc-language calc-language-option) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
55 (list lang option) t))) |
40785 | 56 |
57 (defun calc-normal-language () | |
58 (interactive) | |
59 (calc-wrapper | |
60 (calc-set-language nil) | |
41271
fcd507927105
Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
61 (message "Normal language mode"))) |
40785 | 62 |
63 (defun calc-flat-language () | |
64 (interactive) | |
65 (calc-wrapper | |
66 (calc-set-language 'flat) | |
41271
fcd507927105
Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
67 (message "Flat language mode (all stack entries shown on one line)"))) |
40785 | 68 |
69 (defun calc-big-language () | |
70 (interactive) | |
71 (calc-wrapper | |
72 (calc-set-language 'big) | |
41271
fcd507927105
Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
73 (message "\"Big\" language mode"))) |
40785 | 74 |
75 (defun calc-unformatted-language () | |
76 (interactive) | |
77 (calc-wrapper | |
78 (calc-set-language 'unform) | |
41271
fcd507927105
Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
79 (message "Unformatted language mode"))) |
40785 | 80 |
81 | |
82 (defun calc-c-language () | |
83 (interactive) | |
84 (calc-wrapper | |
85 (calc-set-language 'c) | |
41271
fcd507927105
Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
86 (message "`C' language mode"))) |
40785 | 87 |
88 (put 'c 'math-oper-table | |
89 '( ( "u+" ident -1 1000 ) | |
90 ( "u-" neg -1 1000 ) | |
91 ( "u!" calcFunc-lnot -1 1000 ) | |
92 ( "~" calcFunc-not -1 1000 ) | |
93 ( "*" * 190 191 ) | |
94 ( "/" / 190 191 ) | |
95 ( "%" % 190 191 ) | |
96 ( "+" + 180 181 ) | |
97 ( "-" - 180 181 ) | |
98 ( "<<" calcFunc-lsh 170 171 ) | |
99 ( ">>" calcFunc-rsh 170 171 ) | |
100 ( "<" calcFunc-lt 160 161 ) | |
101 ( ">" calcFunc-gt 160 161 ) | |
102 ( "<=" calcFunc-leq 160 161 ) | |
103 ( ">=" calcFunc-geq 160 161 ) | |
104 ( "==" calcFunc-eq 150 151 ) | |
105 ( "!=" calcFunc-neq 150 151 ) | |
106 ( "&" calcFunc-and 140 141 ) | |
107 ( "^" calcFunc-xor 131 130 ) | |
108 ( "|" calcFunc-or 120 121 ) | |
109 ( "&&" calcFunc-land 110 111 ) | |
110 ( "||" calcFunc-lor 100 101 ) | |
111 ( "?" (math-read-if) 91 90 ) | |
112 ( "!!!" calcFunc-pnot -1 88 ) | |
113 ( "&&&" calcFunc-pand 85 86 ) | |
114 ( "|||" calcFunc-por 75 76 ) | |
115 ( "=" calcFunc-assign 51 50 ) | |
116 ( ":=" calcFunc-assign 51 50 ) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
117 ( "::" calcFunc-condition 45 46 ))) ; should support full assignments |
40785 | 118 |
119 (put 'c 'math-function-table | |
120 '( ( acos . calcFunc-arccos ) | |
121 ( acosh . calcFunc-arccosh ) | |
122 ( asin . calcFunc-arcsin ) | |
123 ( asinh . calcFunc-arcsinh ) | |
124 ( atan . calcFunc-arctan ) | |
125 ( atan2 . calcFunc-arctan2 ) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
126 ( atanh . calcFunc-arctanh ))) |
40785 | 127 |
128 (put 'c 'math-variable-table | |
129 '( ( M_PI . var-pi ) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
130 ( M_E . var-e ))) |
40785 | 131 |
132 (put 'c 'math-vector-brackets "{}") | |
133 | |
134 (put 'c 'math-radix-formatter | |
135 (function (lambda (r s) | |
136 (if (= r 16) (format "0x%s" s) | |
137 (if (= r 8) (format "0%s" s) | |
138 (format "%d#%s" r s)))))) | |
139 | |
140 | |
141 (defun calc-pascal-language (n) | |
142 (interactive "P") | |
143 (calc-wrapper | |
144 (and n (setq n (prefix-numeric-value n))) | |
145 (calc-set-language 'pascal n) | |
146 (message (if (and n (/= n 0)) | |
147 (if (> n 0) | |
41271
fcd507927105
Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
148 "Pascal language mode (all uppercase)" |
fcd507927105
Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
149 "Pascal language mode (all lowercase)") |
fcd507927105
Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
150 "Pascal language mode")))) |
40785 | 151 |
152 (put 'pascal 'math-oper-table | |
153 '( ( "not" calcFunc-lnot -1 1000 ) | |
154 ( "*" * 190 191 ) | |
155 ( "/" / 190 191 ) | |
156 ( "and" calcFunc-and 190 191 ) | |
157 ( "div" calcFunc-idiv 190 191 ) | |
158 ( "mod" % 190 191 ) | |
159 ( "u+" ident -1 185 ) | |
160 ( "u-" neg -1 185 ) | |
161 ( "+" + 180 181 ) | |
162 ( "-" - 180 181 ) | |
163 ( "or" calcFunc-or 180 181 ) | |
164 ( "xor" calcFunc-xor 180 181 ) | |
165 ( "shl" calcFunc-lsh 180 181 ) | |
166 ( "shr" calcFunc-rsh 180 181 ) | |
167 ( "in" calcFunc-in 160 161 ) | |
168 ( "<" calcFunc-lt 160 161 ) | |
169 ( ">" calcFunc-gt 160 161 ) | |
170 ( "<=" calcFunc-leq 160 161 ) | |
171 ( ">=" calcFunc-geq 160 161 ) | |
172 ( "=" calcFunc-eq 160 161 ) | |
173 ( "<>" calcFunc-neq 160 161 ) | |
174 ( "!!!" calcFunc-pnot -1 85 ) | |
175 ( "&&&" calcFunc-pand 80 81 ) | |
176 ( "|||" calcFunc-por 75 76 ) | |
177 ( ":=" calcFunc-assign 51 50 ) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
178 ( "::" calcFunc-condition 45 46 ))) |
40785 | 179 |
180 (put 'pascal 'math-input-filter 'calc-input-case-filter) | |
181 (put 'pascal 'math-output-filter 'calc-output-case-filter) | |
182 | |
183 (put 'pascal 'math-radix-formatter | |
184 (function (lambda (r s) | |
185 (if (= r 16) (format "$%s" s) | |
186 (format "%d#%s" r s))))) | |
187 | |
188 (defun calc-input-case-filter (str) | |
189 (cond ((or (null calc-language-option) (= calc-language-option 0)) | |
190 str) | |
191 (t | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
192 (downcase str)))) |
40785 | 193 |
194 (defun calc-output-case-filter (str) | |
195 (cond ((or (null calc-language-option) (= calc-language-option 0)) | |
196 str) | |
197 ((> calc-language-option 0) | |
198 (upcase str)) | |
199 (t | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
200 (downcase str)))) |
40785 | 201 |
202 | |
203 (defun calc-fortran-language (n) | |
204 (interactive "P") | |
205 (calc-wrapper | |
206 (and n (setq n (prefix-numeric-value n))) | |
207 (calc-set-language 'fortran n) | |
208 (message (if (and n (/= n 0)) | |
209 (if (> n 0) | |
41271
fcd507927105
Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
210 "FORTRAN language mode (all uppercase)" |
fcd507927105
Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
211 "FORTRAN language mode (all lowercase)") |
fcd507927105
Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
212 "FORTRAN language mode")))) |
40785 | 213 |
214 (put 'fortran 'math-oper-table | |
215 '( ( "u/" (math-parse-fortran-vector) -1 1 ) | |
216 ( "/" (math-parse-fortran-vector-end) 1 -1 ) | |
217 ( "**" ^ 201 200 ) | |
218 ( "u+" ident -1 191 ) | |
219 ( "u-" neg -1 191 ) | |
220 ( "*" * 190 191 ) | |
221 ( "/" / 190 191 ) | |
222 ( "+" + 180 181 ) | |
223 ( "-" - 180 181 ) | |
224 ( ".LT." calcFunc-lt 160 161 ) | |
225 ( ".GT." calcFunc-gt 160 161 ) | |
226 ( ".LE." calcFunc-leq 160 161 ) | |
227 ( ".GE." calcFunc-geq 160 161 ) | |
228 ( ".EQ." calcFunc-eq 160 161 ) | |
229 ( ".NE." calcFunc-neq 160 161 ) | |
230 ( ".NOT." calcFunc-lnot -1 121 ) | |
231 ( ".AND." calcFunc-land 110 111 ) | |
232 ( ".OR." calcFunc-lor 100 101 ) | |
233 ( "!!!" calcFunc-pnot -1 85 ) | |
234 ( "&&&" calcFunc-pand 80 81 ) | |
235 ( "|||" calcFunc-por 75 76 ) | |
236 ( "=" calcFunc-assign 51 50 ) | |
237 ( ":=" calcFunc-assign 51 50 ) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
238 ( "::" calcFunc-condition 45 46 ))) |
40785 | 239 |
240 (put 'fortran 'math-vector-brackets "//") | |
241 | |
242 (put 'fortran 'math-function-table | |
243 '( ( acos . calcFunc-arccos ) | |
244 ( acosh . calcFunc-arccosh ) | |
245 ( aimag . calcFunc-im ) | |
246 ( aint . calcFunc-ftrunc ) | |
247 ( asin . calcFunc-arcsin ) | |
248 ( asinh . calcFunc-arcsinh ) | |
249 ( atan . calcFunc-arctan ) | |
250 ( atan2 . calcFunc-arctan2 ) | |
251 ( atanh . calcFunc-arctanh ) | |
252 ( conjg . calcFunc-conj ) | |
253 ( log . calcFunc-ln ) | |
254 ( nint . calcFunc-round ) | |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
49263
diff
changeset
|
255 ( real . calcFunc-re ))) |
40785 | 256 |
257 (put 'fortran 'math-input-filter 'calc-input-case-filter) | |
258 (put 'fortran 'math-output-filter 'calc-output-case-filter) | |
259 | |
58571
4ca47d70b075
(math-expr-data, math-expr-token, math-exp-old-pos): Declare them.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58411
diff
changeset
|
260 ;; The next few variables are local to math-read-exprs in calc-aent.el |
4ca47d70b075
(math-expr-data, math-expr-token, math-exp-old-pos): Declare them.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58411
diff
changeset
|
261 ;; and math-read-expr in calc-ext.el, but are set in functions they call. |
4ca47d70b075
(math-expr-data, math-expr-token, math-exp-old-pos): Declare them.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58411
diff
changeset
|
262 |
4ca47d70b075
(math-expr-data, math-expr-token, math-exp-old-pos): Declare them.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58411
diff
changeset
|
263 (defvar math-exp-token) |
4ca47d70b075
(math-expr-data, math-expr-token, math-exp-old-pos): Declare them.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58411
diff
changeset
|
264 (defvar math-expr-data) |
4ca47d70b075
(math-expr-data, math-expr-token, math-exp-old-pos): Declare them.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58411
diff
changeset
|
265 (defvar math-exp-old-pos) |
4ca47d70b075
(math-expr-data, math-expr-token, math-exp-old-pos): Declare them.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58411
diff
changeset
|
266 |
41271
fcd507927105
Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
267 (defvar math-parsing-fortran-vector nil) |
40785 | 268 (defun math-parse-fortran-vector (op) |
269 (let ((math-parsing-fortran-vector '(end . "\000"))) | |
270 (prog1 | |
271 (math-read-brackets t "]") | |
58134
3089957051ea
(math-parse-tex-sum): Use declared variable math-exp-old-pos.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58107
diff
changeset
|
272 (setq math-exp-token (car math-parsing-fortran-vector) |
58107
cfad3432f125
(math-parse-fortran-vector, math-parse-fortran-vector-end,
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
273 math-expr-data (cdr math-parsing-fortran-vector))))) |
40785 | 274 |
275 (defun math-parse-fortran-vector-end (x op) | |
276 (if math-parsing-fortran-vector | |
277 (progn | |
58134
3089957051ea
(math-parse-tex-sum): Use declared variable math-exp-old-pos.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58107
diff
changeset
|
278 (setq math-parsing-fortran-vector (cons math-exp-token math-expr-data) |
3089957051ea
(math-parse-tex-sum): Use declared variable math-exp-old-pos.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58107
diff
changeset
|
279 math-exp-token 'end |
58107
cfad3432f125
(math-parse-fortran-vector, math-parse-fortran-vector-end,
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
280 math-expr-data "\000") |
40785 | 281 x) |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
282 (throw 'syntax "Unmatched closing `/'"))) |
40785 | 283 |
284 (defun math-parse-fortran-subscr (sym args) | |
285 (setq sym (math-build-var-name sym)) | |
286 (while args | |
287 (setq sym (list 'calcFunc-subscr sym (car args)) | |
288 args (cdr args))) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
289 sym) |
40785 | 290 |
291 | |
292 (defun calc-tex-language (n) | |
293 (interactive "P") | |
294 (calc-wrapper | |
295 (and n (setq n (prefix-numeric-value n))) | |
296 (calc-set-language 'tex n) | |
297 (message (if (and n (/= n 0)) | |
298 (if (> n 0) | |
41271
fcd507927105
Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
299 "TeX language mode with \\hbox{func}(\\hbox{var})" |
fcd507927105
Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
300 "TeX language mode with \\func{\\hbox{var}}") |
fcd507927105
Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
301 "TeX language mode")))) |
40785 | 302 |
303 (put 'tex 'math-oper-table | |
304 '( ( "u+" ident -1 1000 ) | |
305 ( "u-" neg -1 1000 ) | |
306 ( "\\hat" calcFunc-hat -1 950 ) | |
307 ( "\\check" calcFunc-check -1 950 ) | |
308 ( "\\tilde" calcFunc-tilde -1 950 ) | |
309 ( "\\acute" calcFunc-acute -1 950 ) | |
310 ( "\\grave" calcFunc-grave -1 950 ) | |
311 ( "\\dot" calcFunc-dot -1 950 ) | |
312 ( "\\ddot" calcFunc-dotdot -1 950 ) | |
313 ( "\\breve" calcFunc-breve -1 950 ) | |
314 ( "\\bar" calcFunc-bar -1 950 ) | |
315 ( "\\vec" calcFunc-Vec -1 950 ) | |
316 ( "\\underline" calcFunc-under -1 950 ) | |
317 ( "u|" calcFunc-abs -1 0 ) | |
318 ( "|" closing 0 -1 ) | |
319 ( "\\lfloor" calcFunc-floor -1 0 ) | |
320 ( "\\rfloor" closing 0 -1 ) | |
321 ( "\\lceil" calcFunc-ceil -1 0 ) | |
322 ( "\\rceil" closing 0 -1 ) | |
323 ( "\\pm" sdev 300 300 ) | |
324 ( "!" calcFunc-fact 210 -1 ) | |
325 ( "^" ^ 201 200 ) | |
326 ( "_" calcFunc-subscr 201 200 ) | |
327 ( "\\times" * 191 190 ) | |
328 ( "*" * 191 190 ) | |
329 ( "2x" * 191 190 ) | |
330 ( "+" + 180 181 ) | |
331 ( "-" - 180 181 ) | |
332 ( "\\over" / 170 171 ) | |
333 ( "/" / 170 171 ) | |
334 ( "\\choose" calcFunc-choose 170 171 ) | |
335 ( "\\mod" % 170 171 ) | |
336 ( "<" calcFunc-lt 160 161 ) | |
337 ( ">" calcFunc-gt 160 161 ) | |
338 ( "\\leq" calcFunc-leq 160 161 ) | |
339 ( "\\geq" calcFunc-geq 160 161 ) | |
340 ( "=" calcFunc-eq 160 161 ) | |
341 ( "\\neq" calcFunc-neq 160 161 ) | |
342 ( "\\ne" calcFunc-neq 160 161 ) | |
343 ( "\\lnot" calcFunc-lnot -1 121 ) | |
344 ( "\\land" calcFunc-land 110 111 ) | |
345 ( "\\lor" calcFunc-lor 100 101 ) | |
346 ( "?" (math-read-if) 91 90 ) | |
347 ( "!!!" calcFunc-pnot -1 85 ) | |
348 ( "&&&" calcFunc-pand 80 81 ) | |
349 ( "|||" calcFunc-por 75 76 ) | |
350 ( "\\gets" calcFunc-assign 51 50 ) | |
351 ( ":=" calcFunc-assign 51 50 ) | |
352 ( "::" calcFunc-condition 45 46 ) | |
353 ( "\\to" calcFunc-evalto 40 41 ) | |
354 ( "\\to" calcFunc-evalto 40 -1 ) | |
355 ( "=>" calcFunc-evalto 40 41 ) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
356 ( "=>" calcFunc-evalto 40 -1 ))) |
40785 | 357 |
358 (put 'tex 'math-function-table | |
359 '( ( \\arccos . calcFunc-arccos ) | |
360 ( \\arcsin . calcFunc-arcsin ) | |
361 ( \\arctan . calcFunc-arctan ) | |
362 ( \\arg . calcFunc-arg ) | |
363 ( \\cos . calcFunc-cos ) | |
364 ( \\cosh . calcFunc-cosh ) | |
365 ( \\det . calcFunc-det ) | |
366 ( \\exp . calcFunc-exp ) | |
367 ( \\gcd . calcFunc-gcd ) | |
368 ( \\ln . calcFunc-ln ) | |
369 ( \\log . calcFunc-log10 ) | |
370 ( \\max . calcFunc-max ) | |
371 ( \\min . calcFunc-min ) | |
372 ( \\tan . calcFunc-tan ) | |
373 ( \\sin . calcFunc-sin ) | |
374 ( \\sinh . calcFunc-sinh ) | |
375 ( \\sqrt . calcFunc-sqrt ) | |
376 ( \\tanh . calcFunc-tanh ) | |
377 ( \\phi . calcFunc-totient ) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
378 ( \\mu . calcFunc-moebius ))) |
40785 | 379 |
380 (put 'tex 'math-variable-table | |
381 '( ( \\pi . var-pi ) | |
382 ( \\infty . var-inf ) | |
383 ( \\infty . var-uinf ) | |
384 ( \\phi . var-phi ) | |
385 ( \\gamma . var-gamma ) | |
386 ( \\sum . (math-parse-tex-sum calcFunc-sum) ) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
387 ( \\prod . (math-parse-tex-sum calcFunc-prod) ))) |
40785 | 388 |
389 (put 'tex 'math-complex-format 'i) | |
390 | |
391 (defun math-parse-tex-sum (f val) | |
392 (let (low high save) | |
58107
cfad3432f125
(math-parse-fortran-vector, math-parse-fortran-vector-end,
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
393 (or (equal math-expr-data "_") (throw 'syntax "Expected `_'")) |
40785 | 394 (math-read-token) |
58134
3089957051ea
(math-parse-tex-sum): Use declared variable math-exp-old-pos.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58107
diff
changeset
|
395 (setq save math-exp-old-pos) |
40785 | 396 (setq low (math-read-factor)) |
397 (or (eq (car-safe low) 'calcFunc-eq) | |
398 (progn | |
58134
3089957051ea
(math-parse-tex-sum): Use declared variable math-exp-old-pos.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58107
diff
changeset
|
399 (setq math-exp-old-pos (1+ save)) |
40785 | 400 (throw 'syntax "Expected equation"))) |
58107
cfad3432f125
(math-parse-fortran-vector, math-parse-fortran-vector-end,
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
401 (or (equal math-expr-data "^") (throw 'syntax "Expected `^'")) |
40785 | 402 (math-read-token) |
403 (setq high (math-read-factor)) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
404 (list (nth 2 f) (math-read-factor) (nth 1 low) (nth 2 low) high))) |
40785 | 405 |
406 (defun math-tex-input-filter (str) ; allow parsing of 123\,456\,789. | |
407 (while (string-match "[0-9]\\\\,[0-9]" str) | |
408 (setq str (concat (substring str 0 (1+ (match-beginning 0))) | |
409 (substring str (1- (match-end 0)))))) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
410 str) |
40785 | 411 (put 'tex 'math-input-filter 'math-tex-input-filter) |
412 | |
413 | |
414 (defun calc-eqn-language (n) | |
415 (interactive "P") | |
416 (calc-wrapper | |
417 (calc-set-language 'eqn) | |
41271
fcd507927105
Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
418 (message "Eqn language mode"))) |
40785 | 419 |
420 (put 'eqn 'math-oper-table | |
421 '( ( "u+" ident -1 1000 ) | |
422 ( "u-" neg -1 1000 ) | |
423 ( "prime" (math-parse-eqn-prime) 950 -1 ) | |
424 ( "prime" calcFunc-Prime 950 -1 ) | |
425 ( "dot" calcFunc-dot 950 -1 ) | |
426 ( "dotdot" calcFunc-dotdot 950 -1 ) | |
427 ( "hat" calcFunc-hat 950 -1 ) | |
428 ( "tilde" calcFunc-tilde 950 -1 ) | |
429 ( "vec" calcFunc-Vec 950 -1 ) | |
430 ( "dyad" calcFunc-dyad 950 -1 ) | |
431 ( "bar" calcFunc-bar 950 -1 ) | |
432 ( "under" calcFunc-under 950 -1 ) | |
433 ( "sub" calcFunc-subscr 931 930 ) | |
434 ( "sup" ^ 921 920 ) | |
435 ( "sqrt" calcFunc-sqrt -1 910 ) | |
436 ( "over" / 900 901 ) | |
437 ( "u|" calcFunc-abs -1 0 ) | |
438 ( "|" closing 0 -1 ) | |
439 ( "left floor" calcFunc-floor -1 0 ) | |
440 ( "right floor" closing 0 -1 ) | |
441 ( "left ceil" calcFunc-ceil -1 0 ) | |
442 ( "right ceil" closing 0 -1 ) | |
443 ( "+-" sdev 300 300 ) | |
444 ( "!" calcFunc-fact 210 -1 ) | |
445 ( "times" * 191 190 ) | |
446 ( "*" * 191 190 ) | |
447 ( "2x" * 191 190 ) | |
448 ( "/" / 180 181 ) | |
449 ( "%" % 180 181 ) | |
450 ( "+" + 170 171 ) | |
451 ( "-" - 170 171 ) | |
452 ( "<" calcFunc-lt 160 161 ) | |
453 ( ">" calcFunc-gt 160 161 ) | |
454 ( "<=" calcFunc-leq 160 161 ) | |
455 ( ">=" calcFunc-geq 160 161 ) | |
456 ( "=" calcFunc-eq 160 161 ) | |
457 ( "==" calcFunc-eq 160 161 ) | |
458 ( "!=" calcFunc-neq 160 161 ) | |
459 ( "u!" calcFunc-lnot -1 121 ) | |
460 ( "&&" calcFunc-land 110 111 ) | |
461 ( "||" calcFunc-lor 100 101 ) | |
462 ( "?" (math-read-if) 91 90 ) | |
463 ( "!!!" calcFunc-pnot -1 85 ) | |
464 ( "&&&" calcFunc-pand 80 81 ) | |
465 ( "|||" calcFunc-por 75 76 ) | |
466 ( "<-" calcFunc-assign 51 50 ) | |
467 ( ":=" calcFunc-assign 51 50 ) | |
468 ( "::" calcFunc-condition 45 46 ) | |
469 ( "->" calcFunc-evalto 40 41 ) | |
470 ( "->" calcFunc-evalto 40 -1 ) | |
471 ( "=>" calcFunc-evalto 40 41 ) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
472 ( "=>" calcFunc-evalto 40 -1 ))) |
40785 | 473 |
474 (put 'eqn 'math-function-table | |
475 '( ( arc\ cos . calcFunc-arccos ) | |
476 ( arc\ cosh . calcFunc-arccosh ) | |
477 ( arc\ sin . calcFunc-arcsin ) | |
478 ( arc\ sinh . calcFunc-arcsinh ) | |
479 ( arc\ tan . calcFunc-arctan ) | |
480 ( arc\ tanh . calcFunc-arctanh ) | |
481 ( GAMMA . calcFunc-gamma ) | |
482 ( phi . calcFunc-totient ) | |
483 ( mu . calcFunc-moebius ) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
484 ( matrix . (math-parse-eqn-matrix) ))) |
40785 | 485 |
486 (put 'eqn 'math-variable-table | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
487 '( ( inf . var-uinf ))) |
40785 | 488 |
489 (put 'eqn 'math-complex-format 'i) | |
490 | |
491 (defun math-parse-eqn-matrix (f sym) | |
492 (let ((vec nil)) | |
58107
cfad3432f125
(math-parse-fortran-vector, math-parse-fortran-vector-end,
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
493 (while (assoc math-expr-data '(("ccol") ("lcol") ("rcol"))) |
40785 | 494 (math-read-token) |
58107
cfad3432f125
(math-parse-fortran-vector, math-parse-fortran-vector-end,
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
495 (or (equal math-expr-data calc-function-open) |
40785 | 496 (throw 'syntax "Expected `{'")) |
497 (math-read-token) | |
498 (setq vec (cons (cons 'vec (math-read-expr-list)) vec)) | |
58107
cfad3432f125
(math-parse-fortran-vector, math-parse-fortran-vector-end,
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
499 (or (equal math-expr-data calc-function-close) |
40785 | 500 (throw 'syntax "Expected `}'")) |
501 (math-read-token)) | |
58107
cfad3432f125
(math-parse-fortran-vector, math-parse-fortran-vector-end,
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
502 (or (equal math-expr-data calc-function-close) |
40785 | 503 (throw 'syntax "Expected `}'")) |
504 (math-read-token) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
505 (math-transpose (cons 'vec (nreverse vec))))) |
40785 | 506 |
507 (defun math-parse-eqn-prime (x sym) | |
508 (if (eq (car-safe x) 'var) | |
58107
cfad3432f125
(math-parse-fortran-vector, math-parse-fortran-vector-end,
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
509 (if (equal math-expr-data calc-function-open) |
40785 | 510 (progn |
511 (math-read-token) | |
58107
cfad3432f125
(math-parse-fortran-vector, math-parse-fortran-vector-end,
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
512 (let ((args (if (or (equal math-expr-data calc-function-close) |
58134
3089957051ea
(math-parse-tex-sum): Use declared variable math-exp-old-pos.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58107
diff
changeset
|
513 (eq math-exp-token 'end)) |
40785 | 514 nil |
515 (math-read-expr-list)))) | |
58107
cfad3432f125
(math-parse-fortran-vector, math-parse-fortran-vector-end,
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
516 (if (not (or (equal math-expr-data calc-function-close) |
58134
3089957051ea
(math-parse-tex-sum): Use declared variable math-exp-old-pos.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58107
diff
changeset
|
517 (eq math-exp-token 'end))) |
40785 | 518 (throw 'syntax "Expected `)'")) |
519 (math-read-token) | |
520 (cons (intern (format "calcFunc-%s'" (nth 1 x))) args))) | |
521 (list 'var | |
522 (intern (concat (symbol-name (nth 1 x)) "'")) | |
523 (intern (concat (symbol-name (nth 2 x)) "'")))) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
524 (list 'calcFunc-Prime x))) |
40785 | 525 |
526 | |
527 (defun calc-mathematica-language () | |
528 (interactive) | |
529 (calc-wrapper | |
530 (calc-set-language 'math) | |
41271
fcd507927105
Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
531 (message "Mathematica language mode"))) |
40785 | 532 |
533 (put 'math 'math-oper-table | |
534 '( ( "[[" (math-read-math-subscr) 250 -1 ) | |
535 ( "!" calcFunc-fact 210 -1 ) | |
536 ( "!!" calcFunc-dfact 210 -1 ) | |
537 ( "^" ^ 201 200 ) | |
538 ( "u+" ident -1 197 ) | |
539 ( "u-" neg -1 197 ) | |
540 ( "/" / 195 196 ) | |
541 ( "*" * 190 191 ) | |
542 ( "2x" * 190 191 ) | |
543 ( "+" + 180 181 ) | |
544 ( "-" - 180 181 ) | |
545 ( "<" calcFunc-lt 160 161 ) | |
546 ( ">" calcFunc-gt 160 161 ) | |
547 ( "<=" calcFunc-leq 160 161 ) | |
548 ( ">=" calcFunc-geq 160 161 ) | |
549 ( "==" calcFunc-eq 150 151 ) | |
550 ( "!=" calcFunc-neq 150 151 ) | |
551 ( "u!" calcFunc-lnot -1 121 ) | |
552 ( "&&" calcFunc-land 110 111 ) | |
553 ( "||" calcFunc-lor 100 101 ) | |
554 ( "!!!" calcFunc-pnot -1 85 ) | |
555 ( "&&&" calcFunc-pand 80 81 ) | |
556 ( "|||" calcFunc-por 75 76 ) | |
557 ( ":=" calcFunc-assign 51 50 ) | |
558 ( "=" calcFunc-assign 51 50 ) | |
559 ( "->" calcFunc-assign 51 50 ) | |
560 ( ":>" calcFunc-assign 51 50 ) | |
561 ( "::" calcFunc-condition 45 46 ) | |
562 )) | |
563 | |
564 (put 'math 'math-function-table | |
565 '( ( Abs . calcFunc-abs ) | |
566 ( ArcCos . calcFunc-arccos ) | |
567 ( ArcCosh . calcFunc-arccosh ) | |
568 ( ArcSin . calcFunc-arcsin ) | |
569 ( ArcSinh . calcFunc-arcsinh ) | |
570 ( ArcTan . calcFunc-arctan ) | |
571 ( ArcTanh . calcFunc-arctanh ) | |
572 ( Arg . calcFunc-arg ) | |
573 ( Binomial . calcFunc-choose ) | |
574 ( Ceiling . calcFunc-ceil ) | |
575 ( Conjugate . calcFunc-conj ) | |
576 ( Cos . calcFunc-cos ) | |
577 ( Cosh . calcFunc-cosh ) | |
578 ( D . calcFunc-deriv ) | |
579 ( Dt . calcFunc-tderiv ) | |
580 ( Det . calcFunc-det ) | |
581 ( Exp . calcFunc-exp ) | |
582 ( EulerPhi . calcFunc-totient ) | |
583 ( Floor . calcFunc-floor ) | |
584 ( Gamma . calcFunc-gamma ) | |
585 ( GCD . calcFunc-gcd ) | |
586 ( If . calcFunc-if ) | |
587 ( Im . calcFunc-im ) | |
588 ( Inverse . calcFunc-inv ) | |
589 ( Integrate . calcFunc-integ ) | |
590 ( Join . calcFunc-vconcat ) | |
591 ( LCM . calcFunc-lcm ) | |
592 ( Log . calcFunc-ln ) | |
593 ( Max . calcFunc-max ) | |
594 ( Min . calcFunc-min ) | |
595 ( Mod . calcFunc-mod ) | |
596 ( MoebiusMu . calcFunc-moebius ) | |
597 ( Random . calcFunc-random ) | |
598 ( Round . calcFunc-round ) | |
599 ( Re . calcFunc-re ) | |
600 ( Sign . calcFunc-sign ) | |
601 ( Sin . calcFunc-sin ) | |
602 ( Sinh . calcFunc-sinh ) | |
603 ( Sqrt . calcFunc-sqrt ) | |
604 ( Tan . calcFunc-tan ) | |
605 ( Tanh . calcFunc-tanh ) | |
606 ( Transpose . calcFunc-trn ) | |
607 ( Length . calcFunc-vlen ) | |
608 )) | |
609 | |
610 (put 'math 'math-variable-table | |
611 '( ( I . var-i ) | |
612 ( Pi . var-pi ) | |
613 ( E . var-e ) | |
614 ( GoldenRatio . var-phi ) | |
615 ( EulerGamma . var-gamma ) | |
616 ( Infinity . var-inf ) | |
617 ( ComplexInfinity . var-uinf ) | |
618 ( Indeterminate . var-nan ) | |
619 )) | |
620 | |
621 (put 'math 'math-vector-brackets "{}") | |
622 (put 'math 'math-complex-format 'I) | |
623 (put 'math 'math-function-open "[") | |
624 (put 'math 'math-function-close "]") | |
625 | |
626 (put 'math 'math-radix-formatter | |
627 (function (lambda (r s) (format "%d^^%s" r s)))) | |
628 | |
629 (defun math-read-math-subscr (x op) | |
630 (let ((idx (math-read-expr-level 0))) | |
58107
cfad3432f125
(math-parse-fortran-vector, math-parse-fortran-vector-end,
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
631 (or (and (equal math-expr-data "]") |
40785 | 632 (progn |
633 (math-read-token) | |
58107
cfad3432f125
(math-parse-fortran-vector, math-parse-fortran-vector-end,
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
634 (equal math-expr-data "]"))) |
40785 | 635 (throw 'syntax "Expected ']]'")) |
636 (math-read-token) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
637 (list 'calcFunc-subscr x idx))) |
40785 | 638 |
639 | |
640 (defun calc-maple-language () | |
641 (interactive) | |
642 (calc-wrapper | |
643 (calc-set-language 'maple) | |
41271
fcd507927105
Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
644 (message "Maple language mode"))) |
40785 | 645 |
646 (put 'maple 'math-oper-table | |
647 '( ( "matrix" ident -1 300 ) | |
648 ( "MATRIX" ident -1 300 ) | |
649 ( "!" calcFunc-fact 210 -1 ) | |
650 ( "^" ^ 201 200 ) | |
651 ( "**" ^ 201 200 ) | |
652 ( "u+" ident -1 197 ) | |
653 ( "u-" neg -1 197 ) | |
654 ( "/" / 191 192 ) | |
655 ( "*" * 191 192 ) | |
656 ( "intersect" calcFunc-vint 191 192 ) | |
657 ( "+" + 180 181 ) | |
658 ( "-" - 180 181 ) | |
659 ( "union" calcFunc-vunion 180 181 ) | |
660 ( "minus" calcFunc-vdiff 180 181 ) | |
661 ( "mod" % 170 170 ) | |
662 ( ".." (math-read-maple-dots) 165 165 ) | |
663 ( "\\dots" (math-read-maple-dots) 165 165 ) | |
664 ( "<" calcFunc-lt 160 160 ) | |
665 ( ">" calcFunc-gt 160 160 ) | |
666 ( "<=" calcFunc-leq 160 160 ) | |
667 ( ">=" calcFunc-geq 160 160 ) | |
668 ( "=" calcFunc-eq 160 160 ) | |
669 ( "<>" calcFunc-neq 160 160 ) | |
670 ( "not" calcFunc-lnot -1 121 ) | |
671 ( "and" calcFunc-land 110 111 ) | |
672 ( "or" calcFunc-lor 100 101 ) | |
673 ( "!!!" calcFunc-pnot -1 85 ) | |
674 ( "&&&" calcFunc-pand 80 81 ) | |
675 ( "|||" calcFunc-por 75 76 ) | |
676 ( ":=" calcFunc-assign 51 50 ) | |
677 ( "::" calcFunc-condition 45 46 ) | |
678 )) | |
679 | |
680 (put 'maple 'math-function-table | |
681 '( ( bernoulli . calcFunc-bern ) | |
682 ( binomial . calcFunc-choose ) | |
683 ( diff . calcFunc-deriv ) | |
684 ( GAMMA . calcFunc-gamma ) | |
685 ( ifactor . calcFunc-prfac ) | |
686 ( igcd . calcFunc-gcd ) | |
687 ( ilcm . calcFunc-lcm ) | |
688 ( int . calcFunc-integ ) | |
689 ( modp . % ) | |
690 ( irem . % ) | |
691 ( iquo . calcFunc-idiv ) | |
692 ( isprime . calcFunc-prime ) | |
693 ( length . calcFunc-vlen ) | |
694 ( member . calcFunc-in ) | |
695 ( crossprod . calcFunc-cross ) | |
696 ( inverse . calcFunc-inv ) | |
697 ( trace . calcFunc-tr ) | |
698 ( transpose . calcFunc-trn ) | |
699 ( vectdim . calcFunc-vlen ) | |
700 )) | |
701 | |
702 (put 'maple 'math-variable-table | |
703 '( ( I . var-i ) | |
704 ( Pi . var-pi ) | |
705 ( E . var-e ) | |
706 ( infinity . var-inf ) | |
707 ( infinity . var-uinf ) | |
708 ( infinity . var-nan ) | |
709 )) | |
710 | |
711 (put 'maple 'math-complex-format 'I) | |
712 | |
713 (defun math-read-maple-dots (x op) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
714 (list 'intv 3 x (math-read-expr-level (nth 3 op)))) |
40785 | 715 |
716 | |
58411
9ceda393e263
(math-read-big-lines): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58134
diff
changeset
|
717 ;; The variable math-read-big-lines is local to math-read-big-expr in |
9ceda393e263
(math-read-big-lines): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58134
diff
changeset
|
718 ;; calc-ext.el, but is used by math-read-big-rec, math-read-big-char, |
9ceda393e263
(math-read-big-lines): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58134
diff
changeset
|
719 ;; math-read-big-emptyp, math-read-big-error and math-read-big-balance, |
9ceda393e263
(math-read-big-lines): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58134
diff
changeset
|
720 ;; which are called (directly and indirectly) by math-read-big-expr. |
9ceda393e263
(math-read-big-lines): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58134
diff
changeset
|
721 ;; It is also local to math-read-big-bigp in calc-ext.el, which calls |
9ceda393e263
(math-read-big-lines): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58134
diff
changeset
|
722 ;; math-read-big-balance. |
9ceda393e263
(math-read-big-lines): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58134
diff
changeset
|
723 (defvar math-read-big-lines) |
40785 | 724 |
58411
9ceda393e263
(math-read-big-lines): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58134
diff
changeset
|
725 ;; The variables math-read-big-baseline and math-read-big-h2 are |
9ceda393e263
(math-read-big-lines): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58134
diff
changeset
|
726 ;; local to math-read-big-expr in calc-ext.el, but used by |
9ceda393e263
(math-read-big-lines): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58134
diff
changeset
|
727 ;; math-read-big-rec. |
9ceda393e263
(math-read-big-lines): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58134
diff
changeset
|
728 (defvar math-read-big-baseline) |
9ceda393e263
(math-read-big-lines): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58134
diff
changeset
|
729 (defvar math-read-big-h2) |
40785 | 730 |
58411
9ceda393e263
(math-read-big-lines): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58134
diff
changeset
|
731 ;; The variables math-rb-h1, math-rb-h2, math-rb-v1 and math-rb-v2 |
9ceda393e263
(math-read-big-lines): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58134
diff
changeset
|
732 ;; are local to math-read-big-rec, but are used by math-read-big-char, |
9ceda393e263
(math-read-big-lines): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58134
diff
changeset
|
733 ;; math-read-big-emptyp and math-read-big-balance which are called by |
9ceda393e263
(math-read-big-lines): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58134
diff
changeset
|
734 ;; math-read-big-rec. |
9ceda393e263
(math-read-big-lines): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58134
diff
changeset
|
735 ;; math-rb-h2 is also local to math-read-big-bigp in calc-ext.el, |
9ceda393e263
(math-read-big-lines): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58134
diff
changeset
|
736 ;; which calls math-read-big-balance. |
9ceda393e263
(math-read-big-lines): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58134
diff
changeset
|
737 (defvar math-rb-h1) |
9ceda393e263
(math-read-big-lines): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58134
diff
changeset
|
738 (defvar math-rb-h2) |
9ceda393e263
(math-read-big-lines): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58134
diff
changeset
|
739 (defvar math-rb-v1) |
9ceda393e263
(math-read-big-lines): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58134
diff
changeset
|
740 (defvar math-rb-v2) |
40785 | 741 |
58411
9ceda393e263
(math-read-big-lines): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58134
diff
changeset
|
742 (defun math-read-big-rec (math-rb-h1 math-rb-v1 math-rb-h2 math-rb-v2 |
9ceda393e263
(math-read-big-lines): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58134
diff
changeset
|
743 &optional baseline prec short) |
40785 | 744 (or prec (setq prec 0)) |
745 | |
746 ;; Clip whitespace above or below. | |
58411
9ceda393e263
(math-read-big-lines): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58134
diff
changeset
|
747 (while (and (< math-rb-v1 math-rb-v2) |
9ceda393e263
(math-read-big-lines): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58134
diff
changeset
|
748 (math-read-big-emptyp math-rb-h1 math-rb-v1 math-rb-h2 (1+ math-rb-v1))) |
9ceda393e263
(math-read-big-lines): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58134
diff
changeset
|
749 (setq math-rb-v1 (1+ math-rb-v1))) |
9ceda393e263
(math-read-big-lines): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58134
diff
changeset
|
750 (while (and (< math-rb-v1 math-rb-v2) |
9ceda393e263
(math-read-big-lines): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58134
diff
changeset
|
751 (math-read-big-emptyp math-rb-h1 (1- math-rb-v2) math-rb-h2 math-rb-v2)) |
9ceda393e263
(math-read-big-lines): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58134
diff
changeset
|
752 (setq math-rb-v2 (1- math-rb-v2))) |
40785 | 753 |
754 ;; If formula is a single line high, normal parser can handle it. | |
58411
9ceda393e263
(math-read-big-lines): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58134
diff
changeset
|
755 (if (<= math-rb-v2 (1+ math-rb-v1)) |
9ceda393e263
(math-read-big-lines): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58134
diff
changeset
|
756 (if (or (<= math-rb-v2 math-rb-v1) |
9ceda393e263
(math-read-big-lines): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58134
diff
changeset
|
757 (> math-rb-h1 (length (setq math-rb-v2 |
9ceda393e263
(math-read-big-lines): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58134
diff
changeset
|
758 (nth math-rb-v1 math-read-big-lines))))) |
9ceda393e263
(math-read-big-lines): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58134
diff
changeset
|
759 (math-read-big-error math-rb-h1 math-rb-v1) |
9ceda393e263
(math-read-big-lines): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58134
diff
changeset
|
760 (setq math-read-big-baseline math-rb-v1 |
9ceda393e263
(math-read-big-lines): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58134
diff
changeset
|
761 math-read-big-h2 math-rb-h2 |
9ceda393e263
(math-read-big-lines): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58134
diff
changeset
|
762 math-rb-v2 (nth math-rb-v1 math-read-big-lines) |
9ceda393e263
(math-read-big-lines): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58134
diff
changeset
|
763 math-rb-h2 (math-read-expr |
9ceda393e263
(math-read-big-lines): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58134
diff
changeset
|
764 (substring math-rb-v2 math-rb-h1 |
9ceda393e263
(math-read-big-lines): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58134
diff
changeset
|
765 (min math-rb-h2 (length math-rb-v2))))) |
9ceda393e263
(math-read-big-lines): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58134
diff
changeset
|
766 (if (eq (car-safe math-rb-h2) 'error) |
9ceda393e263
(math-read-big-lines): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58134
diff
changeset
|
767 (math-read-big-error (+ math-rb-h1 (nth 1 math-rb-h2)) |
9ceda393e263
(math-read-big-lines): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58134
diff
changeset
|
768 math-rb-v1 (nth 2 math-rb-h2)) |
9ceda393e263
(math-read-big-lines): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58134
diff
changeset
|
769 math-rb-h2)) |
40785 | 770 |
771 ;; Clip whitespace at left or right. | |
58411
9ceda393e263
(math-read-big-lines): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58134
diff
changeset
|
772 (while (and (< math-rb-h1 math-rb-h2) |
9ceda393e263
(math-read-big-lines): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58134
diff
changeset
|
773 (math-read-big-emptyp math-rb-h1 math-rb-v1 (1+ math-rb-h1) math-rb-v2)) |
9ceda393e263
(math-read-big-lines): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58134
diff
changeset
|
774 (setq math-rb-h1 (1+ math-rb-h1))) |
9ceda393e263
(math-read-big-lines): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58134
diff
changeset
|
775 (while (and (< math-rb-h1 math-rb-h2) |
9ceda393e263
(math-read-big-lines): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58134
diff
changeset
|
776 (math-read-big-emptyp (1- math-rb-h2) math-rb-v1 math-rb-h2 math-rb-v2)) |
9ceda393e263
(math-read-big-lines): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58134
diff
changeset
|
777 (setq math-rb-h2 (1- math-rb-h2))) |
40785 | 778 |
779 ;; Scan to find widest left-justified "----" in the region. | |
780 (let* ((widest nil) | |
781 (widest-h2 0) | |
58411
9ceda393e263
(math-read-big-lines): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58134
diff
changeset
|
782 (lines-v1 (nthcdr math-rb-v1 math-read-big-lines)) |
40785 | 783 (p lines-v1) |
58411
9ceda393e263
(math-read-big-lines): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58134
diff
changeset
|
784 (v math-rb-v1) |
40785 | 785 (other-v nil) |
786 other-char line len h) | |
58411
9ceda393e263
(math-read-big-lines): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58134
diff
changeset
|
787 (while (< v math-rb-v2) |
40785 | 788 (setq line (car p) |
58411
9ceda393e263
(math-read-big-lines): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58134
diff
changeset
|
789 len (min math-rb-h2 (length line))) |
9ceda393e263
(math-read-big-lines): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58134
diff
changeset
|
790 (and (< math-rb-h1 len) |
9ceda393e263
(math-read-big-lines): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58134
diff
changeset
|
791 (/= (aref line math-rb-h1) ?\ ) |
9ceda393e263
(math-read-big-lines): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58134
diff
changeset
|
792 (if (and (= (aref line math-rb-h1) ?\-) |
40785 | 793 ;; Make sure it's not a minus sign. |
58411
9ceda393e263
(math-read-big-lines): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58134
diff
changeset
|
794 (or (and (< (1+ math-rb-h1) len) |
9ceda393e263
(math-read-big-lines): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58134
diff
changeset
|
795 (= (aref line (1+ math-rb-h1)) ?\-)) |
9ceda393e263
(math-read-big-lines): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58134
diff
changeset
|
796 (/= (math-read-big-char math-rb-h1 (1- v)) ?\ ) |
9ceda393e263
(math-read-big-lines): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58134
diff
changeset
|
797 (/= (math-read-big-char math-rb-h1 (1+ v)) ?\ ))) |
40785 | 798 (progn |
58411
9ceda393e263
(math-read-big-lines): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58134
diff
changeset
|
799 (setq h math-rb-h1) |
40785 | 800 (while (and (< (setq h (1+ h)) len) |
801 (= (aref line h) ?\-))) | |
802 (if (> h widest-h2) | |
803 (setq widest v | |
804 widest-h2 h))) | |
58411
9ceda393e263
(math-read-big-lines): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58134
diff
changeset
|
805 (or other-v (setq other-v v other-char (aref line math-rb-h1))))) |
40785 | 806 (setq v (1+ v) |
807 p (cdr p))) | |
808 | |
809 (cond ((not (setq v other-v)) | |
58411
9ceda393e263
(math-read-big-lines): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58134
diff
changeset
|
810 (math-read-big-error math-rb-h1 math-rb-v1)) ; Should never happen! |
40785 | 811 |
812 ;; Quotient. | |
813 (widest | |
814 (setq h widest-h2 | |
815 v widest) | |
58411
9ceda393e263
(math-read-big-lines): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58134
diff
changeset
|
816 (let ((num (math-read-big-rec math-rb-h1 math-rb-v1 h v)) |
9ceda393e263
(math-read-big-lines): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58134
diff
changeset
|
817 (den (math-read-big-rec math-rb-h1 (1+ v) h math-rb-v2))) |
40785 | 818 (setq p (if (and (math-integerp num) (math-integerp den)) |
819 (math-make-frac num den) | |
820 (list '/ num den))))) | |
821 | |
822 ;; Big radical sign. | |
823 ((= other-char ?\\) | |
58411
9ceda393e263
(math-read-big-lines): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58134
diff
changeset
|
824 (or (= (math-read-big-char (1+ math-rb-h1) v) ?\|) |
9ceda393e263
(math-read-big-lines): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58134
diff
changeset
|
825 (math-read-big-error (1+ math-rb-h1) v "Malformed root sign")) |
9ceda393e263
(math-read-big-lines): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58134
diff
changeset
|
826 (math-read-big-emptyp math-rb-h1 math-rb-v1 (1+ math-rb-h1) v nil t) |
9ceda393e263
(math-read-big-lines): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58134
diff
changeset
|
827 (while (= (math-read-big-char (1+ math-rb-h1) (setq v (1- v))) ?\|)) |
9ceda393e263
(math-read-big-lines): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58134
diff
changeset
|
828 (or (= (math-read-big-char (setq h (+ math-rb-h1 2)) v) ?\_) |
40785 | 829 (math-read-big-error h v "Malformed root sign")) |
830 (while (= (math-read-big-char (setq h (1+ h)) v) ?\_)) | |
58411
9ceda393e263
(math-read-big-lines): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58134
diff
changeset
|
831 (math-read-big-emptyp math-rb-h1 math-rb-v1 (1+ math-rb-h1) v nil t) |
9ceda393e263
(math-read-big-lines): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58134
diff
changeset
|
832 (math-read-big-emptyp math-rb-h1 (1+ other-v) h math-rb-v2 nil t) |
40785 | 833 (setq p (list 'calcFunc-sqrt (math-read-big-rec |
58411
9ceda393e263
(math-read-big-lines): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58134
diff
changeset
|
834 (+ math-rb-h1 2) (1+ v) |
40785 | 835 h (1+ other-v) baseline)) |
58411
9ceda393e263
(math-read-big-lines): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58134
diff
changeset
|
836 v math-read-big-baseline)) |
40785 | 837 |
838 ;; Small radical sign. | |
839 ((and (= other-char ?V) | |
58411
9ceda393e263
(math-read-big-lines): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58134
diff
changeset
|
840 (= (math-read-big-char (1+ math-rb-h1) (1- v)) ?\_)) |
9ceda393e263
(math-read-big-lines): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58134
diff
changeset
|
841 (setq h (1+ math-rb-h1)) |
9ceda393e263
(math-read-big-lines): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58134
diff
changeset
|
842 (math-read-big-emptyp math-rb-h1 math-rb-v1 h (1- v) nil t) |
9ceda393e263
(math-read-big-lines): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58134
diff
changeset
|
843 (math-read-big-emptyp math-rb-h1 (1+ v) h math-rb-v2 nil t) |
9ceda393e263
(math-read-big-lines): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58134
diff
changeset
|
844 (math-read-big-emptyp math-rb-h1 math-rb-v1 (1+ math-rb-h1) v nil t) |
40785 | 845 (while (= (math-read-big-char (setq h (1+ h)) (1- v)) ?\_)) |
846 (setq p (list 'calcFunc-sqrt (math-read-big-rec | |
58411
9ceda393e263
(math-read-big-lines): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58134
diff
changeset
|
847 (1+ math-rb-h1) v h (1+ v) t)) |
9ceda393e263
(math-read-big-lines): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58134
diff
changeset
|
848 v math-read-big-baseline)) |
40785 | 849 |
850 ;; Binomial coefficient. | |
851 ((and (= other-char ?\() | |
58411
9ceda393e263
(math-read-big-lines): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58134
diff
changeset
|
852 (= (math-read-big-char (1+ math-rb-h1) v) ?\ ) |
9ceda393e263
(math-read-big-lines): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58134
diff
changeset
|
853 (= (string-match "( *)" (nth v math-read-big-lines) |
9ceda393e263
(math-read-big-lines): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58134
diff
changeset
|
854 math-rb-h1) math-rb-h1)) |
40785 | 855 (setq h (match-end 0)) |
58411
9ceda393e263
(math-read-big-lines): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58134
diff
changeset
|
856 (math-read-big-emptyp math-rb-h1 math-rb-v1 (1+ math-rb-h1) v nil t) |
9ceda393e263
(math-read-big-lines): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58134
diff
changeset
|
857 (math-read-big-emptyp math-rb-h1 (1+ v) (1+ math-rb-h1) math-rb-v2 nil t) |
9ceda393e263
(math-read-big-lines): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58134
diff
changeset
|
858 (math-read-big-emptyp (1- h) math-rb-v1 h v nil t) |
9ceda393e263
(math-read-big-lines): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58134
diff
changeset
|
859 (math-read-big-emptyp (1- h) (1+ v) h math-rb-v2 nil t) |
40785 | 860 (setq p (list 'calcFunc-choose |
58411
9ceda393e263
(math-read-big-lines): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58134
diff
changeset
|
861 (math-read-big-rec (1+ math-rb-h1) math-rb-v1 (1- h) v) |
9ceda393e263
(math-read-big-lines): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58134
diff
changeset
|
862 (math-read-big-rec (1+ math-rb-h1) (1+ v) |
9ceda393e263
(math-read-big-lines): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58134
diff
changeset
|
863 (1- h) math-rb-v2)))) |
40785 | 864 |
865 ;; Minus sign. | |
866 ((= other-char ?\-) | |
58411
9ceda393e263
(math-read-big-lines): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58134
diff
changeset
|
867 (setq p (list 'neg (math-read-big-rec (1+ math-rb-h1) math-rb-v1 |
9ceda393e263
(math-read-big-lines): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58134
diff
changeset
|
868 math-rb-h2 math-rb-v2 v 250 t)) |
9ceda393e263
(math-read-big-lines): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58134
diff
changeset
|
869 v math-read-big-baseline |
9ceda393e263
(math-read-big-lines): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58134
diff
changeset
|
870 h math-read-big-h2)) |
40785 | 871 |
872 ;; Parentheses. | |
873 ((= other-char ?\() | |
58411
9ceda393e263
(math-read-big-lines): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58134
diff
changeset
|
874 (math-read-big-emptyp math-rb-h1 math-rb-v1 (1+ math-rb-h1) v nil t) |
9ceda393e263
(math-read-big-lines): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58134
diff
changeset
|
875 (math-read-big-emptyp math-rb-h1 (1+ v) (1+ math-rb-h1) math-rb-v2 nil t) |
9ceda393e263
(math-read-big-lines): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58134
diff
changeset
|
876 (setq h (math-read-big-balance (1+ math-rb-h1) v "(" t)) |
9ceda393e263
(math-read-big-lines): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58134
diff
changeset
|
877 (math-read-big-emptyp (1- h) math-rb-v1 h v nil t) |
9ceda393e263
(math-read-big-lines): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58134
diff
changeset
|
878 (math-read-big-emptyp (1- h) (1+ v) h math-rb-v2 nil t) |
40785 | 879 (let ((sep (math-read-big-char (1- h) v)) |
880 hmid) | |
881 (if (= sep ?\.) | |
882 (setq h (1+ h))) | |
883 (if (= sep ?\]) | |
884 (math-read-big-error (1- h) v "Expected `)'")) | |
885 (if (= sep ?\)) | |
58411
9ceda393e263
(math-read-big-lines): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58134
diff
changeset
|
886 (setq p (math-read-big-rec |
9ceda393e263
(math-read-big-lines): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58134
diff
changeset
|
887 (1+ math-rb-h1) math-rb-v1 (1- h) math-rb-v2 v)) |
40785 | 888 (setq hmid (math-read-big-balance h v "(") |
58411
9ceda393e263
(math-read-big-lines): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58134
diff
changeset
|
889 p (list p |
9ceda393e263
(math-read-big-lines): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58134
diff
changeset
|
890 (math-read-big-rec h math-rb-v1 (1- hmid) math-rb-v2 v)) |
40785 | 891 h hmid) |
892 (cond ((= sep ?\.) | |
893 (setq p (cons 'intv (cons (if (= (math-read-big-char | |
894 (1- h) v) | |
895 ?\)) | |
896 0 1) | |
897 p)))) | |
898 ((= (math-read-big-char (1- h) v) ?\]) | |
899 (math-read-big-error (1- h) v "Expected `)'")) | |
900 ((= sep ?\,) | |
901 (or (and (math-realp (car p)) (math-realp (nth 1 p))) | |
902 (math-read-big-error | |
58411
9ceda393e263
(math-read-big-lines): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58134
diff
changeset
|
903 math-rb-h1 v "Complex components must be real")) |
40785 | 904 (setq p (cons 'cplx p))) |
905 ((= sep ?\;) | |
906 (or (and (math-realp (car p)) (math-anglep (nth 1 p))) | |
907 (math-read-big-error | |
58411
9ceda393e263
(math-read-big-lines): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58134
diff
changeset
|
908 math-rb-h1 v "Complex components must be real")) |
40785 | 909 (setq p (cons 'polar p))))))) |
910 | |
911 ;; Matrix. | |
912 ((and (= other-char ?\[) | |
58411
9ceda393e263
(math-read-big-lines): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58134
diff
changeset
|
913 (or (= (math-read-big-char (setq h math-rb-h1) (1+ v)) ?\[) |
40785 | 914 (= (math-read-big-char (setq h (1+ h)) v) ?\[) |
915 (and (= (math-read-big-char h v) ?\ ) | |
916 (= (math-read-big-char (setq h (1+ h)) v) ?\[))) | |
917 (= (math-read-big-char h (1+ v)) ?\[)) | |
58411
9ceda393e263
(math-read-big-lines): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58134
diff
changeset
|
918 (math-read-big-emptyp math-rb-h1 math-rb-v1 h v nil t) |
40785 | 919 (let ((vtop v) |
920 (hleft h) | |
921 (hright nil)) | |
922 (setq p nil) | |
923 (while (progn | |
924 (setq h (math-read-big-balance (1+ hleft) v "[")) | |
925 (if hright | |
926 (or (= h hright) | |
927 (math-read-big-error hright v "Expected `]'")) | |
928 (setq hright h)) | |
929 (setq p (cons (math-read-big-rec | |
930 hleft v h (1+ v)) p)) | |
931 (and (memq (math-read-big-char h v) '(?\ ?\,)) | |
932 (= (math-read-big-char hleft (1+ v)) ?\[))) | |
933 (setq v (1+ v))) | |
58411
9ceda393e263
(math-read-big-lines): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58134
diff
changeset
|
934 (or (= hleft math-rb-h1) |
40785 | 935 (progn |
936 (if (= (math-read-big-char h v) ?\ ) | |
937 (setq h (1+ h))) | |
938 (and (= (math-read-big-char h v) ?\]) | |
939 (setq h (1+ h)))) | |
940 (math-read-big-error (1- h) v "Expected `]'")) | |
941 (if (= (math-read-big-char h vtop) ?\,) | |
942 (setq h (1+ h))) | |
58411
9ceda393e263
(math-read-big-lines): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58134
diff
changeset
|
943 (math-read-big-emptyp math-rb-h1 (1+ v) (1- h) math-rb-v2 nil t) |
40785 | 944 (setq v (+ vtop (/ (- v vtop) 2)) |
945 p (cons 'vec (nreverse p))))) | |
946 | |
947 ;; Square brackets. | |
948 ((= other-char ?\[) | |
58411
9ceda393e263
(math-read-big-lines): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58134
diff
changeset
|
949 (math-read-big-emptyp math-rb-h1 math-rb-v1 (1+ math-rb-h1) v nil t) |
9ceda393e263
(math-read-big-lines): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58134
diff
changeset
|
950 (math-read-big-emptyp math-rb-h1 (1+ v) (1+ math-rb-h1) math-rb-v2 nil t) |
40785 | 951 (setq p nil |
58411
9ceda393e263
(math-read-big-lines): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58134
diff
changeset
|
952 h (1+ math-rb-h1)) |
40785 | 953 (while (progn |
954 (setq widest (math-read-big-balance h v "[" t)) | |
58411
9ceda393e263
(math-read-big-lines): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58134
diff
changeset
|
955 (math-read-big-emptyp (1- h) math-rb-v1 h v nil t) |
9ceda393e263
(math-read-big-lines): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58134
diff
changeset
|
956 (math-read-big-emptyp (1- h) (1+ v) h math-rb-v2 nil t) |
40785 | 957 (setq p (cons (math-read-big-rec |
58411
9ceda393e263
(math-read-big-lines): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58134
diff
changeset
|
958 h math-rb-v1 (1- widest) math-rb-v2 v) p) |
40785 | 959 h widest) |
960 (= (math-read-big-char (1- h) v) ?\,))) | |
961 (setq widest (math-read-big-char (1- h) v)) | |
962 (if (or (memq widest '(?\; ?\))) | |
963 (and (eq widest ?\.) (cdr p))) | |
964 (math-read-big-error (1- h) v "Expected `]'")) | |
965 (if (= widest ?\.) | |
966 (setq h (1+ h) | |
967 widest (math-read-big-balance h v "[") | |
58411
9ceda393e263
(math-read-big-lines): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58134
diff
changeset
|
968 p (nconc p (list (math-read-big-rec |
9ceda393e263
(math-read-big-lines): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58134
diff
changeset
|
969 h math-rb-v1 (1- widest) math-rb-v2 v))) |
40785 | 970 h widest |
971 p (cons 'intv (cons (if (= (math-read-big-char (1- h) v) | |
972 ?\]) | |
973 3 2) | |
974 p))) | |
975 (setq p (cons 'vec (nreverse p))))) | |
976 | |
977 ;; Date form. | |
978 ((= other-char ?\<) | |
58411
9ceda393e263
(math-read-big-lines): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58134
diff
changeset
|
979 (setq line (nth v math-read-big-lines)) |
9ceda393e263
(math-read-big-lines): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58134
diff
changeset
|
980 (string-match ">" line math-rb-h1) |
40785 | 981 (setq h (match-end 0)) |
58411
9ceda393e263
(math-read-big-lines): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58134
diff
changeset
|
982 (math-read-big-emptyp math-rb-h1 math-rb-v1 h v nil t) |
9ceda393e263
(math-read-big-lines): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58134
diff
changeset
|
983 (math-read-big-emptyp math-rb-h1 (1+ v) h math-rb-v2 nil t) |
9ceda393e263
(math-read-big-lines): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58134
diff
changeset
|
984 (setq p (math-read-big-rec math-rb-h1 v h (1+ v) v))) |
40785 | 985 |
986 ;; Variable name or function call. | |
987 ((or (and (>= other-char ?a) (<= other-char ?z)) | |
988 (and (>= other-char ?A) (<= other-char ?Z))) | |
58411
9ceda393e263
(math-read-big-lines): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58134
diff
changeset
|
989 (setq line (nth v math-read-big-lines)) |
9ceda393e263
(math-read-big-lines): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58134
diff
changeset
|
990 (string-match "\\([a-zA-Z'_]+\\) *" line math-rb-h1) |
40785 | 991 (setq h (match-end 1) |
992 widest (match-end 0) | |
993 p (math-match-substring line 1)) | |
58411
9ceda393e263
(math-read-big-lines): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58134
diff
changeset
|
994 (math-read-big-emptyp math-rb-h1 math-rb-v1 h v nil t) |
9ceda393e263
(math-read-big-lines): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58134
diff
changeset
|
995 (math-read-big-emptyp math-rb-h1 (1+ v) h math-rb-v2 nil t) |
40785 | 996 (if (= (math-read-big-char widest v) ?\() |
997 (progn | |
998 (setq line (if (string-match "-" p) | |
999 (intern p) | |
1000 (intern (concat "calcFunc-" p))) | |
1001 h (1+ widest) | |
1002 p nil) | |
58411
9ceda393e263
(math-read-big-lines): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58134
diff
changeset
|
1003 (math-read-big-emptyp widest math-rb-v1 h v nil t) |
9ceda393e263
(math-read-big-lines): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58134
diff
changeset
|
1004 (math-read-big-emptyp widest (1+ v) h math-rb-v2 nil t) |
40785 | 1005 (while (progn |
1006 (setq widest (math-read-big-balance h v "(" t)) | |
58411
9ceda393e263
(math-read-big-lines): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58134
diff
changeset
|
1007 (math-read-big-emptyp (1- h) math-rb-v1 h v nil t) |
9ceda393e263
(math-read-big-lines): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58134
diff
changeset
|
1008 (math-read-big-emptyp (1- h) (1+ v) h math-rb-v2 nil t) |
40785 | 1009 (setq p (cons (math-read-big-rec |
58411
9ceda393e263
(math-read-big-lines): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58134
diff
changeset
|
1010 h math-rb-v1 (1- widest) math-rb-v2 v) p) |
40785 | 1011 h widest) |
1012 (= (math-read-big-char (1- h) v) ?\,))) | |
1013 (or (= (math-read-big-char (1- h) v) ?\)) | |
1014 (math-read-big-error (1- h) v "Expected `)'")) | |
1015 (setq p (cons line (nreverse p)))) | |
1016 (setq p (list 'var | |
1017 (intern (math-remove-dashes p)) | |
1018 (if (string-match "-" p) | |
1019 (intern p) | |
1020 (intern (concat "var-" p))))))) | |
1021 | |
1022 ;; Number. | |
1023 (t | |
58411
9ceda393e263
(math-read-big-lines): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58134
diff
changeset
|
1024 (setq line (nth v math-read-big-lines)) |
9ceda393e263
(math-read-big-lines): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58134
diff
changeset
|
1025 (or (= (string-match "_?\\([0-9]+.?0*@ *\\)?\\([0-9]+.?0*' *\\)?\\([0-9]+\\(#\\|\\^\\^\\)[0-9a-zA-Z:]+\\|[0-9]+:[0-9:]+\\|[0-9.]+\\([eE][-+_]?[0-9]+\\)?\"?\\)?" line math-rb-h1) math-rb-h1) |
40785 | 1026 (math-read-big-error h v "Expected a number")) |
1027 (setq h (match-end 0) | |
1028 p (math-read-number (math-match-substring line 0))) | |
58411
9ceda393e263
(math-read-big-lines): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58134
diff
changeset
|
1029 (math-read-big-emptyp math-rb-h1 math-rb-v1 h v nil t) |
9ceda393e263
(math-read-big-lines): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58134
diff
changeset
|
1030 (math-read-big-emptyp math-rb-h1 (1+ v) h math-rb-v2 nil t))) |
40785 | 1031 |
58411
9ceda393e263
(math-read-big-lines): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58134
diff
changeset
|
1032 ;; Now left term is bounded by math-rb-h1, math-rb-v1, h, math-rb-v2; |
9ceda393e263
(math-read-big-lines): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58134
diff
changeset
|
1033 ;; baseline = v. |
40785 | 1034 (if baseline |
1035 (or (= v baseline) | |
58411
9ceda393e263
(math-read-big-lines): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58134
diff
changeset
|
1036 (math-read-big-error math-rb-h1 v "Inconsistent baseline in formula")) |
40785 | 1037 (setq baseline v)) |
1038 | |
1039 ;; Look for superscripts or subscripts. | |
58411
9ceda393e263
(math-read-big-lines): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58134
diff
changeset
|
1040 (setq line (nth baseline math-read-big-lines) |
9ceda393e263
(math-read-big-lines): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58134
diff
changeset
|
1041 len (min math-rb-h2 (length line)) |
40785 | 1042 widest h) |
1043 (while (and (< widest len) | |
1044 (= (aref line widest) ?\ )) | |
1045 (setq widest (1+ widest))) | |
58411
9ceda393e263
(math-read-big-lines): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58134
diff
changeset
|
1046 (and (>= widest len) (setq widest math-rb-h2)) |
9ceda393e263
(math-read-big-lines): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58134
diff
changeset
|
1047 (if (math-read-big-emptyp h v widest math-rb-v2) |
9ceda393e263
(math-read-big-lines): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58134
diff
changeset
|
1048 (if (math-read-big-emptyp h math-rb-v1 widest v) |
40785 | 1049 (setq h widest) |
58411
9ceda393e263
(math-read-big-lines): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58134
diff
changeset
|
1050 (setq p (list '^ p (math-read-big-rec h math-rb-v1 widest v)) |
40785 | 1051 h widest)) |
58411
9ceda393e263
(math-read-big-lines): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58134
diff
changeset
|
1052 (if (math-read-big-emptyp h math-rb-v1 widest v) |
40785 | 1053 (setq p (list 'calcFunc-subscr p |
58411
9ceda393e263
(math-read-big-lines): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58134
diff
changeset
|
1054 (math-read-big-rec h v widest math-rb-v2)) |
40785 | 1055 h widest))) |
1056 | |
1057 ;; Look for an operator name and grab additional terms. | |
1058 (while (and (< h len) | |
1059 (if (setq widest (and (math-read-big-emptyp | |
58411
9ceda393e263
(math-read-big-lines): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58134
diff
changeset
|
1060 h math-rb-v1 (1+ h) v) |
40785 | 1061 (math-read-big-emptyp |
58411
9ceda393e263
(math-read-big-lines): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58134
diff
changeset
|
1062 h (1+ v) (1+ h) math-rb-v2) |
40785 | 1063 (string-match "<=\\|>=\\|\\+/-\\|!=\\|&&\\|||\\|:=\\|=>\\|." line h) |
1064 (assoc (math-match-substring line 0) | |
1065 math-standard-opers))) | |
1066 (and (>= (nth 2 widest) prec) | |
1067 (setq h (match-end 0))) | |
1068 (and (not (eq (string-match ",\\|;\\|\\.\\.\\|)\\|\\]\\|:" line h) | |
1069 h)) | |
1070 (setq widest '("2x" * 196 195))))) | |
1071 (cond ((eq (nth 3 widest) -1) | |
1072 (setq p (list (nth 1 widest) p))) | |
1073 ((equal (car widest) "?") | |
58411
9ceda393e263
(math-read-big-lines): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58134
diff
changeset
|
1074 (let ((y (math-read-big-rec h math-rb-v1 math-rb-h2 |
9ceda393e263
(math-read-big-lines): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58134
diff
changeset
|
1075 math-rb-v2 baseline nil t))) |
9ceda393e263
(math-read-big-lines): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58134
diff
changeset
|
1076 (or (= (math-read-big-char math-read-big-h2 baseline) ?\:) |
9ceda393e263
(math-read-big-lines): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58134
diff
changeset
|
1077 (math-read-big-error math-read-big-h2 baseline "Expected `:'")) |
40785 | 1078 (setq p (list (nth 1 widest) p y |
58411
9ceda393e263
(math-read-big-lines): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58134
diff
changeset
|
1079 (math-read-big-rec |
9ceda393e263
(math-read-big-lines): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58134
diff
changeset
|
1080 (1+ math-read-big-h2) math-rb-v1 math-rb-h2 math-rb-v2 |
9ceda393e263
(math-read-big-lines): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58134
diff
changeset
|
1081 baseline (nth 3 widest) t)) |
9ceda393e263
(math-read-big-lines): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58134
diff
changeset
|
1082 h math-read-big-h2))) |
40785 | 1083 (t |
1084 (setq p (list (nth 1 widest) p | |
58411
9ceda393e263
(math-read-big-lines): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58134
diff
changeset
|
1085 (math-read-big-rec h math-rb-v1 math-rb-h2 math-rb-v2 |
40785 | 1086 baseline (nth 3 widest) t)) |
58411
9ceda393e263
(math-read-big-lines): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58134
diff
changeset
|
1087 h math-read-big-h2)))) |
40785 | 1088 |
1089 ;; Return all relevant information to caller. | |
58411
9ceda393e263
(math-read-big-lines): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58134
diff
changeset
|
1090 (setq math-read-big-baseline baseline |
9ceda393e263
(math-read-big-lines): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58134
diff
changeset
|
1091 math-read-big-h2 h) |
9ceda393e263
(math-read-big-lines): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58134
diff
changeset
|
1092 (or short (= math-read-big-h2 math-rb-h2) |
40785 | 1093 (math-read-big-error h baseline)) |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
1094 p))) |
40785 | 1095 |
1096 (defun math-read-big-char (h v) | |
58411
9ceda393e263
(math-read-big-lines): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58134
diff
changeset
|
1097 (or (and (>= h math-rb-h1) |
9ceda393e263
(math-read-big-lines): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58134
diff
changeset
|
1098 (< h math-rb-h2) |
9ceda393e263
(math-read-big-lines): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58134
diff
changeset
|
1099 (>= v math-rb-v1) |
9ceda393e263
(math-read-big-lines): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58134
diff
changeset
|
1100 (< v math-rb-v2) |
9ceda393e263
(math-read-big-lines): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58134
diff
changeset
|
1101 (let ((line (nth v math-read-big-lines))) |
40785 | 1102 (and line |
1103 (< h (length line)) | |
1104 (aref line h)))) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
1105 ?\ )) |
40785 | 1106 |
1107 (defun math-read-big-emptyp (eh1 ev1 eh2 ev2 &optional what error) | |
58411
9ceda393e263
(math-read-big-lines): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58134
diff
changeset
|
1108 (and (< ev1 math-rb-v1) (setq ev1 math-rb-v1)) |
9ceda393e263
(math-read-big-lines): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58134
diff
changeset
|
1109 (and (< eh1 math-rb-h1) (setq eh1 math-rb-h1)) |
9ceda393e263
(math-read-big-lines): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58134
diff
changeset
|
1110 (and (> ev2 math-rb-v2) (setq ev2 math-rb-v2)) |
9ceda393e263
(math-read-big-lines): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58134
diff
changeset
|
1111 (and (> eh2 math-rb-h2) (setq eh2 math-rb-h2)) |
40785 | 1112 (or what (setq what ?\ )) |
58411
9ceda393e263
(math-read-big-lines): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58134
diff
changeset
|
1113 (let ((p (nthcdr ev1 math-read-big-lines)) |
40785 | 1114 h) |
1115 (while (and (< ev1 ev2) | |
1116 (progn | |
1117 (setq h (min eh2 (length (car p)))) | |
1118 (while (and (>= (setq h (1- h)) eh1) | |
1119 (= (aref (car p) h) what))) | |
1120 (and error (>= h eh1) | |
1121 (math-read-big-error h ev1 (if (stringp error) | |
1122 error | |
1123 "Whitespace expected"))) | |
1124 (< h eh1))) | |
1125 (setq ev1 (1+ ev1) | |
1126 p (cdr p))) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
1127 (>= ev1 ev2))) |
40785 | 1128 |
58411
9ceda393e263
(math-read-big-lines): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58134
diff
changeset
|
1129 ;; math-read-big-err-msg is local to math-read-big-expr in calc-ext.el, |
9ceda393e263
(math-read-big-lines): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58134
diff
changeset
|
1130 ;; but is used by math-read-big-error which is called (indirectly) by |
9ceda393e263
(math-read-big-lines): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58134
diff
changeset
|
1131 ;; math-read-big-expr. |
9ceda393e263
(math-read-big-lines): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58134
diff
changeset
|
1132 (defvar math-read-big-err-msg) |
9ceda393e263
(math-read-big-lines): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58134
diff
changeset
|
1133 |
40785 | 1134 (defun math-read-big-error (h v &optional msg) |
1135 (let ((pos 0) | |
58411
9ceda393e263
(math-read-big-lines): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58134
diff
changeset
|
1136 (p math-read-big-lines)) |
40785 | 1137 (while (> v 0) |
1138 (setq pos (+ pos 1 (length (car p))) | |
1139 p (cdr p) | |
1140 v (1- v))) | |
1141 (setq h (+ pos (min h (length (car p)))) | |
58411
9ceda393e263
(math-read-big-lines): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58134
diff
changeset
|
1142 math-read-big-err-msg (list 'error h (or msg "Syntax error"))) |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
1143 (throw 'syntax nil))) |
40785 | 1144 |
1145 (defun math-read-big-balance (h v what &optional commas) | |
58411
9ceda393e263
(math-read-big-lines): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58134
diff
changeset
|
1146 (let* ((line (nth v math-read-big-lines)) |
9ceda393e263
(math-read-big-lines): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58134
diff
changeset
|
1147 (len (min math-rb-h2 (length line))) |
40785 | 1148 (count 1)) |
1149 (while (> count 0) | |
1150 (if (>= h len) | |
1151 (if what | |
58411
9ceda393e263
(math-read-big-lines): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58134
diff
changeset
|
1152 (math-read-big-error nil v (format "Unmatched `%s'" what)) |
40785 | 1153 (setq count 0)) |
1154 (if (memq (aref line h) '(?\( ?\[)) | |
1155 (setq count (1+ count)) | |
1156 (if (if (and commas (= count 1)) | |
1157 (or (memq (aref line h) '(?\) ?\] ?\, ?\;)) | |
1158 (and (eq (aref line h) ?\.) | |
1159 (< (1+ h) len) | |
1160 (eq (aref line (1+ h)) ?\.))) | |
1161 (memq (aref line h) '(?\) ?\]))) | |
1162 (setq count (1- count)))) | |
1163 (setq h (1+ h)))) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
1164 h)) |
40785 | 1165 |
52401 | 1166 ;;; arch-tag: 483bfe15-f290-4fef-bb7d-ce65be687f2e |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
1167 ;;; calc-lang.el ends here |