annotate lisp/w3/dsssl.el @ 14:9ee227acff29 r19-15b90

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