nendo 0.2.0 → 0.3.0
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.
- data/bin/nendo +37 -2
- data/example/cgi/dekamoji.cgi +100 -0
- data/example/cgi/sample.cgi +32 -0
- data/{sample → example}/exit.nnd +0 -0
- data/{sample → example}/fact.nnd +2 -2
- data/{sample → example}/fizzbuzz1.nnd +2 -2
- data/example/html-lite-sample.nnd +51 -0
- data/{sample → example}/scratch.nnd +1 -5
- data/{sample → example}/tak.nnd +0 -0
- data/lib/init.nnd +171 -30
- data/lib/init.nndc +3736 -2009
- data/lib/nendo.rb +322 -127
- data/lib/text/html-lite.nnd +231 -0
- data/lib/text/html-lite.nndc +2652 -0
- data/lib/text/tree.nnd +23 -0
- data/lib/text/tree.nndc +215 -0
- metadata +14 -7
@@ -0,0 +1,231 @@
|
|
1
|
+
;;;
|
2
|
+
;;; html-lite.scm - lightweight HTML construction
|
3
|
+
;;;
|
4
|
+
;;; Copyright (c) 2000-2009 Shiro Kawai <shiro@acm.org>
|
5
|
+
;;;
|
6
|
+
;;; Redistribution and use in source and binary forms, with or without
|
7
|
+
;;; modification, are permitted provided that the following conditions
|
8
|
+
;;; are met:
|
9
|
+
;;;
|
10
|
+
;;; 1. Redistributions of source code must retain the above copyright
|
11
|
+
;;; notice, this list of conditions and the following disclaimer.
|
12
|
+
;;;
|
13
|
+
;;; 2. Redistributions in binary form must reproduce the above copyright
|
14
|
+
;;; notice, this list of conditions and the following disclaimer in the
|
15
|
+
;;; documentation and/or other materials provided with the distribution.
|
16
|
+
;;;
|
17
|
+
;;; 3. Neither the name of the authors nor the names of its contributors
|
18
|
+
;;; may be used to endorse or promote products derived from this
|
19
|
+
;;; software without specific prior written permission.
|
20
|
+
;;;
|
21
|
+
;;; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
22
|
+
;;; "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
23
|
+
;;; LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
24
|
+
;;; A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
25
|
+
;;; OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
26
|
+
;;; SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
|
27
|
+
;;; TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
28
|
+
;;; PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
29
|
+
;;; LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
30
|
+
;;; NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
31
|
+
;;; SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
32
|
+
;;;
|
33
|
+
;;; $Id: html-lite.scm,v 1.19 2008-05-10 13:36:11 shirok Exp $
|
34
|
+
;;;
|
35
|
+
;;;
|
36
|
+
;;; ported for Nendo language by Kiyoka Nishiyama.
|
37
|
+
|
38
|
+
;; Escaping ---------------------------------------------
|
39
|
+
(define (html-escape c)
|
40
|
+
(case c
|
41
|
+
(("<") "<")
|
42
|
+
((">") ">")
|
43
|
+
(("&") "&")
|
44
|
+
(("\"") """)
|
45
|
+
(else c)))
|
46
|
+
|
47
|
+
(define (html-escape-string string)
|
48
|
+
(string-join
|
49
|
+
(map
|
50
|
+
html-escape
|
51
|
+
(to-list (string.split "")))
|
52
|
+
""))
|
53
|
+
|
54
|
+
;;(html-escape-string "<html> & \"abc\"")
|
55
|
+
|
56
|
+
|
57
|
+
;; Doctype ----------------------------------------------
|
58
|
+
|
59
|
+
;; Doctype database
|
60
|
+
;; (type ...) => (xml? doctype)
|
61
|
+
(define *doctype-alist*
|
62
|
+
'(((:strict :html :html-strict :html-4.01 :html-4.01-strict)
|
63
|
+
#f
|
64
|
+
"<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\"
|
65
|
+
\"http://www.w3.org/TR/html4/strict.dtd\">\n")
|
66
|
+
((:transitional :html-transitional :html-4.01-transitional)
|
67
|
+
#f
|
68
|
+
"<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"
|
69
|
+
\"http://www.w3.org/TR/html4/loose.dtd\">\n")
|
70
|
+
((:frameset :html-frameset :html-4.01-frameset)
|
71
|
+
#f
|
72
|
+
"<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Frameset//EN\"
|
73
|
+
\"http://www.w3.org/TR/html4/frameset.dtd\">\n")
|
74
|
+
((:xhtml-1.0-strict :xhtml-1.0)
|
75
|
+
#t
|
76
|
+
"<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"
|
77
|
+
\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n")
|
78
|
+
((:xhtml-1.0-transitional)
|
79
|
+
#t
|
80
|
+
"<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\"
|
81
|
+
\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n")
|
82
|
+
((:xhtml-1.0-frameset)
|
83
|
+
#t
|
84
|
+
"<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Frameset//EN\"
|
85
|
+
\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd\">\n")
|
86
|
+
((:xhtml-1.1)
|
87
|
+
#t
|
88
|
+
"<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.1//EN\"
|
89
|
+
\"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd\">\n")
|
90
|
+
))
|
91
|
+
|
92
|
+
(define (html-doctype . type)
|
93
|
+
(let1 type (if (null? type)
|
94
|
+
:html-4.01-strict
|
95
|
+
type)
|
96
|
+
(cond ((find (lambda (e) (memq type (car e))) *doctype-alist*)
|
97
|
+
=> caddr )
|
98
|
+
(else (error "Unknown doctype type spec" type)))))
|
99
|
+
|
100
|
+
;; Elements ------------------------------------------------
|
101
|
+
|
102
|
+
(define (make-html-element name . args)
|
103
|
+
(define (get-attr args attrs)
|
104
|
+
(cond ((null? args) (values (reverse attrs) args))
|
105
|
+
((keyword? (car args))
|
106
|
+
(cond ((null? (cdr args))
|
107
|
+
(values (reverse (list* (car args) " " attrs)) args))
|
108
|
+
((eq? (cadr args) #f)
|
109
|
+
(get-attr (cddr args) attrs))
|
110
|
+
((eq? (cadr args) #t)
|
111
|
+
(get-attr (cddr args) (list* (car args) " " attrs)))
|
112
|
+
(else
|
113
|
+
(get-attr (cddr args)
|
114
|
+
(list* (sprintf "=\"%s\""
|
115
|
+
(html-escape-string (x->string (cadr args))))
|
116
|
+
(car args)
|
117
|
+
" "
|
118
|
+
attrs)))))
|
119
|
+
(else (values (reverse attrs) args))))
|
120
|
+
|
121
|
+
(let ((empty? (get-keyword :empty? args #f)))
|
122
|
+
(if empty?
|
123
|
+
(lambda args
|
124
|
+
(receive (attr args) (get-attr args '())
|
125
|
+
(unless (null? args)
|
126
|
+
(errorf "element %s can't have content: %s" name (write-to-string args)))
|
127
|
+
(list "<" name attr " />")))
|
128
|
+
(lambda args
|
129
|
+
(receive (attr args) (get-attr args '())
|
130
|
+
(list "<" name attr ">" args "</" name "\n>"))))))
|
131
|
+
|
132
|
+
|
133
|
+
(define define-html-elements
|
134
|
+
(macro elements
|
135
|
+
(letrec ((make-scheme-name
|
136
|
+
(lambda (name)
|
137
|
+
(string->symbol (sprintf "html:%s" name)))))
|
138
|
+
|
139
|
+
(let loop ((elements elements)
|
140
|
+
(r '()))
|
141
|
+
(cond ((null? elements) `(begin ,@(reverse r)))
|
142
|
+
((and (pair? (cdr elements)) (eqv? (cadr elements) :empty))
|
143
|
+
(loop (cddr elements)
|
144
|
+
(list* `(define ,(make-scheme-name (car elements))
|
145
|
+
(make-html-element ',(car elements) :empty? #t))
|
146
|
+
`(export ,(make-scheme-name (car elements)))
|
147
|
+
r)))
|
148
|
+
(else
|
149
|
+
(loop (cdr elements)
|
150
|
+
(list* `(define ,(make-scheme-name (car elements))
|
151
|
+
(make-html-element ',(car elements)))
|
152
|
+
`(export ,(make-scheme-name (car elements)))
|
153
|
+
r))))
|
154
|
+
))))
|
155
|
+
|
156
|
+
|
157
|
+
;; http://www.w3.org/TR/html4/sgml/dtd.html
|
158
|
+
|
159
|
+
;; TEXT MARKUP
|
160
|
+
|
161
|
+
;; %fontstyle
|
162
|
+
(define-html-elements tt i b big small)
|
163
|
+
|
164
|
+
;; %phrase
|
165
|
+
(define-html-elements em strong dfn code samp kbd var cite abbr acronym)
|
166
|
+
|
167
|
+
(define-html-elements sub sup span bdo br :empty)
|
168
|
+
|
169
|
+
;; HTML CONTENT MODELS
|
170
|
+
|
171
|
+
;; DOCUMENT BODY
|
172
|
+
|
173
|
+
(define-html-elements body address div)
|
174
|
+
|
175
|
+
;; THE ANCHOR ELEMENT
|
176
|
+
(define-html-elements a)
|
177
|
+
|
178
|
+
;; cLIENT-SIDE IMAGE MAPS
|
179
|
+
(define-html-elements map area :empty)
|
180
|
+
|
181
|
+
;; THE LINK EKEMENT
|
182
|
+
(define-html-elements link :empty)
|
183
|
+
|
184
|
+
;; IMAGES
|
185
|
+
(define-html-elements img :empty)
|
186
|
+
|
187
|
+
;; OBJECT
|
188
|
+
(define-html-elements object param :empty)
|
189
|
+
|
190
|
+
;; HORIZONTAL RULE
|
191
|
+
(define-html-elements hr :empty)
|
192
|
+
|
193
|
+
;; PARAGRAPHS
|
194
|
+
(define-html-elements p)
|
195
|
+
|
196
|
+
;; HEADINGS
|
197
|
+
(define-html-elements h1 h2 h3 h4 h5 h6)
|
198
|
+
|
199
|
+
;; PREFORMATTED
|
200
|
+
(define-html-elements pre)
|
201
|
+
|
202
|
+
;; INLINE QUOTES
|
203
|
+
(define-html-elements q)
|
204
|
+
|
205
|
+
;; BLOCK-LIKE QUOTES
|
206
|
+
(define-html-elements blockquote)
|
207
|
+
|
208
|
+
;; INSERTED/DELETED TEXT
|
209
|
+
(define-html-elements ins del)
|
210
|
+
|
211
|
+
;; LISTS
|
212
|
+
(define-html-elements dl dt dd ol ul li)
|
213
|
+
|
214
|
+
;; FORMS
|
215
|
+
(define-html-elements form label input :empty select optgroup option
|
216
|
+
textarea fieldset legend button)
|
217
|
+
|
218
|
+
;; TABLES
|
219
|
+
(define-html-elements table caption thead tfoot tbody colgroup
|
220
|
+
col :empty tr th td)
|
221
|
+
|
222
|
+
;; DOCUMENT HEAD
|
223
|
+
(define-html-elements head title base :empty meta :empty
|
224
|
+
style script noscript)
|
225
|
+
|
226
|
+
;; DOCUMENT STRUCTURE
|
227
|
+
(define-html-elements html)
|
228
|
+
|
229
|
+
;; FRAMES
|
230
|
+
(define-html-elements frameset frame noframes iframe)
|
231
|
+
|