eliscript 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +674 -0
- package/README.md +135 -0
- package/bin/eliscript +16 -0
- package/bin/eliscript-bootstrap +15 -0
- package/bin/eliscript-build +15 -0
- package/bin/eliscript-check +15 -0
- package/bin/eliscript-eval +15 -0
- package/bin/eliscript-format +15 -0
- package/bin/eliscript-org +10 -0
- package/bin/eliscript-portable +17 -0
- package/bin/eliscript-seed +10 -0
- package/bin/eliscript-seed-build +10 -0
- package/bin/eliscript-watch +15 -0
- package/bootstrap/README.md +100 -0
- package/bootstrap/compiler/analyzer.eli +1426 -0
- package/bootstrap/compiler/compiler.eli +472 -0
- package/bootstrap/compiler/emitter.eli +1745 -0
- package/bootstrap/compiler/expander.eli +2522 -0
- package/bootstrap/compiler/formatter.eli +359 -0
- package/bootstrap/compiler/ir.eli +297 -0
- package/bootstrap/compiler/lower.eli +661 -0
- package/bootstrap/compiler/project.eli +1120 -0
- package/bootstrap/compiler/reader.eli +321 -0
- package/bootstrap/compiler/source-map.eli +165 -0
- package/bootstrap/compiler/symbol.eli +92 -0
- package/bootstrap/compiler/syntax.eli +54 -0
- package/bootstrap/compiler/transient-analysis.eli +825 -0
- package/bootstrap/host/build.mjs +28 -0
- package/bootstrap/host/bun.mjs +282 -0
- package/bootstrap/host/check-cli.mjs +163 -0
- package/bootstrap/host/eliscript-cli.mjs +36 -0
- package/bootstrap/host/evaluation-cli.mjs +401 -0
- package/bootstrap/host/evaluation.mjs +560 -0
- package/bootstrap/host/format-cli.mjs +139 -0
- package/bootstrap/host/project-cli.mjs +295 -0
- package/bootstrap/host/project.mjs +1080 -0
- package/bootstrap/host/watch-cli.mjs +129 -0
- package/bootstrap/host/watch.mjs +267 -0
- package/browser/host.mjs +357 -0
- package/browser/worker.mjs +60 -0
- package/compiler/README.md +118 -0
- package/compiler/eliscript-analyzer.el +716 -0
- package/compiler/eliscript-cli.el +108 -0
- package/compiler/eliscript-diagnostic.el +158 -0
- package/compiler/eliscript-emitter.el +1351 -0
- package/compiler/eliscript-evaluation.el +259 -0
- package/compiler/eliscript-expander.el +1630 -0
- package/compiler/eliscript-form.el +79 -0
- package/compiler/eliscript-ir-emitter.el +1460 -0
- package/compiler/eliscript-ir.el +356 -0
- package/compiler/eliscript-lower.el +463 -0
- package/compiler/eliscript-macro-eval.el +811 -0
- package/compiler/eliscript-parameters.el +324 -0
- package/compiler/eliscript-portable.el +492 -0
- package/compiler/eliscript-project-cli.el +156 -0
- package/compiler/eliscript-project.el +1676 -0
- package/compiler/eliscript-reader.el +421 -0
- package/compiler/eliscript-source-map.el +192 -0
- package/compiler/eliscript-symbol.el +101 -0
- package/compiler/eliscript-transient-analysis.el +817 -0
- package/compiler/eliscript.el +239 -0
- package/dist/bootstrap/analyzer.mjs +968 -0
- package/dist/bootstrap/analyzer.mjs.map +1 -0
- package/dist/bootstrap/compiler.mjs +228 -0
- package/dist/bootstrap/compiler.mjs.map +1 -0
- package/dist/bootstrap/emitter.mjs +1173 -0
- package/dist/bootstrap/emitter.mjs.map +1 -0
- package/dist/bootstrap/expander.mjs +1469 -0
- package/dist/bootstrap/expander.mjs.map +1 -0
- package/dist/bootstrap/formatter.mjs +304 -0
- package/dist/bootstrap/formatter.mjs.map +1 -0
- package/dist/bootstrap/ir.mjs +193 -0
- package/dist/bootstrap/ir.mjs.map +1 -0
- package/dist/bootstrap/lower.mjs +344 -0
- package/dist/bootstrap/lower.mjs.map +1 -0
- package/dist/bootstrap/project.mjs +585 -0
- package/dist/bootstrap/project.mjs.map +1 -0
- package/dist/bootstrap/reader.mjs +259 -0
- package/dist/bootstrap/reader.mjs.map +1 -0
- package/dist/bootstrap/source-map.mjs +154 -0
- package/dist/bootstrap/source-map.mjs.map +1 -0
- package/dist/bootstrap/symbol.mjs +74 -0
- package/dist/bootstrap/symbol.mjs.map +1 -0
- package/dist/bootstrap/syntax.mjs +38 -0
- package/dist/bootstrap/syntax.mjs.map +1 -0
- package/dist/bootstrap/transient-analysis.mjs +660 -0
- package/dist/bootstrap/transient-analysis.mjs.map +1 -0
- package/dist/browser/compiler.js +6491 -0
- package/editor/README.md +83 -0
- package/editor/eliscript-mode.el +878 -0
- package/editor/eliscript-repl.el +501 -0
- package/package.json +163 -0
- package/platform/README.md +48 -0
- package/platform/browser.mjs +204 -0
- package/platform/worker.mjs +166 -0
- package/runtime/README.md +296 -0
- package/runtime/core/collection-internals.mjs +512 -0
- package/runtime/core/collection.mjs +645 -0
- package/runtime/core/data-text.mjs +532 -0
- package/runtime/core/data.mjs +268 -0
- package/runtime/core/identifier.mjs +314 -0
- package/runtime/core/lazy-sequence.mjs +244 -0
- package/runtime/core/list-internals.mjs +18 -0
- package/runtime/core/list.mjs +273 -0
- package/runtime/core/map-internals.mjs +793 -0
- package/runtime/core/map.mjs +394 -0
- package/runtime/core/metadata-internals.mjs +14 -0
- package/runtime/core/metadata.mjs +44 -0
- package/runtime/core/object-impl.mjs +65 -0
- package/runtime/core/object-impl.mjs.map +1 -0
- package/runtime/core/object.mjs +13 -0
- package/runtime/core/order.mjs +234 -0
- package/runtime/core/persistent-kind.mjs +43 -0
- package/runtime/core/protocol-error.mjs +36 -0
- package/runtime/core/protocol-impl.mjs +326 -0
- package/runtime/core/protocol-impl.mjs.map +1 -0
- package/runtime/core/protocol.mjs +14 -0
- package/runtime/core/queue-internals.mjs +27 -0
- package/runtime/core/queue.mjs +238 -0
- package/runtime/core/record.mjs +346 -0
- package/runtime/core/regex.mjs +184 -0
- package/runtime/core/sequence.mjs +632 -0
- package/runtime/core/set-algebra.mjs +287 -0
- package/runtime/core/set-internals.mjs +33 -0
- package/runtime/core/set.mjs +378 -0
- package/runtime/core/sorted-internals.mjs +215 -0
- package/runtime/core/sorted.mjs +598 -0
- package/runtime/core/text-impl.mjs +95 -0
- package/runtime/core/text-impl.mjs.map +1 -0
- package/runtime/core/text.mjs +15 -0
- package/runtime/core/transducer.mjs +668 -0
- package/runtime/core/transient-internals.mjs +38 -0
- package/runtime/core/transient.mjs +53 -0
- package/runtime/core/truth.mjs +3 -0
- package/runtime/core/type.mjs +262 -0
- package/runtime/core/value-internals.mjs +188 -0
- package/runtime/core/value.mjs +93 -0
- package/runtime/core/vector-internals.mjs +102 -0
- package/runtime/core/vector.mjs +951 -0
- package/runtime/literals.mjs +34 -0
- package/runtime/source-mapping.mjs +220 -0
- package/runtime/testing/list.mjs +52 -0
- package/runtime/testing/map.mjs +145 -0
- package/runtime/testing/queue.mjs +49 -0
- package/runtime/testing/set.mjs +61 -0
- package/runtime/testing/sorted.mjs +105 -0
- package/runtime/testing/value.mjs +17 -0
- package/runtime/testing/vector.mjs +102 -0
- package/runtime/worker-value-codec.mjs +565 -0
- package/runtime/worker-value-stream.mjs +786 -0
- package/runtime/worker.mjs +975 -0
- package/stdlib/README.md +774 -0
- package/stdlib/bit.eli +36 -0
- package/stdlib/core/collection.eli +134 -0
- package/stdlib/core/data-text.eli +16 -0
- package/stdlib/core/data.eli +306 -0
- package/stdlib/core/identifier.eli +32 -0
- package/stdlib/core/lazy-sequence.eli +63 -0
- package/stdlib/core/metadata.eli +20 -0
- package/stdlib/core/object.eli +89 -0
- package/stdlib/core/order.eli +133 -0
- package/stdlib/core/protocol.eli +387 -0
- package/stdlib/core/record.eli +16 -0
- package/stdlib/core/regex.eli +17 -0
- package/stdlib/core/seq.eli +701 -0
- package/stdlib/core/set.eli +312 -0
- package/stdlib/core/sorted.eli +53 -0
- package/stdlib/core/text.eli +103 -0
- package/stdlib/core/transducer.eli +59 -0
- package/stdlib/core/transient.eli +24 -0
- package/stdlib/core/type.eli +19 -0
- package/stdlib/core/walk.eli +195 -0
- package/stdlib/core/zipper.eli +508 -0
- package/stdlib/data-text.eli +1092 -0
- package/stdlib/data.eli +42 -0
- package/stdlib/deferred.eli +70 -0
- package/stdlib/function.eli +120 -0
- package/stdlib/hierarchy.eli +245 -0
- package/stdlib/identifier.eli +147 -0
- package/stdlib/interop/js.eli +616 -0
- package/stdlib/json.eli +870 -0
- package/stdlib/metadata.eli +56 -0
- package/stdlib/multimethod.eli +464 -0
- package/stdlib/numeric.eli +193 -0
- package/stdlib/object.eli +96 -0
- package/stdlib/persistent-list.eli +145 -0
- package/stdlib/persistent-map.eli +724 -0
- package/stdlib/persistent-queue.eli +32 -0
- package/stdlib/persistent-set.eli +236 -0
- package/stdlib/persistent-vector.eli +342 -0
- package/stdlib/result.eli +141 -0
- package/stdlib/sequence.eli +106 -0
- package/stdlib/state/atom.eli +265 -0
- package/stdlib/text.eli +88 -0
- package/stdlib/value.eli +325 -0
|
@@ -0,0 +1,324 @@
|
|
|
1
|
+
;;; eliscript-parameters.el --- Function parameter parsing -*- lexical-binding: t; -*-
|
|
2
|
+
|
|
3
|
+
;;; Commentary:
|
|
4
|
+
|
|
5
|
+
;; Parse the shared required, optional, and rest parameter grammar while
|
|
6
|
+
;; preserving located source forms for diagnostics and IR lowering.
|
|
7
|
+
|
|
8
|
+
;;; Code:
|
|
9
|
+
|
|
10
|
+
(require 'cl-lib)
|
|
11
|
+
(require 'eliscript-form)
|
|
12
|
+
|
|
13
|
+
(cl-defstruct (eliscript-parameter
|
|
14
|
+
(:constructor eliscript-parameter-create))
|
|
15
|
+
kind
|
|
16
|
+
form)
|
|
17
|
+
|
|
18
|
+
(defconst eliscript-binding--markers '(&optional &rest &body))
|
|
19
|
+
|
|
20
|
+
(defun eliscript-binding-map-pattern-p (form)
|
|
21
|
+
"Return non-nil when FORM is a reader map in binding position."
|
|
22
|
+
(let ((value (eliscript-form-value form)))
|
|
23
|
+
(and (proper-list-p value)
|
|
24
|
+
value
|
|
25
|
+
(eq (eliscript-form-value (car value)) 'hash-map))))
|
|
26
|
+
|
|
27
|
+
(defun eliscript-binding-pattern-p (form)
|
|
28
|
+
"Return non-nil when FORM can represent a binding pattern."
|
|
29
|
+
(let ((value (eliscript-form-value form)))
|
|
30
|
+
(or (and value
|
|
31
|
+
(symbolp value)
|
|
32
|
+
(not (memq value eliscript-binding--markers)))
|
|
33
|
+
(vectorp value)
|
|
34
|
+
(eliscript-binding-map-pattern-p form))))
|
|
35
|
+
|
|
36
|
+
(defun eliscript-binding--split-name (name)
|
|
37
|
+
"Return NAME as a (NAMESPACE . LOCAL-NAME) string pair."
|
|
38
|
+
(let* ((text (symbol-name name))
|
|
39
|
+
(slash (cl-position ?/ text :from-end t)))
|
|
40
|
+
(if slash
|
|
41
|
+
(cons (substring text 0 slash) (substring text (1+ slash)))
|
|
42
|
+
(cons nil text))))
|
|
43
|
+
|
|
44
|
+
(defun eliscript-binding--map-shortcut (directive)
|
|
45
|
+
"Return normalized map shortcut metadata for keyword DIRECTIVE."
|
|
46
|
+
(when (keywordp directive)
|
|
47
|
+
(let* ((parts
|
|
48
|
+
(eliscript-binding--split-name
|
|
49
|
+
(intern (substring (symbol-name directive) 1))))
|
|
50
|
+
(kind (intern (cdr parts))))
|
|
51
|
+
(when (memq kind '(keys strs syms))
|
|
52
|
+
(list :kind kind :namespace (car parts))))))
|
|
53
|
+
|
|
54
|
+
(defun eliscript-binding--map-shortcut-entry
|
|
55
|
+
(kind namespace name-form name)
|
|
56
|
+
"Normalize one KIND shortcut binding for NAME-FORM and NAME.
|
|
57
|
+
|
|
58
|
+
NAMESPACE comes from a qualified shortcut such as `:user/keys'."
|
|
59
|
+
(let* ((parts (eliscript-binding--split-name name))
|
|
60
|
+
(local-name (cdr parts))
|
|
61
|
+
(key-namespace (or namespace (car parts)))
|
|
62
|
+
(qualified-name
|
|
63
|
+
(if key-namespace
|
|
64
|
+
(concat key-namespace "/" local-name)
|
|
65
|
+
local-name))
|
|
66
|
+
(target
|
|
67
|
+
(eliscript-form-inherit (intern local-name) name-form)))
|
|
68
|
+
(list :target target
|
|
69
|
+
:key-kind kind
|
|
70
|
+
:key-name
|
|
71
|
+
(pcase kind
|
|
72
|
+
('keys (intern (concat ":" qualified-name)))
|
|
73
|
+
('syms (intern qualified-name))
|
|
74
|
+
('strs (symbol-name name))))))
|
|
75
|
+
|
|
76
|
+
(defun eliscript-binding-map-spec (pattern fail)
|
|
77
|
+
"Validate map binding PATTERN and return its normalized specification.
|
|
78
|
+
|
|
79
|
+
The result contains `:entries', each with `:target', `:key', and optional
|
|
80
|
+
`:default', plus an optional `:as' binding. FAIL receives the offending form
|
|
81
|
+
and a diagnostic message."
|
|
82
|
+
(let* ((items (cdr (eliscript-form-value pattern)))
|
|
83
|
+
entries defaults as
|
|
84
|
+
shortcuts-seen or-seen as-seen)
|
|
85
|
+
(unless (= (% (length items) 2) 0)
|
|
86
|
+
(funcall fail pattern "map binding pattern requires key/value pairs"))
|
|
87
|
+
(while items
|
|
88
|
+
(let* ((left (pop items))
|
|
89
|
+
(right (pop items))
|
|
90
|
+
(directive (eliscript-form-value left))
|
|
91
|
+
(shortcut (eliscript-binding--map-shortcut directive)))
|
|
92
|
+
(cond
|
|
93
|
+
(shortcut
|
|
94
|
+
(when (memq directive shortcuts-seen)
|
|
95
|
+
(funcall fail left
|
|
96
|
+
(format "map binding pattern accepts %s once" directive)))
|
|
97
|
+
(push directive shortcuts-seen)
|
|
98
|
+
(let ((names (eliscript-form-value right)))
|
|
99
|
+
(unless (vectorp names)
|
|
100
|
+
(funcall fail right
|
|
101
|
+
(format "map binding :%s value must be a vector"
|
|
102
|
+
(plist-get shortcut :kind))))
|
|
103
|
+
(dolist (name-form (append names nil))
|
|
104
|
+
(let ((name (eliscript-form-value name-form)))
|
|
105
|
+
(unless (and name
|
|
106
|
+
(symbolp name)
|
|
107
|
+
(not (keywordp name))
|
|
108
|
+
(not (memq name eliscript-binding--markers))
|
|
109
|
+
(> (length
|
|
110
|
+
(cdr (eliscript-binding--split-name name)))
|
|
111
|
+
0))
|
|
112
|
+
(funcall fail name-form
|
|
113
|
+
(format "map binding :%s entries must be symbols"
|
|
114
|
+
(plist-get shortcut :kind))))
|
|
115
|
+
(push
|
|
116
|
+
(eliscript-binding--map-shortcut-entry
|
|
117
|
+
(plist-get shortcut :kind)
|
|
118
|
+
(plist-get shortcut :namespace)
|
|
119
|
+
name-form name)
|
|
120
|
+
entries)))))
|
|
121
|
+
((eq directive :or)
|
|
122
|
+
(when or-seen
|
|
123
|
+
(funcall fail left "map binding pattern accepts :or once"))
|
|
124
|
+
(setq or-seen t)
|
|
125
|
+
(unless (eliscript-binding-map-pattern-p right)
|
|
126
|
+
(funcall fail right "map binding :or value must be a map"))
|
|
127
|
+
(let ((pairs (cdr (eliscript-form-value right))))
|
|
128
|
+
(while pairs
|
|
129
|
+
(let* ((name-form (pop pairs))
|
|
130
|
+
(default (pop pairs))
|
|
131
|
+
(name (eliscript-form-value name-form)))
|
|
132
|
+
(unless (and name
|
|
133
|
+
(symbolp name)
|
|
134
|
+
(not (keywordp name))
|
|
135
|
+
(not (memq name eliscript-binding--markers)))
|
|
136
|
+
(funcall fail name-form
|
|
137
|
+
"map binding :or keys must be binding symbols"))
|
|
138
|
+
(when (assq name defaults)
|
|
139
|
+
(funcall fail name-form
|
|
140
|
+
"duplicate map binding :or default"))
|
|
141
|
+
(push (cons name default) defaults)))))
|
|
142
|
+
((eq directive :as)
|
|
143
|
+
(when as-seen
|
|
144
|
+
(funcall fail left "map binding pattern accepts :as once"))
|
|
145
|
+
(setq as-seen t)
|
|
146
|
+
(let ((name (eliscript-form-value right)))
|
|
147
|
+
(unless (and name
|
|
148
|
+
(symbolp name)
|
|
149
|
+
(not (keywordp name))
|
|
150
|
+
(not (memq name eliscript-binding--markers)))
|
|
151
|
+
(funcall fail right "map binding :as value must be a symbol"))
|
|
152
|
+
(setq as right)))
|
|
153
|
+
((keywordp directive)
|
|
154
|
+
(funcall fail left
|
|
155
|
+
(format "unknown map binding directive: %s" directive)))
|
|
156
|
+
(t
|
|
157
|
+
(unless (eliscript-binding-pattern-p left)
|
|
158
|
+
(funcall fail left "map binding entry target must be a binding pattern"))
|
|
159
|
+
(let ((key (eliscript-form-value right)))
|
|
160
|
+
(unless (or (keywordp key) (stringp key) (numberp key))
|
|
161
|
+
(funcall fail right
|
|
162
|
+
"map binding entry key must be a keyword, string, or number")))
|
|
163
|
+
(push (list :target left :key right) entries)))))
|
|
164
|
+
(setq entries (nreverse entries))
|
|
165
|
+
(dolist (default defaults)
|
|
166
|
+
(let ((entry
|
|
167
|
+
(cl-find-if
|
|
168
|
+
(lambda (candidate)
|
|
169
|
+
(eq (eliscript-form-value (plist-get candidate :target))
|
|
170
|
+
(car default)))
|
|
171
|
+
entries)))
|
|
172
|
+
(unless entry
|
|
173
|
+
(funcall fail (cdr default)
|
|
174
|
+
(format "map binding :or has no scalar target: %s"
|
|
175
|
+
(car default))))
|
|
176
|
+
(plist-put entry :default (cdr default))))
|
|
177
|
+
(list :entries entries :as as)))
|
|
178
|
+
|
|
179
|
+
(defun eliscript-binding-defaults (pattern fail)
|
|
180
|
+
"Return every default expression nested in binding PATTERN."
|
|
181
|
+
(let ((value (eliscript-form-value pattern)))
|
|
182
|
+
(cond
|
|
183
|
+
((or (null value) (symbolp value)) nil)
|
|
184
|
+
((vectorp value)
|
|
185
|
+
(apply #'append
|
|
186
|
+
(mapcar
|
|
187
|
+
(lambda (element)
|
|
188
|
+
(let ((element-value (eliscript-form-value element)))
|
|
189
|
+
(if (or (null element-value)
|
|
190
|
+
(eq element-value '&rest))
|
|
191
|
+
nil
|
|
192
|
+
(eliscript-binding-defaults element fail))))
|
|
193
|
+
(append value nil))))
|
|
194
|
+
((eliscript-binding-map-pattern-p pattern)
|
|
195
|
+
(let ((spec (eliscript-binding-map-spec pattern fail)) defaults)
|
|
196
|
+
(dolist (entry (plist-get spec :entries))
|
|
197
|
+
(when (plist-member entry :default)
|
|
198
|
+
(push (plist-get entry :default) defaults))
|
|
199
|
+
(setq defaults
|
|
200
|
+
(nconc
|
|
201
|
+
(nreverse
|
|
202
|
+
(eliscript-binding-defaults
|
|
203
|
+
(plist-get entry :target) fail))
|
|
204
|
+
defaults)))
|
|
205
|
+
(nreverse defaults)))
|
|
206
|
+
(t nil))))
|
|
207
|
+
|
|
208
|
+
(defun eliscript-binding-names (pattern fail)
|
|
209
|
+
"Validate binding PATTERN and return its bound symbol forms.
|
|
210
|
+
|
|
211
|
+
FAIL receives the offending form and a diagnostic message. Vector patterns
|
|
212
|
+
support nested vectors, nil holes, and one final `&rest' symbol. Map patterns
|
|
213
|
+
support explicit entries plus `:keys', `:strs', `:syms', qualified
|
|
214
|
+
shortcuts, `:or', and `:as'."
|
|
215
|
+
(let ((value (eliscript-form-value pattern)))
|
|
216
|
+
(cond
|
|
217
|
+
((null value) nil)
|
|
218
|
+
((symbolp value)
|
|
219
|
+
(if (memq value eliscript-binding--markers)
|
|
220
|
+
(progn
|
|
221
|
+
(funcall fail pattern "invalid binding pattern marker")
|
|
222
|
+
nil)
|
|
223
|
+
(list pattern)))
|
|
224
|
+
((vectorp value)
|
|
225
|
+
(let ((elements (append value nil))
|
|
226
|
+
names
|
|
227
|
+
rest-seen
|
|
228
|
+
rest-done)
|
|
229
|
+
(dolist (element elements)
|
|
230
|
+
(let ((element-value (eliscript-form-value element)))
|
|
231
|
+
(cond
|
|
232
|
+
((eq element-value '&rest)
|
|
233
|
+
(when (or rest-seen rest-done)
|
|
234
|
+
(funcall fail element "invalid vector binding pattern"))
|
|
235
|
+
(setq rest-seen t))
|
|
236
|
+
(rest-seen
|
|
237
|
+
(unless (and element-value
|
|
238
|
+
(symbolp element-value)
|
|
239
|
+
(not (memq element-value
|
|
240
|
+
eliscript-binding--markers)))
|
|
241
|
+
(funcall fail element
|
|
242
|
+
"vector &rest binding must be a symbol"))
|
|
243
|
+
(push element names)
|
|
244
|
+
(setq rest-seen nil
|
|
245
|
+
rest-done t))
|
|
246
|
+
(rest-done
|
|
247
|
+
(funcall fail element
|
|
248
|
+
"vector &rest binding must be final"))
|
|
249
|
+
((null element-value) nil)
|
|
250
|
+
(t
|
|
251
|
+
(setq names
|
|
252
|
+
(nconc
|
|
253
|
+
(nreverse (eliscript-binding-names element fail))
|
|
254
|
+
names))))))
|
|
255
|
+
(when rest-seen
|
|
256
|
+
(funcall fail pattern "vector &rest requires a binding"))
|
|
257
|
+
(nreverse names)))
|
|
258
|
+
((eliscript-binding-map-pattern-p pattern)
|
|
259
|
+
(let* ((spec (eliscript-binding-map-spec pattern fail))
|
|
260
|
+
(entries (plist-get spec :entries))
|
|
261
|
+
(as (plist-get spec :as))
|
|
262
|
+
names)
|
|
263
|
+
(dolist (entry entries)
|
|
264
|
+
(setq names
|
|
265
|
+
(nconc names
|
|
266
|
+
(eliscript-binding-names
|
|
267
|
+
(plist-get entry :target) fail))))
|
|
268
|
+
(if as (append names (list as)) names)))
|
|
269
|
+
(t
|
|
270
|
+
(funcall
|
|
271
|
+
fail pattern
|
|
272
|
+
(format "binding pattern must be a symbol, vector, or map: %S"
|
|
273
|
+
(eliscript-form-strip pattern)))
|
|
274
|
+
nil))))
|
|
275
|
+
|
|
276
|
+
(defun eliscript-parameters-parse (parameters fail)
|
|
277
|
+
"Parse located function PARAMETERS, calling FAIL for invalid syntax.
|
|
278
|
+
|
|
279
|
+
FAIL receives the offending form and a fully formatted diagnostic message."
|
|
280
|
+
(let ((items (eliscript-form-value parameters)))
|
|
281
|
+
(unless (proper-list-p items)
|
|
282
|
+
(funcall fail parameters "function arguments must be a list"))
|
|
283
|
+
(let ((mode 'required)
|
|
284
|
+
parsed)
|
|
285
|
+
(dolist (parameter items)
|
|
286
|
+
(let ((name (eliscript-form-value parameter)))
|
|
287
|
+
(cond
|
|
288
|
+
((eq name '&optional)
|
|
289
|
+
(unless (eq mode 'required)
|
|
290
|
+
(funcall fail parameter "invalid function parameter list"))
|
|
291
|
+
(setq mode 'optional))
|
|
292
|
+
((eq name '&rest)
|
|
293
|
+
(unless (memq mode '(required optional))
|
|
294
|
+
(funcall fail parameter "invalid function parameter list"))
|
|
295
|
+
(setq mode 'rest))
|
|
296
|
+
((eq name '&body)
|
|
297
|
+
(funcall fail parameter "invalid function parameter list"))
|
|
298
|
+
((eq mode 'rest)
|
|
299
|
+
(unless (and name
|
|
300
|
+
(symbolp name)
|
|
301
|
+
(not (memq name eliscript-binding--markers)))
|
|
302
|
+
(funcall fail parameter
|
|
303
|
+
"function &rest parameter must be a symbol"))
|
|
304
|
+
(push (eliscript-parameter-create :kind 'rest :form parameter)
|
|
305
|
+
parsed)
|
|
306
|
+
(setq mode 'done))
|
|
307
|
+
((eq mode 'done)
|
|
308
|
+
(funcall fail parameter "invalid function parameter list"))
|
|
309
|
+
(t
|
|
310
|
+
(unless (eliscript-binding-pattern-p parameter)
|
|
311
|
+
(funcall
|
|
312
|
+
fail parameter
|
|
313
|
+
(format "function arguments must be symbols, vectors, or maps: %S"
|
|
314
|
+
(eliscript-form-strip parameters))))
|
|
315
|
+
(eliscript-binding-names parameter fail)
|
|
316
|
+
(push (eliscript-parameter-create :kind mode :form parameter)
|
|
317
|
+
parsed)))))
|
|
318
|
+
(when (eq mode 'rest)
|
|
319
|
+
(funcall fail parameters "invalid function parameter list"))
|
|
320
|
+
(nreverse parsed))))
|
|
321
|
+
|
|
322
|
+
(provide 'eliscript-parameters)
|
|
323
|
+
|
|
324
|
+
;;; eliscript-parameters.el ends here
|