mirror of
https://github.com/ashinn/chibi-scheme.git
synced 2025-05-19 13:49:17 +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)
|
(skip-comment in 0)
|
||||||
(read-one))
|
(read-one))
|
||||||
((#\!)
|
((#\!)
|
||||||
|
(read-char in)
|
||||||
|
(let ((c (peek-char in)))
|
||||||
|
(cond
|
||||||
|
((or (char-whitespace? c) (eqv? c #\/))
|
||||||
|
(skip-line in)
|
||||||
|
(read-one))
|
||||||
|
(else
|
||||||
(let ((name (read-name #f in)))
|
(let ((name (read-name #f in)))
|
||||||
(cond
|
(cond
|
||||||
((string-ci=? name "!fold-case")
|
((string-ci=? name "fold-case")
|
||||||
(set-port-fold-case! in #t))
|
(set-port-fold-case! in #t))
|
||||||
((string-ci=? name "!no-fold-case")
|
((string-ci=? name "no-fold-case")
|
||||||
(set-port-fold-case! in #f))
|
(set-port-fold-case! in #f))
|
||||||
(else ;; assume a #!/bin/bash line
|
(else ;; assume a #!/bin/bash line
|
||||||
(skip-line in)))
|
(error "unknown #! symbol" name)))
|
||||||
(let ((res (read-one)))
|
(read-one))))))
|
||||||
(if (not (eof-object? res))
|
|
||||||
res))))
|
|
||||||
((#\() (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)))
|
||||||
|
|
29
sexp.c
29
sexp.c
|
@ -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);
|
||||||
|
|
Loading…
Add table
Reference in a new issue