mirror of
https://github.com/ashinn/chibi-scheme.git
synced 2025-05-19 05:39:18 +02:00
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:
parent
95bc62b45e
commit
ce24f67224
2 changed files with 33 additions and 23 deletions
|
@ -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)))
|
||||
|
|
31
sexp.c
31
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);
|
||||
|
|
Loading…
Add table
Reference in a new issue