-
Notifications
You must be signed in to change notification settings - Fork 4
/
parse-web-input.lisp
43 lines (37 loc) · 1.36 KB
/
parse-web-input.lisp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
(in-package :jeffrey.parse-web-input)
(defun input-parse (input-string) ;=> input-names
(mapcar #'parse-integer
(split-sequence #\Space input-string
:remove-empty-subseqs T)))
(defun get-bad-names (input-names)
(loop for name in input-names
if (or (member name *bad-forms*)
(> name 430)
(< name 0))
collect name))
(defun get-good-names (input-names)
(let ((bad-names (get-bad-names input-names)))
(set-difference input-names bad-names)))
(defun pass-options-to-names (good-names key add-top-bottom)
(remove-duplicates
(if (and add-top-bottom (equal key :these))
(append '(0 1) good-names)
(name-transformer key good-names))))
(defun input->names (input-string key add-top-bottom)
(if #1=(get-good-names (input-parse input-string))
(sort (pass-options-to-names #1# key add-top-bottom)
#'<)
'(1))) ; If all input forms are bad, fine, just show AC.
(defmacro process-input ()
`(let ((input-string (parameter "names"))
(label-style (parameter "label-style"))
(add-top-bot (parameter "add-top-bottom"))
(key (cond ((parameter "these")
:these)
((parameter "descendants")
:descendants)
((parameter "ancestors")
:ancestors))))
(list (input->names input-string key add-top-bot)
(get-bad-names (input-parse input-string))
label-style)))