-
Notifications
You must be signed in to change notification settings - Fork 2
/
yaclml-syntax-improvement.lisp
57 lines (46 loc) · 1.57 KB
/
yaclml-syntax-improvement.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
(in-package :weblocks-cms)
#|
Version: 0.0.3
Example of using yaclml after this code evaluating
CL-USER> (<a :href "asdf" "jkl")
<a href="asdf"
>jkl</a
>; No value
CL-USER> (<some-undefined-tag :some-parameter "asdf" "jkl")
<some-undefined-tag some-parameter="asdf"
>jkl</some-undefined-tag
>; No value
CL-USER>
|#
#-YACLML-SYNTAX-IMPROVEMENT
(defvar *original-bracket-macro-reader* (get-macro-character #\())
#-YACLML-SYNTAX-IMPROVEMENT
(defmacro print-tag (tag &rest args)
(setf tag (subseq (string tag) 1))
(unless (find-symbol tag :<)
(eval `(yaclml::def-simple-xtag ,(intern tag :<))))
`(,(find-symbol tag :<) ,@args))
#-YACLML-SYNTAX-IMPROVEMENT
(defun debug-dispatch (stream char)
(let* ((first-char (read-char stream))
(second-char (peek-char nil stream nil))
(function-starts-with-<-and-not-colon
(and
second-char
(equal #\< first-char)
(not (equal #\: second-char))
(not (equal #\Space second-char))
(not (equal #\= second-char))
(not (equal #\) second-char)))))
(unread-char first-char stream )
(if function-starts-with-<-and-not-colon
(funcall *original-bracket-macro-reader*
(make-concatenated-stream
(make-string-input-stream "weblocks-cms::print-tag ")
stream)
char)
(funcall *original-bracket-macro-reader* stream char))))
#-YACLML-SYNTAX-IMPROVEMENT
(set-macro-character #\( #'debug-dispatch)
#-YACLML-SYNTAX-IMPROVEMENT
(push :yaclml-syntax-improvement *features*)