annotate lisp/w3/dsssl.el @ 118:7d55a9ba150c r20-1b11

Import from CVS: tag r20-1b11
author cvs
date Mon, 13 Aug 2007 09:24:17 +0200
parents 0293115a14e9
children 34a5b81f86ba
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
14
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1 ;;; dsssl.el --- DSSSL parser
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
2 ;; Author: wmperry
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 14
diff changeset
3 ;; Created: 1997/01/10 00:13:05
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 14
diff changeset
4 ;; Version: 1.12
14
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
5 ;; Keywords:
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
6
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
7 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 14
diff changeset
8 ;;; Copyright (c) 1996, 1997 by William M. Perry (wmperry@cs.indiana.edu)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 14
diff changeset
9 ;;; Copyright (c) 1997 by Free Software Foundation, Inc.
14
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
10 ;;;
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
11 ;;; This file is part of GNU Emacs.
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
12 ;;;
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
13 ;;; GNU Emacs is free software; you can redistribute it and/or modify
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
14 ;;; it under the terms of the GNU General Public License as published by
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
15 ;;; the Free Software Foundation; either version 2, or (at your option)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
16 ;;; any later version.
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
17 ;;;
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
18 ;;; GNU Emacs is distributed in the hope that it will be useful,
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
19 ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
20 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
21 ;;; GNU General Public License for more details.
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
22 ;;;
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
23 ;;; You should have received a copy of the GNU General Public License
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
24 ;;; along with GNU Emacs; see the file COPYING. If not, write to the
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
25 ;;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
26 ;;; Boston, MA 02111-1307, USA.
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
27 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
28
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
29 (require 'cl)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
30
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
31 (if (not (fboundp 'cl-copy-hashtable))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
32 (defun cl-copy-hashtable (h)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
33 (let ((new (make-hash-table)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
34 (cl-maphash (function (lambda (k v) (cl-puthash k v new))) h)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
35 new)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
36
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
37 ;; We need to have this up at the top to avoid compilation warnings in
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
38 ;; 'make' in dsssl-eval. Call me anal.
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
39 (defstruct flow-object
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
40 (name 'unknown :read-only t) ; Name of this flow object
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
41 (properties nil)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
42 (children nil)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
43 (parent nil)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
44 )
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
45
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
46 (defconst dsssl-builtin-functions
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
47 '(not boolean\? case equal\? null\? list\? list length append
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
48 reverse list-tail list-ref member symbol\? keyword\? quantity\?
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
49 number\? real\? integer\? = < > <= >= + * - / max min abs quotient
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
50 modulo remainder floor ceiling truncate round number->string
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
51 string->number char\? char=\? char-property string\? string
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
52 string-length string-ref string=\? substring string-append
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
53 procedure\? apply external-procedure make time time->string quote
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
54 char-downcase indentity error let)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
55 "A list of all the builtin DSSSL functions that we support.")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
56
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
57 (defsubst dsssl-check-args (args expected)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
58 ;; Signal an error if we don't have the expected # of arguments
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
59 (or (= (length args) expected)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
60 (error "Wrong # arguments (expected %d): %d" expected (length args))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
61
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
62 (defsubst dsssl-min-args (args min)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
63 (or (>= (length args) min)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
64 (error "Wrong # arguments (expected at least %d): %d" min
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
65 (length args))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
66
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
67 (defun dsssl-call-function (func args)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
68 (declare (special defines units))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
69 (let ((old-defines nil)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
70 (old-units nil)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
71 (func-args (nth 1 func))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
72 (real-func (nth 2 func))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
73 (retval nil))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
74 ;; Make sure we got the right # of arguments
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
75 (dsssl-check-args args (length func-args))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
76
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
77 ;; make sure we evaluate all the arguments in the old environment
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
78 (setq args (mapcar 'dsssl-eval args))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
79
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
80 ;; Save the old environment
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
81 (setq old-defines (cl-copy-hashtable defines)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
82 old-units (cl-copy-hashtable units))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
83
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
84 ;; Create the function's environment
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
85 (while func-args
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
86 (cl-puthash (car func-args) (car args) defines)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
87 (setq func-args (cdr func-args)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
88 args (cdr args)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
89
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
90 ;; Now evaluate the function body, returning the value of the last one
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
91 (while real-func
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
92 (setq retval (dsssl-eval (car real-func))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
93 real-func (cdr real-func)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
94
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
95 ;; Restore the previous environment
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
96 (setq defines old-defines
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
97 units old-units)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
98
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
99 ;; And we are out of here baby!
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
100 retval))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
101
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
102 (defun dsssl-eval (form)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
103 ;; We expect to have a 'defines' and 'units' hashtable floating around
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
104 ;; from higher up the call stack.
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
105 (declare (special defines units))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
106 (cond
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
107 ((consp form) ; A function call
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
108 (let ((func (car form))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
109 (args (cdr form)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
110 (case func
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
111 (cons
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
112 (dsssl-check-args args 2)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
113 (cons (dsssl-eval (pop args)) (dsssl-eval (pop args))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
114 (cdr
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
115 (dsssl-check-args args 1)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
116 (cdr (dsssl-eval (pop args))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
117 (car
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
118 (dsssl-check-args args 1)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
119 (car (dsssl-eval (pop args))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
120 (not
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
121 (dsssl-check-args args 1)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
122 (not (dsssl-eval (car args))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
123 (boolean\?
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
124 (dsssl-check-args args 1)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
125 (and (symbolp (car args))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
126 (memq (car args) '(\#f \#t))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
127 (if
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
128 (dsssl-min-args args 2)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
129 (let ((val (dsssl-eval (pop args))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
130 (if val
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
131 (dsssl-eval (nth 0 args))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
132 (if (nth 1 args)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
133 (dsssl-eval (nth 1 args))))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
134 (let ; FIXME
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
135 )
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
136 (case
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
137 (dsssl-min-args args 2)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
138 (let* ((val (dsssl-eval (pop args)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
139 (conditions args)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
140 (done nil)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
141 (possibles nil)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
142 (cur nil))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
143 (while (and conditions (not done))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
144 (setq cur (pop conditions)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
145 possibles (nth 0 cur))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
146 (if (or (and (listp possibles)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
147 (member val possibles))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
148 (equal val possibles)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
149 (memq possibles '(default otherwise)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
150 (setq done (dsssl-eval (nth 1 cur)))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
151 done))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
152 (equal\?
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
153 (dsssl-check-args args 2)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
154 (equal (dsssl-eval (car args)) (dsssl-eval (cadr args))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
155 (null\?
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
156 (dsssl-check-args args 1)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
157 (null (dsssl-eval (car args))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
158 (list\?
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
159 (dsssl-check-args args 1)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
160 (listp (dsssl-eval (car args))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
161 (list
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
162 (mapcar 'dsssl-eval args))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
163 (length
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
164 (dsssl-check-args args 1)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
165 (length (dsssl-eval (car args))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
166 (append
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
167 (apply 'append (mapcar 'dsssl-eval args)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
168 (reverse
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
169 (dsssl-check-args args 1)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
170 (reverse (dsssl-eval (car args))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
171 (list-tail
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
172 (dsssl-check-args args 2)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
173 (nthcdr (dsssl-eval (car args)) (dsssl-eval (cadr args))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
174 (list-ref
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
175 (dsssl-check-args args 2)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
176 (nth (dsssl-eval (car args)) (dsssl-eval (cadr args))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
177 (member
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
178 (dsssl-check-args args 2)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
179 (member (dsssl-eval (car args)) (dsssl-eval (cadr args))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
180 (symbol\?
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
181 (dsssl-check-args args 1)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
182 (symbolp (dsssl-eval (car args))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
183 (keyword\?
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
184 (dsssl-check-args args 1)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
185 (keywordp (dsssl-eval (car args))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
186 (quantity\?
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
187 (dsssl-check-args args 1)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
188 (error "%s not implemented yet." func))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
189 (number\?
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
190 (dsssl-check-args args 1)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
191 (numberp (dsssl-eval (car args))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
192 (real\?
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
193 (dsssl-check-args args 1)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
194 (let ((rval (dsssl-eval (car args))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
195 (and (numberp rval)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
196 (/= (truncate rval) rval))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
197 (integer\?
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
198 (dsssl-check-args args 1)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
199 (let ((rval (dsssl-eval (car args))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
200 (and (numberp rval)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
201 (= (truncate rval) rval))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
202 ((= < > <= >=)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
203 (dsssl-min-args args 2)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
204 (let ((not-done t)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
205 (initial (dsssl-eval (car args)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
206 (next nil))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
207 (setq args (cdr args))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
208 (while (and args not-done)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
209 (setq next (dsssl-eval (car args))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
210 args (cdr args)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
211 not-done (funcall func initial next)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
212 initial next))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
213 not-done))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
214 ((+ *)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
215 (dsssl-min-args args 2)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
216 (let ((acc (dsssl-eval (car args))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
217 (setq args (cdr args))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
218 (while args
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
219 (setq acc (funcall func acc (dsssl-eval (car args)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
220 args (cdr args)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
221 acc))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
222 (-
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
223 (dsssl-min-args args 1)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
224 (apply func (mapcar 'dsssl-eval args)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
225 (/
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
226 (dsssl-min-args args 1)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
227 (if (= (length args) 1)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
228 (/ 1 (dsssl-eval (car args)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
229 (apply func (mapcar 'dsssl-eval args))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
230 ((max min)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
231 (apply func (mapcar 'dsssl-eval args)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
232 (abs
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
233 (dsssl-check-args args 1)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
234 (abs (dsssl-eval (car args))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
235 (quotient ; FIXME
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
236 (error "`%s' not implemented yet!" func))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
237 (modulo
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
238 (dsssl-check-args args 2)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
239 (mod (dsssl-eval (car args)) (dsssl-eval (cadr args))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
240 (remainder
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
241 (dsssl-check-args args 2)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
242 (% (dsssl-eval (car args)) (dsssl-eval (cadr args))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
243 ((floor ceiling truncate round)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
244 (dsssl-check-args args 1)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
245 (funcall func (dsssl-eval (car args))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
246 (number->string
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
247 (dsssl-min-args args 1)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
248 (if (= (length args) 1)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
249 (number-to-string (dsssl-eval (car args)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
250 (if (= (length args) 2) ; They gave us a radix
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
251 (error "Radix arg not supported yet.")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
252 (dsssl-check-args args 1))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
253 (string->number
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
254 (dsssl-min-args args 1)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
255 (if (= (length args) 1)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
256 (string-to-number (dsssl-eval (car args)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
257 (if (= (length args) 2) ; They gave us a radix
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
258 (error "Radix arg not supported yet.")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
259 (dsssl-check-args args 1))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
260 (char\?
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
261 (dsssl-check-args args 1)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
262 (characterp (dsssl-eval (car args))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
263 (char=\?
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
264 (dsssl-check-args args 2)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
265 (char-equal (dsssl-eval (car args)) (dsssl-eval (cadr args))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
266 (char-downcase
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
267 (dsssl-check-args args 1)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
268 (downcase (dsssl-eval (car args))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
269 (char-property ; FIXME
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
270 (error "`%s' not implemented yet!" func))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
271 (string\?
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
272 (dsssl-check-args args 1)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
273 (stringp (dsssl-eval (car args))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
274 (string
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
275 (dsssl-min-args args 1)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
276 (mapconcat 'char-to-string (mapcar 'dsssl-eval args) ""))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
277 (string-length
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
278 (dsssl-check-args args 1)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
279 (length (dsssl-eval (car args))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
280 (string-ref
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
281 (dsssl-check-args args 2)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
282 (aref (dsssl-eval (car args)) (dsssl-eval (cadr args))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
283 (string=\?
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
284 (dsssl-check-args args 2)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
285 (string= (dsssl-eval (car args)) (dsssl-eval (cadr args))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
286 (substring
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
287 (substring (dsssl-eval (pop args))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
288 (dsssl-eval (pop args))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
289 (dsssl-eval (pop args))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
290 (string-append
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
291 (let ((rval ""))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
292 (while args
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
293 (setq rval (concat rval (dsssl-eval (pop args)))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
294 rval))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
295 (procedure\?
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
296 (dsssl-check-args args 1)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
297 (let* ((sym (dsssl-eval (car args)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
298 (def (cl-gethash sym defines)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
299 (or (memq sym dsssl-builtin-functions)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
300 (and def (listp def) (eq (car def) 'lambda)))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
301 (apply ; FIXME
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
302 )
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
303 (external-procedure ; FIXME
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
304 )
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
305 (make
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
306 (let* ((type (dsssl-eval (pop args)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
307 (symname nil)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
308 (props nil)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
309 (tail nil)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
310 (children nil)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
311 (temp nil)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
312 )
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
313 ;; Massage :children into the last slot
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
314 (setq props (mapcar 'dsssl-eval args)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
315 tail (last props)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
316 children (car tail))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
317 (if (consp tail)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
318 (setcar tail nil))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
319 (if (not (car props))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
320 (setq props nil))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
321 (setq temp (- (length props) 1))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
322 ;; Not sure if we should really bother with this or not, but
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
323 ;; it does at least make it look more common-lispy keywordish
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
324 ;; and such. DSSSL keywords look like font-weight:, this makes
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
325 ;; it :font-weight
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
326 (while (>= temp 0)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
327 (setq symname (symbol-name (nth temp props)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
328 (if (string-match "^\\(.*\\):$" symname)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
329 (setf (nth temp props)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
330 (intern (concat ":" (match-string 1 symname)))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
331 (setq temp (- temp 2)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
332
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
333 ;; Create the actual flow object
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
334 (make-flow-object :name type
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
335 :children children
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
336 :properties props)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
337 )
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
338 )
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
339 (time
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
340 (mapconcat 'int-to-string (current-time) ":"))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
341 (time->string
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
342 (dsssl-check-args args 1)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
343 (current-time-string
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
344 (mapcar 'string-to-int
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
345 (split-string (dsssl-eval (car args)) ":"))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
346 (quote
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
347 (dsssl-check-args args 1)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
348 (car args))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
349 (identity
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
350 (dsssl-check-args args 1)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
351 (dsssl-eval (car args)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
352 (error
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
353 (apply 'error (mapcar 'dsssl-eval args)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
354 (otherwise
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
355 ;; A non-built-in function - look it up
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
356 (let ((def (cl-gethash func defines)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
357 (if (and def (listp def) (eq (car def) 'lambda))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
358 (dsssl-call-function def args)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
359 (error "Symbol's function definition is void: %s" func))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
360 )
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
361 )
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
362 )
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
363 ((symbolp form) ; A variable
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
364 ;; A DSSSL keyword!
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
365 (if (string-match ":$" (symbol-name form))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
366 form
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
367 (let ((val (cl-gethash form defines 'ThIS-Is_A_BOgUs-VariuhhBBLE)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
368 (if (not (eq val 'ThIS-Is_A_BOgUs-VariuhhBBLE))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
369 val
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
370 ;; Ok, we got a bogus variable, but maybe it is really a UNIT
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
371 ;; dereference. Check.
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
372 (let ((name (symbol-name form))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
373 (the-units nil)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
374 (number nil)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
375 (conversion nil))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
376 (if (not (string-match "^\\([0-9.]+\\)\\([a-zA-Z]+\\)$" name))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
377 (error "Symbol's value as variable is void: %s" form)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
378 (setq number (string-to-int (match-string 1 name))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
379 the-units (intern (downcase (match-string 2 name)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
380 conversion (cl-gethash the-units units))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
381 (if (or (not conversion) (not (numberp conversion)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
382 (error "Symbol's value as variable is void: %s" form)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
383 (* number conversion))))))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
384 (t
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
385 form)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
386 )
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
387 )
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
388
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
389 (defsubst dsssl-predeclared ()
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
390 (declare (special defines units))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
391 (cl-puthash '\#f nil defines)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
392 (cl-puthash 'nil nil defines)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
393 (cl-puthash '\#t t defines)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
394 ;; NOTE: All units are stored internally as points.
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
395 (cl-puthash 'in (float 72) units)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
396 (cl-puthash 'mm (float (* 72 25.4)) units)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
397 (cl-puthash 'cm (float (* 72 2.54)) units)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
398 )
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
399
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
400 (defun dsssl-parse (buf)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
401 ;; Return the full representation of the DSSSL stylesheet as a series
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
402 ;; of LISP objects.
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
403 (let ((defines (make-hash-table :size 13))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
404 (units (make-hash-table :size 13))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
405 (buf-contents nil))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
406 (dsssl-predeclared)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
407 (save-excursion
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
408 (setq buf-contents (if (or (bufferp buf) (get-buffer buf))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
409 (progn
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
410 (set-buffer buf)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
411 (buffer-string))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
412 buf))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
413 (set-buffer (generate-new-buffer " *dsssl-style*"))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
414 (insert buf-contents)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
415 (goto-char (point-min))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
416 (skip-chars-forward " \t\n\r")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
417 (if (looking-at "<!") ; DOCTYPE present
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
418 (progn
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
419 ;; This should _DEFINITELY_ be smarter
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
420 (search-forward ">" nil t)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
421 ))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
422 (let ((result nil)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
423 (temp nil)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
424 (save-pos nil))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
425 (while (not (eobp))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
426 (condition-case ()
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
427 (setq save-pos (point)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
428 temp (read (current-buffer)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
429 (invalid-read-syntax
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
430 ;; This disgusting hack is in here so that we can basically
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
431 ;; extend the lisp reader to gracefully deal with converting
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
432 ;; DSSSL #\A to Emacs-Lisp ?A notation. If you know of a
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
433 ;; better way, please feel free to send me some email.
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
434 (setq temp nil)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
435 (backward-char 1)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
436 (if (looking-at "#\\\\")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
437 (replace-match "?")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
438 (insert "\\"))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
439 (goto-char save-pos))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
440 (error nil))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
441 (cond
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
442 ((null temp)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
443 nil)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
444 ((listp temp)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
445 (case (car temp)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
446 (define-unit
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
447 (cl-puthash (cadr temp) (dsssl-eval (caddr temp))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
448 units))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
449 (define
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
450 (if (listp (cadr temp))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
451 ;; A function
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
452 (cl-puthash (caadr temp)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
453 (list 'lambda
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
454 (cdadr temp)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
455 (cddr temp)) defines)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
456 ;; A normal define
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
457 (cl-puthash (cadr temp)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
458 (dsssl-eval (caddr temp)) defines)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
459 (otherwise
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
460 (setq result (cons temp result)))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
461 (t
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
462 (setq result (cons temp result))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
463 (skip-chars-forward " \t\n\r"))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
464 (kill-buffer (current-buffer))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
465 (list defines units (nreverse result))))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
466
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
467 (defun dsssl-test (x)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
468 (let* ((result (dsssl-parse x))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
469 (defines (nth 0 result))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
470 (units (nth 1 result))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
471 (forms (nth 2 result)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
472 (mapcar 'dsssl-eval forms)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
473
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
474
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
475 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
476 ;;; The flow object classes.
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
477 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
478 (defmacro flow-object-property (obj prop &optional default)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
479 "Return property PROP of the DSSSL flow object OBJ.
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
480 OBJ can be any flow object class, as long as it was properly derived
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
481 from the base `flow-object' class."
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
482 (` (plist-get (flow-object-properties (, obj)) (, prop) (, default))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
483
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
484 ;; Now for specific types of flow objects
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
485 ;; Still to do:
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
486 ;;; display-group
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
487 ;;; paragraph
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
488 ;;; sequence
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
489 ;;; line-field
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
490 ;;; paragraph-break
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
491 ;;; simple-page-sequence
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
492 ;;; score
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
493 ;;; table
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
494 ;;; table-row
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
495 ;;; table-cell
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
496 ;;; rule
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
497 ;;; external-graphic
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
498
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
499
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
500 (provide 'dsssl)