input: stop treating lone CRs as end-of-lines

We used to treat lone CRs (\r, aka ^M) as regular NLs (\n), probably
to please Classic MacOS.  As of today, it makes more sense to treat \r
like a plain white space character.

https://lists.gnu.org/archive/html/bison-patches/2019-09/msg00027.html

* src/scan-gram.l (no_cr_read): Remove.  Instead, use...
(eol): this new abbreviation denoting end-of-line.
* src/location.c (caret_getc): New.
(location_caret): Use it.
* tests/diagnostics.at (Carriage return): Adjust expectations.
(CR NL): New.
This commit is contained in:
Akim Demaille
2019-09-10 18:51:25 +02:00
parent 5e4133175d
commit 19da501e06
4 changed files with 76 additions and 71 deletions

View File

@@ -169,7 +169,7 @@ static struct
} caret_info;
void
caret_free ()
caret_free (void)
{
if (caret_info.source)
{
@@ -178,6 +178,23 @@ caret_free ()
}
}
/* Getc, but smash \r\n as \n. */
static int
caret_getc (void)
{
FILE *f = caret_info.source;
int res = getc (f);
if (res == '\r')
{
int c = getc (f);
if (c == '\n')
res = c;
else
ungetc (c, f);
}
return res;
}
void
location_caret (location loc, const char *style, FILE *out)
{
@@ -230,7 +247,7 @@ location_caret (location loc, const char *style, FILE *out)
/* Advance to the line's position, keeping track of the offset. */
while (caret_info.line < loc.start.line)
{
int c = getc (caret_info.source);
int c = caret_getc ();
if (c == EOF)
/* Something is wrong, that line number does not exist. */
return;
@@ -241,7 +258,7 @@ location_caret (location loc, const char *style, FILE *out)
/* Read the actual line. Don't update the offset, so that we keep a pointer
to the start of the line. */
{
int c = getc (caret_info.source);
int c = caret_getc ();
if (c != EOF)
{
bool single_line = loc.start.line == loc.end.line;
@@ -268,7 +285,7 @@ location_caret (location loc, const char *style, FILE *out)
opened = true;
}
fputc (c, out);
c = getc (caret_info.source);
c = caret_getc ();
++byte;
if (opened
&& (single_line