Making #! a line comment only if followed by whitespace or /,

otherwise we report a bad symbol for anything other than (no-)fold-case.
This commit is contained in:
Alex Shinn 2014-05-05 14:24:52 +09:00
parent 95bc62b45e
commit ce24f67224
2 changed files with 33 additions and 23 deletions

View file

@ -287,17 +287,22 @@
(skip-comment in 0) (skip-comment in 0)
(read-one)) (read-one))
((#\!) ((#\!)
(let ((name (read-name #f in))) (read-char in)
(let ((c (peek-char in)))
(cond (cond
((string-ci=? name "!fold-case") ((or (char-whitespace? c) (eqv? c #\/))
(set-port-fold-case! in #t)) (skip-line in)
((string-ci=? name "!no-fold-case") (read-one))
(set-port-fold-case! in #f)) (else
(else ;; assume a #!/bin/bash line (let ((name (read-name #f in)))
(skip-line in))) (cond
(let ((res (read-one))) ((string-ci=? name "fold-case")
(if (not (eof-object? res)) (set-port-fold-case! in #t))
res)))) ((string-ci=? name "no-fold-case")
(set-port-fold-case! in #f))
(else ;; assume a #!/bin/bash line
(error "unknown #! symbol" name)))
(read-one))))))
((#\() (list->vector (read-one))) ((#\() (list->vector (read-one)))
((#\') (read-char in) (list 'syntax (read-one))) ((#\') (read-char in) (list 'syntax (read-one)))
((#\`) (read-char in) (list 'quasisyntax (read-one))) ((#\`) (read-char in) (list 'quasisyntax (read-one)))

31
sexp.c
View file

@ -2891,24 +2891,29 @@ sexp sexp_read_raw (sexp ctx, sexp in) {
goto scan_loop; goto scan_loop;
break; break;
case '!': case '!':
#if SEXP_USE_FOLD_CASE_SYMS c1 = sexp_read_char(ctx, in);
res = sexp_read_symbol(ctx, in, '!', 0); if (isspace(c1) || c1 == '/') {
if (sexp_stringp(res)
&& strcmp("!fold-case", sexp_string_data(res)) == 0) {
sexp_port_fold_casep(in) = 1;
} else if (sexp_stringp(res)
&& strcmp("!no-fold-case", sexp_string_data(res)) == 0) {
sexp_port_fold_casep(in) = 0;
} else {
#endif
while ((c1 = sexp_read_char(ctx, in)) != EOF) while ((c1 = sexp_read_char(ctx, in)) != EOF)
if (c1 == '\n') if (c1 == '\n')
break; break;
sexp_port_line(in)++; sexp_port_line(in)++;
#if SEXP_USE_FOLD_CASE_SYMS res = SEXP_VOID;
} else {
sexp_push_char(ctx, c1, in);
res = sexp_read_symbol(ctx, in, '!', 0);
if (SEXP_USE_FOLD_CASE_SYMS && sexp_stringp(res)
&& strcmp("!fold-case", sexp_string_data(res)) == 0) {
sexp_port_fold_casep(in) = 1;
} else if (SEXP_USE_FOLD_CASE_SYMS && sexp_stringp(res)
&& strcmp("!no-fold-case", sexp_string_data(res)) == 0) {
sexp_port_fold_casep(in) = 0;
} else {
res = sexp_read_error(ctx, "unknown #! symbol", res, in);
}
} }
#endif if (!sexp_exceptionp(res))
goto scan_loop; goto scan_loop;
break;
case '\\': case '\\':
c1 = sexp_read_char(ctx, in); c1 = sexp_read_char(ctx, in);
c2 = sexp_read_char(ctx, in); c2 = sexp_read_char(ctx, in);