mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-06-12 14:50:19 +02:00
(scm_flush_ws): Detect "#!"-style comments here.
(scm_lreadr): Abort on seeing "#!", which should no longer happen. (skip_scsh_block_comment): Use scm_input_error instead of scm_misc_error in case of EOF.
This commit is contained in:
parent
242a43b5b3
commit
0520c32088
1 changed files with 47 additions and 40 deletions
|
@ -164,7 +164,37 @@ scm_grow_tok_buf (SCM *tok_buf)
|
||||||
return newdata;
|
return newdata;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Consume an SCSH-style block comment. Assume that we've already
|
||||||
|
read the initial `#!', and eat characters until we get a
|
||||||
|
newline/exclamation-point/sharp-sign/newline sequence.
|
||||||
|
|
||||||
|
A carriage return is also reocgnized as a newline. */
|
||||||
|
|
||||||
|
static void
|
||||||
|
skip_scsh_block_comment (SCM port)
|
||||||
|
{
|
||||||
|
int state = 0;
|
||||||
|
|
||||||
|
for (;;)
|
||||||
|
{
|
||||||
|
int c = scm_getc (port);
|
||||||
|
|
||||||
|
if (c == EOF)
|
||||||
|
scm_input_error ("skip_block_comment", port,
|
||||||
|
"unterminated `#! ... !#' comment", SCM_EOL);
|
||||||
|
|
||||||
|
if (state == 1 && c == '!')
|
||||||
|
state = 2;
|
||||||
|
else if (state == 2 && c == '#')
|
||||||
|
state = 3;
|
||||||
|
else if (state == 3 && (c == '\n' || c == '\r'))
|
||||||
|
return;
|
||||||
|
else if (c == '\n' || c == '\r')
|
||||||
|
state = 1;
|
||||||
|
else
|
||||||
|
state = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
scm_flush_ws (SCM port, const char *eoferr)
|
scm_flush_ws (SCM port, const char *eoferr)
|
||||||
|
@ -195,6 +225,20 @@ scm_flush_ws (SCM port, const char *eoferr)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case '#':
|
||||||
|
switch (c = scm_getc (port))
|
||||||
|
{
|
||||||
|
case EOF:
|
||||||
|
eoferr = "read_sharp";
|
||||||
|
goto goteof;
|
||||||
|
case '!':
|
||||||
|
skip_scsh_block_comment (port);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
scm_ungetc (c, port);
|
||||||
|
return '#';
|
||||||
|
}
|
||||||
|
break;
|
||||||
case SCM_LINE_INCREMENTORS:
|
case SCM_LINE_INCREMENTORS:
|
||||||
case SCM_SINGLE_SPACES:
|
case SCM_SINGLE_SPACES:
|
||||||
case '\t':
|
case '\t':
|
||||||
|
@ -284,39 +328,6 @@ recsexpr (SCM obj, long line, int column, SCM filename)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Consume an SCSH-style block comment. Assume that we've already
|
|
||||||
read the initial `#!', and eat characters until we get a
|
|
||||||
newline/exclamation-point/sharp-sign/newline sequence.
|
|
||||||
|
|
||||||
A carriage return is also reocgnized as a newline. */
|
|
||||||
|
|
||||||
static void
|
|
||||||
skip_scsh_block_comment (SCM port)
|
|
||||||
#define FUNC_NAME "skip_scsh_block_comment"
|
|
||||||
{
|
|
||||||
int state = 0;
|
|
||||||
|
|
||||||
for (;;)
|
|
||||||
{
|
|
||||||
int c = scm_getc (port);
|
|
||||||
|
|
||||||
if (c == EOF)
|
|
||||||
SCM_MISC_ERROR ("unterminated `#! ... !#' comment", SCM_EOL);
|
|
||||||
|
|
||||||
if (state == 1 && c == '!')
|
|
||||||
state = 2;
|
|
||||||
else if (state == 2 && c == '#')
|
|
||||||
state = 3;
|
|
||||||
else if (state == 3 && (c == '\n' || c == '\r'))
|
|
||||||
return;
|
|
||||||
else if (c == '\n' || c == '\r')
|
|
||||||
state = 1;
|
|
||||||
else
|
|
||||||
state = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#undef FUNC_NAME
|
|
||||||
|
|
||||||
|
|
||||||
static SCM scm_get_hash_procedure(int c);
|
static SCM scm_get_hash_procedure(int c);
|
||||||
static SCM scm_i_lreadparen (SCM *, SCM, char *, SCM *, char);
|
static SCM scm_i_lreadparen (SCM *, SCM, char *, SCM *, char);
|
||||||
|
@ -334,7 +345,6 @@ scm_lreadr (SCM *tok_buf, SCM port, SCM *copy)
|
||||||
|
|
||||||
tryagain:
|
tryagain:
|
||||||
c = scm_flush_ws (port, s_scm_read);
|
c = scm_flush_ws (port, s_scm_read);
|
||||||
tryagain_no_flush_ws:
|
|
||||||
switch (c)
|
switch (c)
|
||||||
{
|
{
|
||||||
case EOF:
|
case EOF:
|
||||||
|
@ -443,12 +453,9 @@ scm_lreadr (SCM *tok_buf, SCM port, SCM *copy)
|
||||||
goto num;
|
goto num;
|
||||||
|
|
||||||
case '!':
|
case '!':
|
||||||
/* start of a shell script. Parse as a block comment,
|
/* should never happen, #!...!# block comments are skipped
|
||||||
terminated by !#, just like SCSH. */
|
over in scm_flush_ws. */
|
||||||
skip_scsh_block_comment (port);
|
abort ();
|
||||||
/* EOF is not an error here */
|
|
||||||
c = scm_flush_ws (port, (char *)NULL);
|
|
||||||
goto tryagain_no_flush_ws;
|
|
||||||
|
|
||||||
#if SCM_HAVE_ARRAYS
|
#if SCM_HAVE_ARRAYS
|
||||||
case '*':
|
case '*':
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue