From ce24f67224686277546f8c7dfd8d5dbabc69a103 Mon Sep 17 00:00:00 2001 From: Alex Shinn Date: Mon, 5 May 2014 14:24:52 +0900 Subject: [PATCH] Making #! a line comment only if followed by whitespace or /, otherwise we report a bad symbol for anything other than (no-)fold-case. --- lib/srfi/38.scm | 25 +++++++++++++++---------- sexp.c | 31 ++++++++++++++++++------------- 2 files changed, 33 insertions(+), 23 deletions(-) diff --git a/lib/srfi/38.scm b/lib/srfi/38.scm index bbbb18ad..2b362129 100644 --- a/lib/srfi/38.scm +++ b/lib/srfi/38.scm @@ -287,17 +287,22 @@ (skip-comment in 0) (read-one)) ((#\!) - (let ((name (read-name #f in))) + (read-char in) + (let ((c (peek-char in))) (cond - ((string-ci=? name "!fold-case") - (set-port-fold-case! in #t)) - ((string-ci=? name "!no-fold-case") - (set-port-fold-case! in #f)) - (else ;; assume a #!/bin/bash line - (skip-line in))) - (let ((res (read-one))) - (if (not (eof-object? res)) - res)))) + ((or (char-whitespace? c) (eqv? c #\/)) + (skip-line in) + (read-one)) + (else + (let ((name (read-name #f in))) + (cond + ((string-ci=? name "fold-case") + (set-port-fold-case! in #t)) + ((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))) ((#\') (read-char in) (list 'syntax (read-one))) ((#\`) (read-char in) (list 'quasisyntax (read-one))) diff --git a/sexp.c b/sexp.c index 88337d13..30e84d06 100644 --- a/sexp.c +++ b/sexp.c @@ -2891,24 +2891,29 @@ sexp sexp_read_raw (sexp ctx, sexp in) { goto scan_loop; break; case '!': -#if SEXP_USE_FOLD_CASE_SYMS - res = sexp_read_symbol(ctx, in, '!', 0); - 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 + c1 = sexp_read_char(ctx, in); + if (isspace(c1) || c1 == '/') { while ((c1 = sexp_read_char(ctx, in)) != EOF) if (c1 == '\n') break; 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 - goto scan_loop; + if (!sexp_exceptionp(res)) + goto scan_loop; + break; case '\\': c1 = sexp_read_char(ctx, in); c2 = sexp_read_char(ctx, in);