implementation of numerical escape sequences in strings ("\12");

better error messages for wrong tokens
This commit is contained in:
Roberto Ierusalimschy
1998-02-11 18:56:46 -02:00
parent 29b7b8e52c
commit aafa106d10

45
llex.c
View File

@@ -1,5 +1,5 @@
/*
** $Id: llex.c,v 1.13 1998/01/09 14:44:55 roberto Exp roberto $
** $Id: llex.c,v 1.14 1998/01/19 20:18:02 roberto Exp roberto $
** Lexical Analizer
** See Copyright Notice in lua.h
*/
@@ -126,7 +126,7 @@ static void ifskip (LexState *LS)
if (LS->current == '\n')
inclinenumber(LS);
else if (LS->current == EOZ)
luaY_syntaxerror("input ends inside a $if", "");
luaY_error("input ends inside a $if");
else next(LS);
}
}
@@ -218,8 +218,8 @@ static int read_long_string (LexState *LS, YYSTYPE *l)
while (1) {
switch (LS->current) {
case EOZ:
save(0);
return WRONGTOKEN;
luaY_error("unfinished long string");
return 0; /* to avoid warnings */
case '[':
save_and_next(LS);
if (LS->current == '[') {
@@ -319,8 +319,8 @@ int luaY_lex (YYSTYPE *l)
switch (LS->current) {
case EOZ:
case '\n':
save(0);
return WRONGTOKEN;
luaY_error("unfinished string");
return 0; /* to avoid warnings */
case '\\':
next(LS); /* do not save the '\' */
switch (LS->current) {
@@ -328,7 +328,29 @@ int luaY_lex (YYSTYPE *l)
case 't': save('\t'); next(LS); break;
case 'r': save('\r'); next(LS); break;
case '\n': save('\n'); inclinenumber(LS); break;
default : save_and_next(LS); break;
case '\\': case '"': case '\'': {
save(LS->current);
next(LS);
break;
}
default : {
if (isdigit(LS->current)) {
int c = 0;
int i = 0;
do {
c = 10*c + (LS->current-'0');
i++;
next(LS);
} while (i<3 && isdigit(LS->current));
save(c);
}
else {
save('\\');
save(LS->current);
luaY_error("invalid escape sequence");
}
break;
}
}
break;
default:
@@ -369,7 +391,7 @@ int luaY_lex (YYSTYPE *l)
if (LS->current == '.') {
save_and_next(LS);
if (LS->current == '.') {
save(0);
save('.');
luaY_error(
"ambiguous syntax (decimal point x string concatenation)");
}
@@ -389,8 +411,8 @@ int luaY_lex (YYSTYPE *l)
save_and_next(LS);
neg = (LS->current=='-');
if (LS->current == '+' || LS->current == '-') save_and_next(LS);
if (!isdigit(LS->current)) {
save(0); return WRONGTOKEN; }
if (!isdigit(LS->current))
luaY_error("invalid numeral format");
do {
e = 10.0*e + (LS->current-'0');
save_and_next(LS);
@@ -406,9 +428,8 @@ int luaY_lex (YYSTYPE *l)
}
case EOZ:
save(0);
if (LS->iflevel > 0)
luaY_syntaxerror("input ends inside a $if", "");
luaY_error("input ends inside a $if");
return 0;
default: