mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-05-20 11:40:18 +02:00
fix reading of #||||#
* libguile/read.c (scm_read_r6rs_block_comment): * test-suite/tests/reader.test ("reading"): Fix reading of #||||#, originally reported in bug debbugs.gnu.org/9672, by Bruno Haible. Thanks, Bruno!
This commit is contained in:
parent
21524430e9
commit
6d5f8c324e
2 changed files with 28 additions and 21 deletions
|
@ -1133,34 +1133,33 @@ scm_read_r6rs_block_comment (scm_t_wchar chr, SCM port)
|
|||
/* Unlike SCSH-style block comments, SRFI-30/R6RS block comments may be
|
||||
nested. So care must be taken. */
|
||||
int nesting_level = 1;
|
||||
int opening_seen = 0, closing_seen = 0;
|
||||
|
||||
int a = scm_getc (port);
|
||||
|
||||
if (a == EOF)
|
||||
scm_i_input_error ("scm_read_r6rs_block_comment", port,
|
||||
"unterminated `#| ... |#' comment", SCM_EOL);
|
||||
|
||||
while (nesting_level > 0)
|
||||
{
|
||||
int c = scm_getc (port);
|
||||
int b = scm_getc (port);
|
||||
|
||||
if (c == EOF)
|
||||
if (b == EOF)
|
||||
scm_i_input_error ("scm_read_r6rs_block_comment", port,
|
||||
"unterminated `#| ... |#' comment", SCM_EOL);
|
||||
|
||||
if (opening_seen)
|
||||
{
|
||||
if (c == '|')
|
||||
nesting_level++;
|
||||
opening_seen = 0;
|
||||
}
|
||||
else if (closing_seen)
|
||||
{
|
||||
if (c == '#')
|
||||
nesting_level--;
|
||||
closing_seen = 0;
|
||||
}
|
||||
else if (c == '|')
|
||||
closing_seen = 1;
|
||||
else if (c == '#')
|
||||
opening_seen = 1;
|
||||
else
|
||||
opening_seen = closing_seen = 0;
|
||||
if (a == '|' && b == '#')
|
||||
{
|
||||
nesting_level--;
|
||||
b = EOF;
|
||||
}
|
||||
else if (a == '#' && b == '|')
|
||||
{
|
||||
nesting_level++;
|
||||
b = EOF;
|
||||
}
|
||||
|
||||
a = b;
|
||||
}
|
||||
|
||||
return SCM_UNSPECIFIED;
|
||||
|
|
|
@ -110,6 +110,14 @@
|
|||
(equal? '(a b c)
|
||||
(read-string "(a b c #| d #| e |# f |#)")))
|
||||
|
||||
(pass-if "R6RS/SRFI-30 nested block comment (2)"
|
||||
(equal? '(a b c)
|
||||
(read-string "(a b c #|||||||#)")))
|
||||
|
||||
(pass-if "R6RS/SRFI-30 nested block comment (3)"
|
||||
(equal? '(a b c)
|
||||
(read-string "(a b c #||||||||#)")))
|
||||
|
||||
(pass-if "R6RS/SRFI-30 block comment syntax overridden"
|
||||
;; To be compatible with 1.8 and earlier, we should be able to override
|
||||
;; this syntax.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue