Mercurial > emacs
annotate lisp/cedet/srecode/dictionary.el @ 111358:4cf33ba4068d
* xfns.c (x_real_positions): Only use _NET_FRAME_EXTENTS if our
parent is the root window. Check this after traversing window tree.
author | Jan D. <jan.h.d@swipnet.se> |
---|---|
date | Thu, 04 Nov 2010 13:37:17 +0100 |
parents | 67ff8ad45bd5 |
children | 376148b31b5e |
rev | line source |
---|---|
104498 | 1 ;;; srecode-dictionary.el --- Dictionary code for the semantic recoder. |
2 | |
106815 | 3 ;; Copyright (C) 2007, 2008, 2009, 2010 Free Software Foundation, Inc. |
104498 | 4 |
5 ;; Author: Eric M. Ludlam <eric@siege-engine.com> | |
6 | |
7 ;; This file is part of GNU Emacs. | |
8 | |
9 ;; GNU Emacs is free software: you can redistribute it and/or modify | |
10 ;; it under the terms of the GNU General Public License as published by | |
11 ;; the Free Software Foundation, either version 3 of the License, or | |
12 ;; (at your option) any later version. | |
13 | |
14 ;; GNU Emacs is distributed in the hope that it will be useful, | |
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 ;; GNU General Public License for more details. | |
18 | |
19 ;; You should have received a copy of the GNU General Public License | |
20 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. | |
21 | |
22 ;;; Commentary: | |
23 ;; | |
105328 | 24 ;; Dictionaries contain lists of names and their associated values. |
104498 | 25 ;; These dictionaries are used to fill in macros from recoder templates. |
26 | |
27 ;;; Code: | |
28 | |
29 ;;; CLASSES | |
30 | |
105652
51bc239bdc37
* cedet/srecode/srt.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
105377
diff
changeset
|
31 (eval-when-compile (require 'cl)) |
104498 | 32 (require 'eieio) |
33 (require 'srecode) | |
34 (require 'srecode/table) | |
35 (eval-when-compile (require 'semantic)) | |
36 | |
37 (declare-function srecode-compile-parse-inserter "srecode/compile") | |
38 (declare-function srecode-dump-code-list "srecode/compile") | |
39 (declare-function srecode-load-tables-for-mode "srecode/find") | |
110531
67ff8ad45bd5
Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106895
diff
changeset
|
40 (declare-function srecode-template-table-in-project-p "srecode/find") |
104498 | 41 (declare-function srecode-insert-code-stream "srecode/insert") |
42 (declare-function data-debug-new-buffer "data-debug") | |
43 (declare-function data-debug-insert-object-slots "eieio-datadebug") | |
44 (declare-function srecode-field "srecode/fields") | |
45 | |
46 (defclass srecode-dictionary () | |
47 ((namehash :initarg :namehash | |
48 :documentation | |
49 "Hash table containing the names of all the templates.") | |
50 (buffer :initarg :buffer | |
51 :documentation | |
52 "The buffer this dictionary was initialized with.") | |
53 (parent :initarg :parent | |
54 :type (or null srecode-dictionary) | |
55 :documentation | |
56 "The parent dictionary. | |
57 Symbols not appearing in this dictionary will be checked against the | |
58 parent dictionary.") | |
59 (origin :initarg :origin | |
60 :type string | |
61 :documentation | |
62 "A string representing the origin of this dictionary. | |
63 Useful only while debugging.") | |
64 ) | |
65 "Dictionary of symbols and what they mean. | |
66 Dictionaries are used to look up named symbols from | |
67 templates to decide what to do with those symbols.") | |
68 | |
69 (defclass srecode-dictionary-compound-value () | |
70 () | |
71 "A compound dictionary value. | |
72 Values stored in a dictionary must be a STRING, | |
73 a dictionary for showing sections, or an instance of a subclass | |
74 of this class. | |
75 | |
76 Compound dictionary values derive from this class, and must | |
77 provide a sequence of method implementations to convert into | |
78 a string." | |
79 :abstract t) | |
80 | |
81 (defclass srecode-dictionary-compound-variable | |
82 (srecode-dictionary-compound-value) | |
83 ((value :initarg :value | |
84 :documentation | |
85 "The value of this template variable. | |
86 Variables in template files are usually a single string | |
87 which can be inserted into a dictionary directly. | |
88 | |
89 Some variables may be more complex and involve dictionary | |
90 lookups, strings, concatenation, or the like. | |
91 | |
92 The format of VALUE is determined by current template | |
93 formatting rules.") | |
94 (compiled :initarg :compiled | |
95 :type list | |
96 :documentation | |
97 "The compiled version of VALUE.") | |
98 ) | |
99 "A compound dictionary value for template file variables. | |
100 You can declare a variable in a template like this: | |
101 | |
102 set NAME \"str\" macro \"OTHERNAME\" | |
103 | |
104 with appending various parts together in a list.") | |
105 | |
106 (defmethod initialize-instance ((this srecode-dictionary-compound-variable) | |
107 &optional fields) | |
108 "Initialize the compound variable THIS. | |
109 Makes sure that :value is compiled." | |
110 (let ((newfields nil) | |
111 (state nil)) | |
112 (while fields | |
113 ;; Strip out :state | |
114 (if (eq (car fields) :state) | |
115 (setq state (car (cdr fields))) | |
116 (setq newfields (cons (car (cdr fields)) | |
117 (cons (car fields) newfields)))) | |
118 (setq fields (cdr (cdr fields)))) | |
119 | |
120 (when (not state) | |
121 (error "Cannot create compound variable without :state")) | |
122 | |
123 (call-next-method this (nreverse newfields)) | |
124 (when (not (slot-boundp this 'compiled)) | |
125 (let ((val (oref this :value)) | |
126 (comp nil)) | |
127 (while val | |
128 (let ((nval (car val)) | |
129 ) | |
130 (cond ((stringp nval) | |
131 (setq comp (cons nval comp))) | |
132 ((and (listp nval) | |
133 (equal (car nval) 'macro)) | |
134 (require 'srecode/compile) | |
135 (setq comp (cons | |
136 (srecode-compile-parse-inserter | |
137 (cdr nval) | |
138 state) | |
139 comp))) | |
140 (t | |
141 (error "Don't know how to handle variable value %S" nval))) | |
142 ) | |
143 (setq val (cdr val))) | |
144 (oset this :compiled (nreverse comp)))))) | |
145 | |
146 ;;; DICTIONARY METHODS | |
147 ;; | |
148 | |
149 (defun srecode-create-dictionary (&optional buffer-or-parent) | |
150 "Create a dictionary for BUFFER. | |
151 If BUFFER-OR-PARENT is not specified, assume a buffer, and | |
152 use the current buffer. | |
153 If BUFFER-OR-PARENT is another dictionary, then remember the | |
154 parent within the new dictionary, and assume that BUFFER | |
155 is the same as belongs to the parent dictionary. | |
156 The dictionary is initialized with variables setup for that | |
157 buffer's table. | |
158 If BUFFER-OR-PARENT is t, then this dictionary should not be | |
105328 | 159 associated with a buffer or parent." |
104498 | 160 (save-excursion |
110531
67ff8ad45bd5
Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106895
diff
changeset
|
161 ;; Handle the parent |
104498 | 162 (let ((parent nil) |
163 (buffer nil) | |
164 (origin nil) | |
165 (initfrombuff nil)) | |
110531
67ff8ad45bd5
Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106895
diff
changeset
|
166 (cond |
67ff8ad45bd5
Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106895
diff
changeset
|
167 ;; Parent is a buffer |
67ff8ad45bd5
Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106895
diff
changeset
|
168 ((bufferp buffer-or-parent) |
67ff8ad45bd5
Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106895
diff
changeset
|
169 (set-buffer buffer-or-parent) |
67ff8ad45bd5
Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106895
diff
changeset
|
170 (setq buffer buffer-or-parent |
67ff8ad45bd5
Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106895
diff
changeset
|
171 origin (buffer-name buffer-or-parent) |
67ff8ad45bd5
Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106895
diff
changeset
|
172 initfrombuff t)) |
67ff8ad45bd5
Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106895
diff
changeset
|
173 |
67ff8ad45bd5
Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106895
diff
changeset
|
174 ;; Parent is another dictionary |
67ff8ad45bd5
Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106895
diff
changeset
|
175 ((srecode-dictionary-child-p buffer-or-parent) |
67ff8ad45bd5
Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106895
diff
changeset
|
176 (setq parent buffer-or-parent |
67ff8ad45bd5
Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106895
diff
changeset
|
177 buffer (oref buffer-or-parent buffer) |
67ff8ad45bd5
Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106895
diff
changeset
|
178 origin (concat (object-name buffer-or-parent) " in " |
67ff8ad45bd5
Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106895
diff
changeset
|
179 (if buffer (buffer-name buffer) |
67ff8ad45bd5
Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106895
diff
changeset
|
180 "no buffer"))) |
67ff8ad45bd5
Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106895
diff
changeset
|
181 (when buffer |
67ff8ad45bd5
Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106895
diff
changeset
|
182 (set-buffer buffer))) |
67ff8ad45bd5
Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106895
diff
changeset
|
183 |
67ff8ad45bd5
Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106895
diff
changeset
|
184 ;; No parent |
67ff8ad45bd5
Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106895
diff
changeset
|
185 ((eq buffer-or-parent t) |
67ff8ad45bd5
Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106895
diff
changeset
|
186 (setq buffer nil |
67ff8ad45bd5
Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106895
diff
changeset
|
187 origin "Unspecified Origin")) |
67ff8ad45bd5
Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106895
diff
changeset
|
188 |
67ff8ad45bd5
Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106895
diff
changeset
|
189 ;; Default to unspecified parent |
67ff8ad45bd5
Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106895
diff
changeset
|
190 (t |
67ff8ad45bd5
Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106895
diff
changeset
|
191 (setq buffer (current-buffer) |
67ff8ad45bd5
Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106895
diff
changeset
|
192 origin (concat "Unspecified. Assume " |
67ff8ad45bd5
Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106895
diff
changeset
|
193 (buffer-name buffer)) |
67ff8ad45bd5
Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106895
diff
changeset
|
194 initfrombuff t))) |
67ff8ad45bd5
Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106895
diff
changeset
|
195 |
67ff8ad45bd5
Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106895
diff
changeset
|
196 ;; Create the new dictionary object. |
104498 | 197 (let ((dict (srecode-dictionary |
198 major-mode | |
110531
67ff8ad45bd5
Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106895
diff
changeset
|
199 :buffer buffer |
67ff8ad45bd5
Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106895
diff
changeset
|
200 :parent parent |
67ff8ad45bd5
Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106895
diff
changeset
|
201 :namehash (make-hash-table :test 'equal |
67ff8ad45bd5
Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106895
diff
changeset
|
202 :size 20) |
67ff8ad45bd5
Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106895
diff
changeset
|
203 :origin origin))) |
104498 | 204 ;; Only set up the default variables if we are being built |
205 ;; directroy for a particular buffer. | |
206 (when initfrombuff | |
207 ;; Variables from the table we are inserting from. | |
208 ;; @todo - get a better tree of tables. | |
209 (let ((mt (srecode-get-mode-table major-mode)) | |
210 (def (srecode-get-mode-table 'default))) | |
211 ;; Each table has multiple template tables. | |
212 ;; Do DEF first so that MT can override any values. | |
213 (srecode-dictionary-add-template-table dict def) | |
214 (srecode-dictionary-add-template-table dict mt) | |
215 )) | |
216 dict)))) | |
217 | |
218 (defmethod srecode-dictionary-add-template-table ((dict srecode-dictionary) | |
219 tpl) | |
220 "Insert into DICT the variables found in table TPL. | |
221 TPL is an object representing a compiled template file." | |
222 (when tpl | |
223 (let ((tabs (oref tpl :tables))) | |
110531
67ff8ad45bd5
Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106895
diff
changeset
|
224 (require 'srecode/find) ; For srecode-template-table-in-project-p |
104498 | 225 (while tabs |
110531
67ff8ad45bd5
Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106895
diff
changeset
|
226 (when (srecode-template-table-in-project-p (car tabs)) |
67ff8ad45bd5
Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106895
diff
changeset
|
227 (let ((vars (oref (car tabs) variables))) |
67ff8ad45bd5
Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106895
diff
changeset
|
228 (while vars |
67ff8ad45bd5
Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106895
diff
changeset
|
229 (srecode-dictionary-set-value |
67ff8ad45bd5
Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106895
diff
changeset
|
230 dict (car (car vars)) (cdr (car vars))) |
67ff8ad45bd5
Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106895
diff
changeset
|
231 (setq vars (cdr vars))))) |
67ff8ad45bd5
Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106895
diff
changeset
|
232 (setq tabs (cdr tabs)))))) |
104498 | 233 |
234 | |
235 (defmethod srecode-dictionary-set-value ((dict srecode-dictionary) | |
236 name value) | |
237 "In dictionary DICT, set NAME to have VALUE." | |
238 ;; Validate inputs | |
110531
67ff8ad45bd5
Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106895
diff
changeset
|
239 (unless (stringp name) |
67ff8ad45bd5
Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106895
diff
changeset
|
240 (signal 'wrong-type-argument (list name 'stringp))) |
67ff8ad45bd5
Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106895
diff
changeset
|
241 |
104498 | 242 ;; Add the value. |
243 (with-slots (namehash) dict | |
244 (puthash name value namehash)) | |
245 ) | |
246 | |
247 (defmethod srecode-dictionary-add-section-dictionary ((dict srecode-dictionary) | |
110531
67ff8ad45bd5
Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106895
diff
changeset
|
248 name &optional show-only force) |
104498 | 249 "In dictionary DICT, add a section dictionary for section macro NAME. |
250 Return the new dictionary. | |
251 | |
110531
67ff8ad45bd5
Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106895
diff
changeset
|
252 You can add several dictionaries to the same section entry. |
67ff8ad45bd5
Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106895
diff
changeset
|
253 For each dictionary added to a variable, the block of codes in |
67ff8ad45bd5
Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106895
diff
changeset
|
254 the template will be repeated. |
104498 | 255 |
106895
181539c8b6a4
Fix typos in docstrings, error messages, etc.
Juanma Barranquero <lekktu@gmail.com>
parents:
106815
diff
changeset
|
256 If optional argument SHOW-ONLY is non-nil, then don't add a new dictionary |
104498 | 257 if there is already one in place. Also, don't add FIRST/LAST entries. |
258 These entries are not needed when we are just showing a section. | |
259 | |
260 Each dictionary added will automatically get values for positional macros | |
261 which will enable SECTIONS to be enabled. | |
262 | |
263 * FIRST - The first entry in the table. | |
264 * NOTFIRST - Not the first entry in the table. | |
265 * LAST - The last entry in the table | |
266 * NOTLAST - Not the last entry in the table. | |
267 | |
268 Adding a new dictionary will alter these values in previously | |
269 inserted dictionaries." | |
270 ;; Validate inputs | |
110531
67ff8ad45bd5
Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106895
diff
changeset
|
271 (unless (stringp name) |
67ff8ad45bd5
Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106895
diff
changeset
|
272 (signal 'wrong-type-argument (list name 'stringp))) |
67ff8ad45bd5
Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106895
diff
changeset
|
273 |
104498 | 274 (let ((new (srecode-create-dictionary dict)) |
110531
67ff8ad45bd5
Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106895
diff
changeset
|
275 (ov (srecode-dictionary-lookup-name dict name t))) |
104498 | 276 |
277 (when (not show-only) | |
278 ;; Setup the FIRST/NOTFIRST and LAST/NOTLAST entries. | |
279 (if (null ov) | |
280 (progn | |
281 (srecode-dictionary-show-section new "FIRST") | |
282 (srecode-dictionary-show-section new "LAST")) | |
283 ;; Not the very first one. Lets clean up CAR. | |
284 (let ((tail (car (last ov)))) | |
285 (srecode-dictionary-hide-section tail "LAST") | |
286 (srecode-dictionary-show-section tail "NOTLAST") | |
287 ) | |
288 (srecode-dictionary-show-section new "NOTFIRST") | |
289 (srecode-dictionary-show-section new "LAST")) | |
290 ) | |
291 | |
110531
67ff8ad45bd5
Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106895
diff
changeset
|
292 (when (or force |
67ff8ad45bd5
Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106895
diff
changeset
|
293 (not show-only) |
67ff8ad45bd5
Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106895
diff
changeset
|
294 (null ov)) |
104498 | 295 (srecode-dictionary-set-value dict name (append ov (list new)))) |
296 ;; Return the new sub-dictionary. | |
297 new)) | |
298 | |
299 (defmethod srecode-dictionary-show-section ((dict srecode-dictionary) name) | |
300 "In dictionary DICT, indicate that the section NAME should be exposed." | |
301 ;; Validate inputs | |
110531
67ff8ad45bd5
Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106895
diff
changeset
|
302 (unless (stringp name) |
67ff8ad45bd5
Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106895
diff
changeset
|
303 (signal 'wrong-type-argument (list name 'stringp))) |
67ff8ad45bd5
Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106895
diff
changeset
|
304 |
104498 | 305 ;; Showing a section is just like making a section dictionary, but |
306 ;; with no dictionary values to add. | |
307 (srecode-dictionary-add-section-dictionary dict name t) | |
308 nil) | |
309 | |
310 (defmethod srecode-dictionary-hide-section ((dict srecode-dictionary) name) | |
311 "In dictionary DICT, indicate that the section NAME should be hidden." | |
312 ;; We need to find the has value, and then delete it. | |
313 ;; Validate inputs | |
110531
67ff8ad45bd5
Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106895
diff
changeset
|
314 (unless (stringp name) |
67ff8ad45bd5
Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106895
diff
changeset
|
315 (signal 'wrong-type-argument (list name 'stringp))) |
67ff8ad45bd5
Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106895
diff
changeset
|
316 |
104498 | 317 ;; Add the value. |
318 (with-slots (namehash) dict | |
319 (remhash name namehash)) | |
320 nil) | |
321 | |
110531
67ff8ad45bd5
Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106895
diff
changeset
|
322 (defmethod srecode-dictionary-add-entries ((dict srecode-dictionary) |
67ff8ad45bd5
Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106895
diff
changeset
|
323 entries &optional state) |
67ff8ad45bd5
Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106895
diff
changeset
|
324 "Add ENTRIES to DICT. |
67ff8ad45bd5
Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106895
diff
changeset
|
325 |
67ff8ad45bd5
Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106895
diff
changeset
|
326 ENTRIES is a list of even length of dictionary entries to |
67ff8ad45bd5
Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106895
diff
changeset
|
327 add. ENTRIES looks like this: |
67ff8ad45bd5
Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106895
diff
changeset
|
328 |
67ff8ad45bd5
Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106895
diff
changeset
|
329 (NAME_1 VALUE_1 NAME_2 VALUE_2 ...) |
67ff8ad45bd5
Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106895
diff
changeset
|
330 |
67ff8ad45bd5
Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106895
diff
changeset
|
331 The following rules apply: |
67ff8ad45bd5
Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106895
diff
changeset
|
332 * NAME_N is a string |
67ff8ad45bd5
Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106895
diff
changeset
|
333 and for values |
67ff8ad45bd5
Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106895
diff
changeset
|
334 * If VALUE_N is t, the section NAME_N is shown. |
67ff8ad45bd5
Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106895
diff
changeset
|
335 * If VALUE_N is a string, an ordinary value is inserted. |
67ff8ad45bd5
Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106895
diff
changeset
|
336 * If VALUE_N is a dictionary, it is inserted as entry NAME_N. |
67ff8ad45bd5
Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106895
diff
changeset
|
337 * Otherwise, a compound variable is created for VALUE_N. |
67ff8ad45bd5
Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106895
diff
changeset
|
338 |
67ff8ad45bd5
Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106895
diff
changeset
|
339 The optional argument STATE has to non-nil when compound values |
67ff8ad45bd5
Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106895
diff
changeset
|
340 are inserted. An error is signaled if ENTRIES contains compound |
67ff8ad45bd5
Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106895
diff
changeset
|
341 values but STATE is nil." |
67ff8ad45bd5
Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106895
diff
changeset
|
342 (while entries |
67ff8ad45bd5
Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106895
diff
changeset
|
343 (let ((name (nth 0 entries)) |
67ff8ad45bd5
Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106895
diff
changeset
|
344 (value (nth 1 entries))) |
67ff8ad45bd5
Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106895
diff
changeset
|
345 (cond |
67ff8ad45bd5
Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106895
diff
changeset
|
346 ;; Value is t; show a section. |
67ff8ad45bd5
Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106895
diff
changeset
|
347 ((eq value t) |
67ff8ad45bd5
Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106895
diff
changeset
|
348 (srecode-dictionary-show-section dict name)) |
67ff8ad45bd5
Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106895
diff
changeset
|
349 |
67ff8ad45bd5
Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106895
diff
changeset
|
350 ;; Value is a simple string; create an ordinary dictionary |
67ff8ad45bd5
Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106895
diff
changeset
|
351 ;; entry |
67ff8ad45bd5
Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106895
diff
changeset
|
352 ((stringp value) |
67ff8ad45bd5
Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106895
diff
changeset
|
353 (srecode-dictionary-set-value dict name value)) |
67ff8ad45bd5
Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106895
diff
changeset
|
354 |
67ff8ad45bd5
Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106895
diff
changeset
|
355 ;; Value is a dictionary; insert as child dictionary. |
67ff8ad45bd5
Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106895
diff
changeset
|
356 ((srecode-dictionary-child-p value) |
67ff8ad45bd5
Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106895
diff
changeset
|
357 (srecode-dictionary-merge |
67ff8ad45bd5
Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106895
diff
changeset
|
358 (srecode-dictionary-add-section-dictionary dict name) |
67ff8ad45bd5
Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106895
diff
changeset
|
359 value t)) |
67ff8ad45bd5
Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106895
diff
changeset
|
360 |
67ff8ad45bd5
Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106895
diff
changeset
|
361 ;; Value is some other object; create a compound value. |
67ff8ad45bd5
Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106895
diff
changeset
|
362 (t |
67ff8ad45bd5
Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106895
diff
changeset
|
363 (unless state |
67ff8ad45bd5
Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106895
diff
changeset
|
364 (error "Cannot insert compound values without state.")) |
67ff8ad45bd5
Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106895
diff
changeset
|
365 |
67ff8ad45bd5
Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106895
diff
changeset
|
366 (srecode-dictionary-set-value |
67ff8ad45bd5
Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106895
diff
changeset
|
367 dict name |
67ff8ad45bd5
Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106895
diff
changeset
|
368 (srecode-dictionary-compound-variable |
67ff8ad45bd5
Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106895
diff
changeset
|
369 name :value value :state state))))) |
67ff8ad45bd5
Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106895
diff
changeset
|
370 (setq entries (nthcdr 2 entries))) |
67ff8ad45bd5
Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106895
diff
changeset
|
371 dict) |
67ff8ad45bd5
Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106895
diff
changeset
|
372 |
67ff8ad45bd5
Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106895
diff
changeset
|
373 (defmethod srecode-dictionary-merge ((dict srecode-dictionary) otherdict |
67ff8ad45bd5
Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106895
diff
changeset
|
374 &optional force) |
67ff8ad45bd5
Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106895
diff
changeset
|
375 "Merge into DICT the dictionary entries from OTHERDICT. |
67ff8ad45bd5
Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106895
diff
changeset
|
376 Unless the optional argument FORCE is non-nil, values in DICT are |
67ff8ad45bd5
Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106895
diff
changeset
|
377 not modified, even if there are values of the same names in |
67ff8ad45bd5
Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106895
diff
changeset
|
378 OTHERDICT." |
104498 | 379 (when otherdict |
380 (maphash | |
381 (lambda (key entry) | |
110531
67ff8ad45bd5
Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106895
diff
changeset
|
382 ;; The new values is only merged in if there was no old value |
67ff8ad45bd5
Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106895
diff
changeset
|
383 ;; or FORCE is non-nil. |
67ff8ad45bd5
Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106895
diff
changeset
|
384 ;; |
104498 | 385 ;; This protects applications from being whacked, and basically |
386 ;; makes these new section dictionary entries act like | |
387 ;; "defaults" instead of overrides. | |
110531
67ff8ad45bd5
Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106895
diff
changeset
|
388 (when (or force |
67ff8ad45bd5
Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106895
diff
changeset
|
389 (not (srecode-dictionary-lookup-name dict key t))) |
67ff8ad45bd5
Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106895
diff
changeset
|
390 (cond |
67ff8ad45bd5
Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106895
diff
changeset
|
391 ;; A list of section dictionaries. We need to merge them in. |
67ff8ad45bd5
Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106895
diff
changeset
|
392 ((and (listp entry) |
67ff8ad45bd5
Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106895
diff
changeset
|
393 (srecode-dictionary-p (car entry))) |
67ff8ad45bd5
Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106895
diff
changeset
|
394 (dolist (sub-dict entry) |
67ff8ad45bd5
Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106895
diff
changeset
|
395 (srecode-dictionary-merge |
67ff8ad45bd5
Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106895
diff
changeset
|
396 (srecode-dictionary-add-section-dictionary |
67ff8ad45bd5
Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106895
diff
changeset
|
397 dict key t t) |
67ff8ad45bd5
Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106895
diff
changeset
|
398 sub-dict force))) |
104498 | 399 |
110531
67ff8ad45bd5
Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106895
diff
changeset
|
400 ;; Other values can be set directly. |
67ff8ad45bd5
Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106895
diff
changeset
|
401 (t |
67ff8ad45bd5
Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106895
diff
changeset
|
402 (srecode-dictionary-set-value dict key entry))))) |
104498 | 403 (oref otherdict namehash)))) |
404 | |
405 (defmethod srecode-dictionary-lookup-name ((dict srecode-dictionary) | |
110531
67ff8ad45bd5
Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106895
diff
changeset
|
406 name &optional non-recursive) |
67ff8ad45bd5
Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106895
diff
changeset
|
407 "Return information about DICT's value for NAME. |
67ff8ad45bd5
Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106895
diff
changeset
|
408 DICT is a dictionary, and NAME is a string that is treated as the |
67ff8ad45bd5
Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106895
diff
changeset
|
409 name of an entry in the dictionary. If such an entry exists, its |
67ff8ad45bd5
Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106895
diff
changeset
|
410 value is returned. Otherwise, nil is returned. Normally, the |
67ff8ad45bd5
Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106895
diff
changeset
|
411 lookup is recursive in the sense that the parent of DICT is |
67ff8ad45bd5
Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106895
diff
changeset
|
412 searched for NAME if it is not found in DICT. This recursive |
67ff8ad45bd5
Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106895
diff
changeset
|
413 lookup can be disabled by the optional argument NON-RECURSIVE. |
67ff8ad45bd5
Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106895
diff
changeset
|
414 |
67ff8ad45bd5
Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106895
diff
changeset
|
415 This function derives values for some special NAMEs, such as |
67ff8ad45bd5
Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106895
diff
changeset
|
416 'FIRST' and 'LAST'." |
104498 | 417 (if (not (slot-boundp dict 'namehash)) |
418 nil | |
110531
67ff8ad45bd5
Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106895
diff
changeset
|
419 ;; Get the value of this name from the dictionary or its parent |
67ff8ad45bd5
Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106895
diff
changeset
|
420 ;; unless the lookup should be non-recursive. |
67ff8ad45bd5
Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106895
diff
changeset
|
421 (with-slots (namehash parent) dict |
67ff8ad45bd5
Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106895
diff
changeset
|
422 (or (gethash name namehash) |
67ff8ad45bd5
Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106895
diff
changeset
|
423 (and (not non-recursive) |
67ff8ad45bd5
Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106895
diff
changeset
|
424 (not (member name '("FIRST" "LAST" "NOTFIRST" "NOTLAST"))) |
67ff8ad45bd5
Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106895
diff
changeset
|
425 parent |
67ff8ad45bd5
Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106895
diff
changeset
|
426 (srecode-dictionary-lookup-name parent name))))) |
67ff8ad45bd5
Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106895
diff
changeset
|
427 ) |
104498 | 428 |
429 (defmethod srecode-root-dictionary ((dict srecode-dictionary)) | |
430 "For dictionary DICT, return the root dictionary. | |
431 The root dictionary is usually for a current or active insertion." | |
432 (let ((ans dict)) | |
433 (while (oref ans parent) | |
434 (setq ans (oref ans parent))) | |
435 ans)) | |
436 | |
437 ;;; COMPOUND VALUE METHODS | |
438 ;; | |
439 ;; Compound values must provide at least the toStriong method | |
440 ;; for use in converting the compound value into sometehing insertable. | |
441 | |
442 (defmethod srecode-compound-toString ((cp srecode-dictionary-compound-value) | |
443 function | |
444 dictionary) | |
445 "Convert the compound dictionary value CP to a string. | |
446 If FUNCTION is non-nil, then FUNCTION is somehow applied to an aspect | |
447 of the compound value. The FUNCTION could be a fraction | |
448 of some function symbol with a logical prefix excluded. | |
449 | |
450 If you subclass `srecode-dictionary-compound-value' then this | |
451 method could return nil, but if it does that, it must insert | |
452 the value itself using `princ', or by detecting if the current | |
453 standard out is a buffer, and using `insert'." | |
454 (object-name cp)) | |
455 | |
456 (defmethod srecode-dump ((cp srecode-dictionary-compound-value) | |
457 &optional indent) | |
458 "Display information about this compound value." | |
459 (princ (object-name cp)) | |
460 ) | |
461 | |
462 (defmethod srecode-compound-toString ((cp srecode-dictionary-compound-variable) | |
463 function | |
464 dictionary) | |
465 "Convert the compound dictionary variable value CP into a string. | |
466 FUNCTION and DICTIONARY are as for the baseclass." | |
467 (require 'srecode/insert) | |
468 (srecode-insert-code-stream (oref cp compiled) dictionary)) | |
469 | |
470 | |
471 (defmethod srecode-dump ((cp srecode-dictionary-compound-variable) | |
472 &optional indent) | |
473 "Display information about this compound value." | |
474 (require 'srecode/compile) | |
475 (princ "# Compound Variable #\n") | |
476 (let ((indent (+ 4 (or indent 0))) | |
477 (cmp (oref cp compiled)) | |
478 ) | |
479 (srecode-dump-code-list cmp (make-string indent ? )) | |
480 )) | |
481 | |
482 ;;; FIELD EDITING COMPOUND VALUE | |
483 ;; | |
484 ;; This is an interface to using field-editing objects | |
485 ;; instead of asking questions. This provides the basics | |
486 ;; behind this compound value. | |
487 | |
488 (defclass srecode-field-value (srecode-dictionary-compound-value) | |
489 ((firstinserter :initarg :firstinserter | |
490 :documentation | |
106895
181539c8b6a4
Fix typos in docstrings, error messages, etc.
Juanma Barranquero <lekktu@gmail.com>
parents:
106815
diff
changeset
|
491 "The inserter object for the first occurrence of this field.") |
104498 | 492 (defaultvalue :initarg :defaultvalue |
493 :documentation | |
494 "The default value for this inserter.") | |
495 ) | |
496 "When inserting values with editable field mode, a dictionary value. | |
497 Compound values allow a field to be stored in the dictionary for when | |
498 it is referenced a second time. This compound value can then be | |
499 inserted with a new editable field.") | |
500 | |
501 (defmethod srecode-compound-toString((cp srecode-field-value) | |
502 function | |
503 dictionary) | |
504 "Convert this field into an insertable string." | |
505 (require 'srecode/fields) | |
506 ;; If we are not in a buffer, then this is not supported. | |
507 (when (not (bufferp standard-output)) | |
105328 | 508 (error "FIELDS invoked while inserting template to non-buffer")) |
104498 | 509 |
510 (if function | |
105328 | 511 (error "@todo: Cannot mix field insertion with functions") |
104498 | 512 |
513 ;; No function. Perform a plain field insertion. | |
514 ;; We know we are in a buffer, so we can perform the insertion. | |
515 (let* ((dv (oref cp defaultvalue)) | |
516 (sti (oref cp firstinserter)) | |
517 (start (point)) | |
518 (name (oref sti :object-name))) | |
519 | |
110531
67ff8ad45bd5
Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106895
diff
changeset
|
520 (cond |
67ff8ad45bd5
Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106895
diff
changeset
|
521 ;; No default value. |
67ff8ad45bd5
Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106895
diff
changeset
|
522 ((not dv) (insert name)) |
67ff8ad45bd5
Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106895
diff
changeset
|
523 ;; A compound value as the default? Recurse. |
67ff8ad45bd5
Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106895
diff
changeset
|
524 ((srecode-dictionary-compound-value-child-p dv) |
67ff8ad45bd5
Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106895
diff
changeset
|
525 (srecode-compound-toString dv function dictionary)) |
67ff8ad45bd5
Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106895
diff
changeset
|
526 ;; A string that is empty? Use the name. |
67ff8ad45bd5
Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106895
diff
changeset
|
527 ((and (stringp dv) (string= dv "")) |
67ff8ad45bd5
Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106895
diff
changeset
|
528 (insert name)) |
67ff8ad45bd5
Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106895
diff
changeset
|
529 ;; Insert strings |
67ff8ad45bd5
Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106895
diff
changeset
|
530 ((stringp dv) (insert dv)) |
67ff8ad45bd5
Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106895
diff
changeset
|
531 ;; Some other issue |
67ff8ad45bd5
Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106895
diff
changeset
|
532 (t |
67ff8ad45bd5
Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106895
diff
changeset
|
533 (error "Unknown default value for value %S" name))) |
104498 | 534 |
110531
67ff8ad45bd5
Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106895
diff
changeset
|
535 ;; Create a field from the inserter. |
104498 | 536 (srecode-field name :name name |
537 :start start | |
538 :end (point) | |
539 :prompt (oref sti prompt) | |
540 :read-fcn (oref sti read-fcn) | |
541 ) | |
542 )) | |
543 ;; Returning nil is a signal that we have done the insertion ourselves. | |
544 nil) | |
545 | |
546 | |
547 ;;; Higher level dictionary functions | |
548 ;; | |
549 (defun srecode-create-section-dictionary (sectiondicts STATE) | |
550 "Create a dictionary with section entries for a template. | |
551 The format for SECTIONDICTS is what is emitted from the template parsers. | |
552 STATE is the current compiler state." | |
553 (when sectiondicts | |
554 (let ((new (srecode-create-dictionary t))) | |
555 ;; Loop over each section. The section is a macro w/in the | |
556 ;; template. | |
557 (while sectiondicts | |
558 (let* ((sect (car (car sectiondicts))) | |
559 (entries (cdr (car sectiondicts))) | |
560 (subdict (srecode-dictionary-add-section-dictionary new sect)) | |
561 ) | |
562 ;; Loop over each entry. This is one variable in the | |
563 ;; section dictionary. | |
564 (while entries | |
565 (let ((tname (semantic-tag-name (car entries))) | |
566 (val (semantic-tag-variable-default (car entries)))) | |
567 (if (eq val t) | |
568 (srecode-dictionary-show-section subdict tname) | |
569 (cond | |
570 ((and (stringp (car val)) | |
571 (= (length val) 1)) | |
572 (setq val (car val))) | |
573 (t | |
574 (setq val (srecode-dictionary-compound-variable | |
575 tname :value val :state STATE)))) | |
576 (srecode-dictionary-set-value | |
577 subdict tname val)) | |
578 (setq entries (cdr entries)))) | |
579 ) | |
580 (setq sectiondicts (cdr sectiondicts))) | |
581 new))) | |
582 | |
110531
67ff8ad45bd5
Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106895
diff
changeset
|
583 (defun srecode-create-dictionaries-from-tags (tags state) |
67ff8ad45bd5
Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106895
diff
changeset
|
584 "Create a dictionary with entries according to TAGS. |
67ff8ad45bd5
Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106895
diff
changeset
|
585 |
67ff8ad45bd5
Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106895
diff
changeset
|
586 TAGS should be in the format produced by the template file |
67ff8ad45bd5
Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106895
diff
changeset
|
587 grammar. That is |
67ff8ad45bd5
Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106895
diff
changeset
|
588 |
67ff8ad45bd5
Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106895
diff
changeset
|
589 TAGS = (ENTRY_1 ENTRY_2 ...) |
67ff8ad45bd5
Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106895
diff
changeset
|
590 |
67ff8ad45bd5
Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106895
diff
changeset
|
591 where |
67ff8ad45bd5
Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106895
diff
changeset
|
592 |
67ff8ad45bd5
Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106895
diff
changeset
|
593 ENTRY_N = (NAME ENTRY_N_1 ENTRY_N_2 ...) | TAG |
67ff8ad45bd5
Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106895
diff
changeset
|
594 |
67ff8ad45bd5
Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106895
diff
changeset
|
595 where TAG is a semantic tag of class 'variable. The (NAME ... ) |
67ff8ad45bd5
Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106895
diff
changeset
|
596 form creates a child dictionary which is stored under the name |
67ff8ad45bd5
Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106895
diff
changeset
|
597 NAME. The TAG form creates a value entry or section dictionary |
67ff8ad45bd5
Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106895
diff
changeset
|
598 entry whose name is the name of the tag. |
67ff8ad45bd5
Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106895
diff
changeset
|
599 |
67ff8ad45bd5
Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106895
diff
changeset
|
600 STATE is the current compiler state." |
67ff8ad45bd5
Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106895
diff
changeset
|
601 (let ((dict (srecode-create-dictionary t)) |
67ff8ad45bd5
Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106895
diff
changeset
|
602 (entries (apply #'append |
67ff8ad45bd5
Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106895
diff
changeset
|
603 (mapcar |
67ff8ad45bd5
Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106895
diff
changeset
|
604 (lambda (entry) |
67ff8ad45bd5
Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106895
diff
changeset
|
605 (cond |
67ff8ad45bd5
Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106895
diff
changeset
|
606 ;; Entry is a tag |
67ff8ad45bd5
Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106895
diff
changeset
|
607 ((semantic-tag-p entry) |
67ff8ad45bd5
Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106895
diff
changeset
|
608 (let ((name (semantic-tag-name entry)) |
67ff8ad45bd5
Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106895
diff
changeset
|
609 (value (semantic-tag-variable-default entry))) |
67ff8ad45bd5
Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106895
diff
changeset
|
610 (list name |
67ff8ad45bd5
Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106895
diff
changeset
|
611 (if (and (listp value) |
67ff8ad45bd5
Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106895
diff
changeset
|
612 (= (length value) 1) |
67ff8ad45bd5
Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106895
diff
changeset
|
613 (stringp (car value))) |
67ff8ad45bd5
Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106895
diff
changeset
|
614 (car value) |
67ff8ad45bd5
Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106895
diff
changeset
|
615 value)))) |
67ff8ad45bd5
Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106895
diff
changeset
|
616 |
67ff8ad45bd5
Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106895
diff
changeset
|
617 ;; Entry is a nested dictionary |
67ff8ad45bd5
Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106895
diff
changeset
|
618 (t |
67ff8ad45bd5
Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106895
diff
changeset
|
619 (let ((name (car entry)) |
67ff8ad45bd5
Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106895
diff
changeset
|
620 (entries (cdr entry))) |
67ff8ad45bd5
Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106895
diff
changeset
|
621 (list name |
67ff8ad45bd5
Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106895
diff
changeset
|
622 (srecode-create-dictionaries-from-tags |
67ff8ad45bd5
Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106895
diff
changeset
|
623 entries state)))))) |
67ff8ad45bd5
Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106895
diff
changeset
|
624 tags)))) |
67ff8ad45bd5
Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106895
diff
changeset
|
625 (srecode-dictionary-add-entries |
67ff8ad45bd5
Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106895
diff
changeset
|
626 dict entries state) |
67ff8ad45bd5
Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106895
diff
changeset
|
627 dict) |
67ff8ad45bd5
Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106895
diff
changeset
|
628 ) |
67ff8ad45bd5
Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106895
diff
changeset
|
629 |
104498 | 630 ;;; DUMP DICTIONARY |
631 ;; | |
632 ;; Make a dictionary, and dump it's contents. | |
633 | |
634 (defun srecode-adebug-dictionary () | |
635 "Run data-debug on this mode's dictionary." | |
636 (interactive) | |
637 (require 'eieio-datadebug) | |
638 (require 'semantic) | |
639 (require 'srecode/find) | |
640 (let* ((modesym major-mode) | |
641 (start (current-time)) | |
642 (junk (or (progn (srecode-load-tables-for-mode modesym) | |
643 (srecode-get-mode-table modesym)) | |
644 (error "No table found for mode %S" modesym))) | |
645 (dict (srecode-create-dictionary (current-buffer))) | |
646 (end (current-time)) | |
647 ) | |
648 (message "Creating a dictionary took %.2f seconds." | |
649 (semantic-elapsed-time start end)) | |
650 (data-debug-new-buffer "*SRECODE ADEBUG*") | |
651 (data-debug-insert-object-slots dict "*"))) | |
652 | |
653 (defun srecode-dictionary-dump () | |
654 "Dump a typical fabricated dictionary." | |
655 (interactive) | |
656 (require 'srecode/find) | |
657 (let ((modesym major-mode)) | |
658 ;; This load allows the dictionary access to inherited | |
659 ;; and stacked dictionary entries. | |
660 (srecode-load-tables-for-mode modesym) | |
661 (let ((tmp (srecode-get-mode-table modesym)) | |
662 ) | |
663 (if (not tmp) | |
664 (error "No table found for mode %S" modesym)) | |
665 ;; Now make the dictionary. | |
666 (let ((dict (srecode-create-dictionary (current-buffer)))) | |
667 (with-output-to-temp-buffer "*SRECODE DUMP*" | |
668 (princ "DICTIONARY FOR ") | |
669 (princ major-mode) | |
670 (princ "\n--------------------------------------------\n") | |
671 (srecode-dump dict)) | |
672 )))) | |
673 | |
674 (defmethod srecode-dump ((dict srecode-dictionary) &optional indent) | |
675 "Dump a dictionary." | |
676 (if (not indent) (setq indent 0)) | |
677 (maphash (lambda (key entry) | |
678 (princ (make-string indent ? )) | |
679 (princ " ") | |
680 (princ key) | |
681 (princ " ") | |
682 (cond ((and (listp entry) | |
683 (srecode-dictionary-p (car entry))) | |
684 (let ((newindent (if indent | |
685 (+ indent 4) | |
686 4))) | |
687 (while entry | |
688 (princ " --> SUBDICTIONARY ") | |
689 (princ (object-name dict)) | |
690 (princ "\n") | |
691 (srecode-dump (car entry) newindent) | |
692 (setq entry (cdr entry)) | |
693 )) | |
694 (princ "\n") | |
695 ) | |
696 ((srecode-dictionary-compound-value-child-p entry) | |
697 (srecode-dump entry indent) | |
698 (princ "\n") | |
699 ) | |
700 (t | |
701 (prin1 entry) | |
702 ;(princ "\n") | |
703 )) | |
704 (terpri) | |
705 ) | |
706 (oref dict namehash)) | |
707 ) | |
708 | |
709 (provide 'srecode/dictionary) | |
710 | |
105377 | 711 ;; arch-tag: c664179c-171c-4709-9b56-d5a2fd30e457 |
104498 | 712 ;;; srecode/dictionary.el ends here |