mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-19 17:23:02 +00:00
fixits: track byte-columns, not character-columns
Because the fix-its were ready the character-based columns, but were
applied on byte-based columns, the result with multibyte characters or
tabs could be "interesting". For instance
%fixed-output_files
%fixed_output-files
%fixed-output-files
%define api.prefix {foo}
%no-default-prec
would give
%fixed-%fixed-output-files %fixed_output-files
%fixed-orefix= "foo"
o_default-prec
* src/fixits.c (fixit_print, fixits_run): Work on byte-base columns.
* tests/input.at: Check it.
This commit is contained in:
23
src/fixits.c
23
src/fixits.c
@@ -69,8 +69,8 @@ fixit_print (fixit const *f, FILE *out)
|
|||||||
{
|
{
|
||||||
fprintf (out, "fix-it:%s:{%d:%d-%d:%d}:%s\n",
|
fprintf (out, "fix-it:%s:{%d:%d-%d:%d}:%s\n",
|
||||||
quotearg_n_style (1, c_quoting_style, f->location.start.file),
|
quotearg_n_style (1, c_quoting_style, f->location.start.file),
|
||||||
f->location.start.line, f->location.start.column,
|
f->location.start.line, f->location.start.byte,
|
||||||
f->location.end.line, f->location.end.column,
|
f->location.end.line, f->location.end.byte,
|
||||||
quotearg_n_style (2, c_quoting_style, f->fix));
|
quotearg_n_style (2, c_quoting_style, f->fix));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -136,19 +136,29 @@ fixits_run (void)
|
|||||||
}
|
}
|
||||||
putc (c, out);
|
putc (c, out);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Look for the right offset. */
|
/* Look for the right offset. */
|
||||||
while (offset < f->location.start.column)
|
bool need_eol = false;
|
||||||
|
while (offset < f->location.start.byte)
|
||||||
{
|
{
|
||||||
int c = getc (in);
|
int c = getc (in);
|
||||||
if (c == EOF)
|
if (c == EOF)
|
||||||
break;
|
break;
|
||||||
++offset;
|
++offset;
|
||||||
putc (c, out);
|
if (c == '\n')
|
||||||
|
/* The position we are asked for is beyond the actual
|
||||||
|
line: pad with spaces, and remember we need a \n. */
|
||||||
|
need_eol = true;
|
||||||
|
putc (need_eol ? ' ' : c, out);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Paste the fix instead. */
|
/* Paste the fix instead. */
|
||||||
fputs (f->fix, out);
|
fputs (f->fix, out);
|
||||||
|
|
||||||
|
/* Maybe install the eol afterwards. */
|
||||||
|
if (need_eol)
|
||||||
|
putc ('\n', out);
|
||||||
|
|
||||||
/* Skip the bad input. */
|
/* Skip the bad input. */
|
||||||
while (line < f->location.end.line)
|
while (line < f->location.end.line)
|
||||||
{
|
{
|
||||||
@@ -161,16 +171,17 @@ fixits_run (void)
|
|||||||
offset = 1;
|
offset = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
while (offset < f->location.end.column)
|
while (offset < f->location.end.byte)
|
||||||
{
|
{
|
||||||
int c = getc (in);
|
int c = getc (in);
|
||||||
if (c == EOF)
|
if (c == EOF)
|
||||||
break;
|
break;
|
||||||
++offset;
|
++offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* If erasing the content of a full line, also remove the
|
/* If erasing the content of a full line, also remove the
|
||||||
end-of-line. */
|
end-of-line. */
|
||||||
if (f->fix[0] == 0 && f->location.start.column == 1)
|
if (f->fix[0] == 0 && f->location.start.byte == 1)
|
||||||
{
|
{
|
||||||
int c = getc (in);
|
int c = getc (in);
|
||||||
if (c == EOF)
|
if (c == EOF)
|
||||||
|
|||||||
@@ -2509,8 +2509,8 @@ AT_DATA_GRAMMAR([[input.y]],
|
|||||||
%file-prefix
|
%file-prefix
|
||||||
=
|
=
|
||||||
"bar"
|
"bar"
|
||||||
%fixed-output_files
|
%fixed-output_files
|
||||||
%fixed_output-files
|
%fixed_output-files
|
||||||
%fixed-output-files
|
%fixed-output-files
|
||||||
%name-prefix= "foo"
|
%name-prefix= "foo"
|
||||||
%no-default_prec
|
%no-default_prec
|
||||||
@@ -2538,13 +2538,13 @@ fix-it:"input.y":{13:1-13:15}:"%file-prefix"
|
|||||||
input.y:14.1-16.5: warning: duplicate directive: '%file-prefix\n =' [-Wother]
|
input.y:14.1-16.5: warning: duplicate directive: '%file-prefix\n =' [-Wother]
|
||||||
input.y:13.1-20: previous declaration
|
input.y:13.1-20: previous declaration
|
||||||
fix-it:"input.y":{14:1-16:6}:""
|
fix-it:"input.y":{14:1-16:6}:""
|
||||||
input.y:17.1-19: warning: deprecated directive: '%fixed-output_files', use '%fixed-output-files' [-Wdeprecated]
|
input.y:17.9-27: warning: deprecated directive: '%fixed-output_files', use '%fixed-output-files' [-Wdeprecated]
|
||||||
fix-it:"input.y":{17:1-17:20}:"%fixed-output-files"
|
fix-it:"input.y":{17:2-17:21}:"%fixed-output-files"
|
||||||
input.y:18.1-19: warning: duplicate directive: '%fixed_output-files' [-Wother]
|
input.y:18.9-27: warning: duplicate directive: '%fixed_output-files' [-Wother]
|
||||||
input.y:17.1-19: previous declaration
|
input.y:17.9-27: previous declaration
|
||||||
fix-it:"input.y":{18:1-18:20}:""
|
fix-it:"input.y":{18:9-18:28}:""
|
||||||
input.y:19.1-19: warning: duplicate directive: '%fixed-output-files' [-Wother]
|
input.y:19.1-19: warning: duplicate directive: '%fixed-output-files' [-Wother]
|
||||||
input.y:17.1-19: previous declaration
|
input.y:17.9-27: previous declaration
|
||||||
fix-it:"input.y":{19:1-19:20}:""
|
fix-it:"input.y":{19:1-19:20}:""
|
||||||
input.y:20.1-19: warning: deprecated directive: '%name-prefix= "foo"', use '%define api.prefix {foo}' [-Wdeprecated]
|
input.y:20.1-19: warning: deprecated directive: '%name-prefix= "foo"', use '%define api.prefix {foo}' [-Wdeprecated]
|
||||||
fix-it:"input.y":{20:1-20:20}:"%define api.prefix {foo}"
|
fix-it:"input.y":{20:1-20:20}:"%define api.prefix {foo}"
|
||||||
@@ -2604,7 +2604,8 @@ AT_CHECK([cat input.y], [],
|
|||||||
%define parse.error verbose
|
%define parse.error verbose
|
||||||
%expect-rr 0
|
%expect-rr 0
|
||||||
%file-prefix "foo"
|
%file-prefix "foo"
|
||||||
%fixed-output-files
|
%fixed-output-files
|
||||||
|
@&t@
|
||||||
%define api.prefix {foo}
|
%define api.prefix {foo}
|
||||||
%no-default-prec
|
%no-default-prec
|
||||||
%no-default-prec
|
%no-default-prec
|
||||||
|
|||||||
Reference in New Issue
Block a user