mirror of
https://github.com/python/cpython.git
synced 2025-11-03 11:23:31 +00:00
Completely ignore lines with only a newline token on them, except
wholly empty lines interactively.
This commit is contained in:
parent
8dcbbac15a
commit
8c11a5c759
1 changed files with 47 additions and 25 deletions
|
|
@ -124,7 +124,7 @@ tok_setups(str)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Set up tokenizer for string */
|
/* Set up tokenizer for file */
|
||||||
|
|
||||||
struct tok_state *
|
struct tok_state *
|
||||||
tok_setupf(fp, ps1, ps2)
|
tok_setupf(fp, ps1, ps2)
|
||||||
|
|
@ -309,6 +309,10 @@ tok_get(tok, p_start, p_end)
|
||||||
char **p_start, **p_end; /* Out: point to start/end of token */
|
char **p_start, **p_end; /* Out: point to start/end of token */
|
||||||
{
|
{
|
||||||
register int c;
|
register int c;
|
||||||
|
int blankline;
|
||||||
|
|
||||||
|
nextline:
|
||||||
|
blankline = 0;
|
||||||
|
|
||||||
/* Get indentation level */
|
/* Get indentation level */
|
||||||
if (tok->atbol) {
|
if (tok->atbol) {
|
||||||
|
|
@ -325,6 +329,20 @@ tok_get(tok, p_start, p_end)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
tok_backup(tok, c);
|
tok_backup(tok, c);
|
||||||
|
if (c == '#' || c == '\n') {
|
||||||
|
/* Lines with only whitespace and/or comments
|
||||||
|
shouldn't affect the indentation and are
|
||||||
|
not passed to the parser as NEWLINE tokens,
|
||||||
|
except *totally* empty lines in interactive
|
||||||
|
mode, which signal the end of a command group. */
|
||||||
|
if (col == 0 && c == '\n' && tok->prompt != NULL)
|
||||||
|
blankline = 0; /* Let it through */
|
||||||
|
else
|
||||||
|
blankline = 1; /* Ignore completely */
|
||||||
|
/* We can't jump back right here since we still
|
||||||
|
may need to skip to the end of a comment */
|
||||||
|
}
|
||||||
|
if (!blankline) {
|
||||||
if (col == tok->indstack[tok->indent]) {
|
if (col == tok->indstack[tok->indent]) {
|
||||||
/* No change */
|
/* No change */
|
||||||
}
|
}
|
||||||
|
|
@ -352,6 +370,7 @@ tok_get(tok, p_start, p_end)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
*p_start = *p_end = tok->cur;
|
*p_start = *p_end = tok->cur;
|
||||||
|
|
||||||
|
|
@ -380,13 +399,14 @@ tok_get(tok, p_start, p_end)
|
||||||
if (c == '#') {
|
if (c == '#') {
|
||||||
/* Hack to allow overriding the tabsize in the file.
|
/* Hack to allow overriding the tabsize in the file.
|
||||||
This is also recognized by vi, when it occurs near the
|
This is also recognized by vi, when it occurs near the
|
||||||
beginning or end of the file. (Will vi never die...?) */
|
beginning or end of the file. (Will vi never die...?)
|
||||||
|
For Python it must be at the beginning of the file! */
|
||||||
int x;
|
int x;
|
||||||
/* XXX The case to (unsigned char *) is needed by THINK C 3.0 */
|
/* XXX The case to (unsigned char *) is needed by THINK C 3.0 */
|
||||||
if (sscanf(/*(unsigned char *)*/tok->cur,
|
if (sscanf(/*(unsigned char *)*/tok->cur,
|
||||||
" vi:set tabsize=%d:", &x) == 1 &&
|
" vi:set tabsize=%d:", &x) == 1 &&
|
||||||
x >= 1 && x <= 40) {
|
x >= 1 && x <= 40) {
|
||||||
fprintf(stderr, "# vi:set tabsize=%d:\n", x);
|
/* fprintf(stderr, "# vi:set tabsize=%d:\n", x); */
|
||||||
tok->tabsize = x;
|
tok->tabsize = x;
|
||||||
}
|
}
|
||||||
do {
|
do {
|
||||||
|
|
@ -411,6 +431,8 @@ tok_get(tok, p_start, p_end)
|
||||||
/* Newline */
|
/* Newline */
|
||||||
if (c == '\n') {
|
if (c == '\n') {
|
||||||
tok->atbol = 1;
|
tok->atbol = 1;
|
||||||
|
if (blankline)
|
||||||
|
goto nextline;
|
||||||
*p_end = tok->cur - 1; /* Leave '\n' out of the string */
|
*p_end = tok->cur - 1; /* Leave '\n' out of the string */
|
||||||
return NEWLINE;
|
return NEWLINE;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue