WebGate

Check-in [01fdd8217d]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Use letrec* in make-at-reader+table to ensure correct sequencing of operations
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 01fdd8217d8a84921ea8130ad7e53f9c8b7d69af
User & Date: murphy 2015-05-04 08:03:04.991
Context
2015-05-04
09:15
Moved suspension module into separate compilation unit, isolating disabled interrupts check-in: 72a7ba057e user: murphy tags: trunk
08:03
Use letrec* in make-at-reader+table to ensure correct sequencing of operations check-in: 01fdd8217d user: murphy tags: trunk
2013-11-24
22:17
Optional direct HTTP support using soup check-in: 11d7807ffd user: murphy tags: trunk
Changes
Unified Diff Ignore Whitespace Patch
Changes to webgate-utils.scm.
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
	 'read-netstring
	 "client side protocol error: malformed netstring (bad terminal)"))
      s)))

;;; @-expressions

(define (make-at-reader+table args)
  (letrec ((command-char
	    (get-keyword #:command-char args (constantly #\@)))
	   (trim-whitespace?
	    (get-keyword #:trim-whitespace? args (constantly #t)))
	   (condense-whitespace?
	    (get-keyword #:condense-whitespace? args (constantly #t)))
	   (list-arguments?
	    (get-keyword #:list-arguments? args (constantly #f)))
	   (char-normal?
	    (cute char-set-contains?
		  (char-set-complement
		   (char-set command-char #\{ #\} #\return #\newline))
		  <>))
	   (char-group?
	    (cute char-set-contains?
		  (char-set #\[ #\{)
		  <>))
	   (skip-whitespace
	    (lambda (port)
	      (when (char-whitespace? (peek-char port))
		(read-char port)
		(skip-whitespace port))))
	   (read-whitespace
	    (if condense-whitespace?
		(lambda (port)
		  (skip-whitespace port)
		  " ")
		(cut read-token char-whitespace? <>)))
	   (read-datum
	    (lambda (port)
	      (parameterize ((current-read-table datum-read-table))
		(read port))))
	   (read-at-exp
	    (lambda (port)
	      (skip-whitespace port)
	      (let ((char (peek-char port)))
		(cond
		 ((eof-object? char)
		  (read-char port))
		 (else
		  (when (eqv? char command-char)
		    (read-char port))
		  (let* ((head (and (not (char-group? (peek-char port)))
				    (read-datum port)))
			 (args (and (eqv? (peek-char port) #\[)
				    (read-datum port)))
			 (body (and (eqv? (peek-char port) #\{)
				    (read-inside-at-exp 'skip port))))
		    (if (or args body)
			(append!
			 (cond
			  (head => list)
			  (else '()))
			 (cond
			  ((and list-arguments? args) => list)
			  (else (or args '())))
			 (or body '()))
			head)))))))
	   (read-inside-at-exp
	    (lambda (brace-mode port)
	      (append!
	       (let ((head
		      (case brace-mode
			((none)
			 '())
			((skip)
			 (and (eqv? (peek-char port) #\{)
			      (begin (read-char port) '())))
			(else
			 (and (eqv? (peek-char port) #\{)
			      (list (string (read-char port))))))))
		 (if head
		     (begin
		       (when trim-whitespace? (skip-whitespace port))
		       head)
		     (syntax-error
		      'read-inside-at-exp "expected @-expression body, found"
		      (peek-char port))))
	       (let more ()
		 (let ((char (peek-char port)))
		   (cond
		    ((eqv? char #\{)
		     (case brace-mode
		       ((none)
			(cons (string (read-char port)) (more)))
		       (else
			(append! (read-inside-at-exp 'keep port) (more)))))
		    ((eqv? char #\})
		     (case brace-mode
		       ((none)
			(cons (string (read-char port)) (more)))
		       ((skip)
			(read-char port)
			'())
		       (else
			(list (string (read-char port))))))
		    ((eof-object? char)
		     (case brace-mode
		       ((none)
			(read-char port)
			'())
		       (else
			(syntax-error
			 'read-inside-at-exp "@-expression body not closed"))))
		    ((eqv? char command-char)
		     (cons (read-at-exp port) (more)))
		    ((char-whitespace? char)
		     (let* ((head (read-whitespace port))
			    (tail (more)))
		       (if (or (pair? tail) (not trim-whitespace?))
			   (cons head tail)
			   tail)))
		    (else
		     (cons (read-token char-normal? port) (more)))))))))
	   (read-table
	    (get-keyword #:read-table args current-read-table))
	   (at-read-table
	    (parameterize ((current-read-table (copy-read-table read-table)))
	      (set-read-syntax! command-char read-at-exp)
	      (current-read-table)))
	   (datum-read-table
	    (let ((spec (get-keyword #:datum-read-table args (constantly #t))))
	      (cond
	       ((procedure? spec)
		(spec at-read-table))
	       (spec
		at-read-table)
	       (else
		read-table)))))
    (values
     (if (get-keyword #:inside? args)
	 (lambda (#!optional (port (current-input-port)))
	   (read-inside-at-exp 'none port))
	 (lambda (#!optional (port (current-input-port)))
	   (read-at-exp port)))
     at-read-table)))







|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|







44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
	 'read-netstring
	 "client side protocol error: malformed netstring (bad terminal)"))
      s)))

;;; @-expressions

(define (make-at-reader+table args)
  (letrec* ((command-char
	     (get-keyword #:command-char args (constantly #\@)))
	    (trim-whitespace?
	     (get-keyword #:trim-whitespace? args (constantly #t)))
	    (condense-whitespace?
	     (get-keyword #:condense-whitespace? args (constantly #t)))
	    (list-arguments?
	     (get-keyword #:list-arguments? args (constantly #f)))
	    (char-normal?
	     (cute char-set-contains?
		   (char-set-complement
		    (char-set command-char #\{ #\} #\return #\newline))
		   <>))
	    (char-group?
	     (cute char-set-contains?
		   (char-set #\[ #\{)
		   <>))
	    (skip-whitespace
	     (lambda (port)
	       (when (char-whitespace? (peek-char port))
		 (read-char port)
		 (skip-whitespace port))))
	    (read-whitespace
	     (if condense-whitespace?
		 (lambda (port)
		   (skip-whitespace port)
		   " ")
		 (cut read-token char-whitespace? <>)))
	    (read-datum
	     (lambda (port)
	       (parameterize ((current-read-table datum-read-table))
		 (read port))))
	    (read-at-exp
	     (lambda (port)
	       (skip-whitespace port)
	       (let ((char (peek-char port)))
		 (cond
		  ((eof-object? char)
		   (read-char port))
		  (else
		   (when (eqv? char command-char)
		     (read-char port))
		   (let* ((head (and (not (char-group? (peek-char port)))
				     (read-datum port)))
			  (args (and (eqv? (peek-char port) #\[)
				     (read-datum port)))
			  (body (and (eqv? (peek-char port) #\{)
				     (read-inside-at-exp 'skip port))))
		     (if (or args body)
			 (append!
			  (cond
			   (head => list)
			   (else '()))
			  (cond
			   ((and list-arguments? args) => list)
			   (else (or args '())))
			  (or body '()))
			 head)))))))
	    (read-inside-at-exp
	     (lambda (brace-mode port)
	       (append!
		(let ((head
		       (case brace-mode
			 ((none)
			  '())
			 ((skip)
			  (and (eqv? (peek-char port) #\{)
			       (begin (read-char port) '())))
			 (else
			  (and (eqv? (peek-char port) #\{)
			       (list (string (read-char port))))))))
		  (if head
		      (begin
			(when trim-whitespace? (skip-whitespace port))
			head)
		      (syntax-error
		       'read-inside-at-exp "expected @-expression body, found"
		       (peek-char port))))
		(let more ()
		  (let ((char (peek-char port)))
		    (cond
		     ((eqv? char #\{)
		      (case brace-mode
			((none)
			 (cons (string (read-char port)) (more)))
			(else
			 (append! (read-inside-at-exp 'keep port) (more)))))
		     ((eqv? char #\})
		      (case brace-mode
			((none)
			 (cons (string (read-char port)) (more)))
			((skip)
			 (read-char port)
			 '())
			(else
			 (list (string (read-char port))))))
		     ((eof-object? char)
		      (case brace-mode
			((none)
			 (read-char port)
			 '())
			(else
			 (syntax-error
			  'read-inside-at-exp "@-expression body not closed"))))
		     ((eqv? char command-char)
		      (cons (read-at-exp port) (more)))
		     ((char-whitespace? char)
		      (let* ((head (read-whitespace port))
			     (tail (more)))
			(if (or (pair? tail) (not trim-whitespace?))
			    (cons head tail)
			    tail)))
		     (else
		      (cons (read-token char-normal? port) (more)))))))))
	    (read-table
	     (get-keyword #:read-table args current-read-table))
	    (at-read-table
	     (parameterize ((current-read-table (copy-read-table read-table)))
	       (set-read-syntax! command-char read-at-exp)
	       (current-read-table)))
	    (datum-read-table
	     (let ((spec (get-keyword #:datum-read-table args (constantly #t))))
	       (cond
		((procedure? spec)
		 (spec at-read-table))
		(spec
		 at-read-table)
		(else
		 read-table)))))
    (values
     (if (get-keyword #:inside? args)
	 (lambda (#!optional (port (current-input-port)))
	   (read-inside-at-exp 'none port))
	 (lambda (#!optional (port (current-input-port)))
	   (read-at-exp port)))
     at-read-table)))