|
311 | 311 | (define (numchk n s) |
312 | 312 | (or n (error (string "invalid numeric constant \"" s "\"")))) |
313 | 313 |
|
| 314 | +(define (string-lastchar s) |
| 315 | + (string.char s (string.dec s (length s)))) |
| 316 | + |
314 | 317 | (define (read-number port leadingdot neg) |
315 | 318 | (let ((str (open-output-string)) |
316 | 319 | (pred char-numeric?) |
|
412 | 415 | (string.sub s 1) |
413 | 416 | s) |
414 | 417 | r is-float32-literal))) |
415 | | - (if (and (eqv? #\. (string.char s (string.dec s (length s)))) |
| 418 | + (if (and (eqv? #\. (string-lastchar s)) |
416 | 419 | (let ((nxt (peek-char port))) |
417 | 420 | (and (not (eof-object? nxt)) |
418 | 421 | (or (identifier-start-char? nxt) |
|
2182 | 2185 | (define (unescape-parsed-string-literal strs) |
2183 | 2186 | (map-at even? unescape-string strs)) |
2184 | 2187 |
|
| 2188 | +;; remove `\` followed by a newline |
| 2189 | +(define (strip-escaped-newline s) |
| 2190 | + (let ((in (open-input-string s)) |
| 2191 | + (out (open-output-string))) |
| 2192 | + (define (loop preceding-backslash?) |
| 2193 | + (let ((c (read-char in))) |
| 2194 | + (cond ((eof-object? c)) |
| 2195 | + (preceding-backslash? |
| 2196 | + (if (not (eqv? c #\newline)) |
| 2197 | + (begin (write-char #\\ out) (write-char c out))) |
| 2198 | + (loop #f)) |
| 2199 | + ((eqv? c #\\) (loop #t)) |
| 2200 | + (else (write-char c out) (loop #f))))) |
| 2201 | + (loop #f) |
| 2202 | + (io.tostring! out))) |
| 2203 | + |
2185 | 2204 | (define (parse-string-literal s delim raw) |
2186 | | - (let ((p (ts:port s))) |
2187 | | - ((if raw identity unescape-parsed-string-literal) |
2188 | | - (if (eqv? (peek-char p) delim) |
2189 | | - (if (eqv? (peek-char (take-char p)) delim) |
2190 | | - (map-first strip-leading-newline |
2191 | | - (dedent-triplequoted-string |
2192 | | - (parse-string-literal- 2 (take-char p) s delim raw))) |
2193 | | - (list "")) |
2194 | | - (parse-string-literal- 0 p s delim raw))))) |
| 2205 | + (let* ((p (ts:port s)) |
| 2206 | + (str (if (eqv? (peek-char p) delim) |
| 2207 | + (if (eqv? (peek-char (take-char p)) delim) |
| 2208 | + (map-first strip-leading-newline |
| 2209 | + (dedent-triplequoted-string |
| 2210 | + (parse-string-literal- 2 (take-char p) s delim raw))) |
| 2211 | + (list "")) |
| 2212 | + (parse-string-literal- 0 p s delim raw)))) |
| 2213 | + (if raw str (unescape-parsed-string-literal |
| 2214 | + (map (lambda (s) |
| 2215 | + (if (string? s) (strip-escaped-newline s) s)) |
| 2216 | + str))))) |
2195 | 2217 |
|
2196 | 2218 | (define (strip-leading-newline s) |
2197 | 2219 | (let ((n (sizeof s))) |
|
0 commit comments