mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-19 09:13:04 +00:00
(literalchar): Fix the code for escaping \, " and '.
(lex): Avoid trouble when there are many chars to discard in a char literal with just several chars in it.
This commit is contained in:
15
src/lex.c
15
src/lex.c
@@ -268,11 +268,11 @@ literalchar(pp, pcode, term)
|
|||||||
so that `\012' and `\n' can be interchangeable. */
|
so that `\012' and `\n' can be interchangeable. */
|
||||||
|
|
||||||
p = *pp;
|
p = *pp;
|
||||||
if (code >= 040 && code < 0177)
|
if (code == '\\') {*p++ = '\\'; *p++ = '\\';}
|
||||||
*p++ = code;
|
|
||||||
else if (code == '\\') {*p++ = '\\'; *p++ = '\\';}
|
|
||||||
else if (code == '\'') {*p++ = '\\'; *p++ = '\'';}
|
else if (code == '\'') {*p++ = '\\'; *p++ = '\'';}
|
||||||
else if (code == '\"') {*p++ = '\\'; *p++ = '\"';}
|
else if (code == '\"') {*p++ = '\\'; *p++ = '\"';}
|
||||||
|
else if (code >= 040 && code < 0177)
|
||||||
|
*p++ = code;
|
||||||
else if (code == '\t') {*p++ = '\\'; *p++ = 't';}
|
else if (code == '\t') {*p++ = '\\'; *p++ = 't';}
|
||||||
else if (code == '\n') {*p++ = '\\'; *p++ = 'n';}
|
else if (code == '\n') {*p++ = '\\'; *p++ = 'n';}
|
||||||
else if (code == '\r') {*p++ = '\\'; *p++ = 'r';}
|
else if (code == '\r') {*p++ = '\\'; *p++ = 'r';}
|
||||||
@@ -381,6 +381,7 @@ lex()
|
|||||||
{
|
{
|
||||||
int code, discode;
|
int code, discode;
|
||||||
char discard[10], *dp;
|
char discard[10], *dp;
|
||||||
|
|
||||||
p = token_buffer;
|
p = token_buffer;
|
||||||
*p++ = '\'';
|
*p++ = '\'';
|
||||||
literalchar(&p, &code, '\'');
|
literalchar(&p, &code, '\'');
|
||||||
@@ -389,8 +390,12 @@ lex()
|
|||||||
if (c != '\'')
|
if (c != '\'')
|
||||||
{
|
{
|
||||||
warn(_("use \"...\" for multi-character literal tokens"));
|
warn(_("use \"...\" for multi-character literal tokens"));
|
||||||
dp = discard;
|
while (1)
|
||||||
while (literalchar(&dp, &discode, '\'')) {}
|
{
|
||||||
|
dp = discard;
|
||||||
|
if (! literalchar(&dp, &discode, '\''))
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
*p++ = '\'';
|
*p++ = '\'';
|
||||||
*p = 0;
|
*p = 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user