History

Lua 5.2.0-beta

Lua Team committed 15 years ago

Commit 8203bab1 parent c2bb1fc4 files · +64 −52Browse files

Showing the changes to src (3 of 4 files). Show all

Unified · Split

3 files
  1. src/llex.c +39 −32
  2. src/lua.hpp +9 −0
  3. src/luaconf.h +5 −7
src/llex.c+39−32
@@ -1,5 +1,5 @@
11 /*
2−** $Id: llex.c,v 2.50 2011/07/05 19:13:45 roberto Exp $
2+** $Id: llex.c,v 2.53 2011/07/08 20:01:38 roberto Exp $
33 ** Lexical Analyzer
44 ** See Copyright Notice in lua.h
55 */
@@ -286,45 +286,51 @@ static void read_long_string (LexState *ls, SemInfo *seminfo, int sep) { · 280 unmodified lines
286286 }
287287
288288
289+static void escerror (LexState *ls, int *c, int n, const char *msg) {
290+ int i;
291+ luaZ_resetbuffer(ls->buff); /* prepare error message */
292+ save(ls, '\\');
293+ for (i = 0; i < n && c[i] != EOZ; i++)
294+ save(ls, c[i]);
295+ lexerror(ls, msg, TK_STRING);
296+}
297+
298+
289299 static int readhexaesc (LexState *ls) {
290− int c1 = next(ls);
291− int c2 = EOZ;
292− if (lisxdigit(c1)) {
293− c2 = next(ls);
294− if (lisxdigit(c2))
295− return (luaO_hexavalue(c1) << 4) + luaO_hexavalue(c2);
300+ int c[3]; /* keep input for error message */
301+ int i = 2; /* at least 'x?' will go to error message */
302+ c[0] = 'x';
303+ c[1] = next(ls); /* first hexa digit */
304+ if (lisxdigit(c[1])) {
305+ c[i++] = next(ls); /* second hexa digit */
306+ if (lisxdigit(c[2]))
307+ return (luaO_hexavalue(c[1]) << 4) + luaO_hexavalue(c[2]);
296308 /* else go through to error */
297309 }
298− luaZ_resetbuffer(ls->buff); /* prepare error message */
299− save(ls, '\\'); save(ls, 'x');
300− if (c1 != EOZ) save(ls, c1);
301− if (c2 != EOZ) save(ls, c2);
302− lexerror(ls, "hexadecimal digit expected", TK_STRING);
310+ escerror(ls, c, i, "hexadecimal digit expected");
303311 return 0; /* to avoid warnings */
304312 }
305313
306314
307315 static int readdecesc (LexState *ls) {
308− int c1 = ls->current; /* first char must be a digit */
309− int c2 = next(ls); /* read second char */
310− int c = c1 - '0'; /* partial result */
311− if (lisdigit(c2)) {
312− int c3 = next(ls); /* read third char */
313− c = 10*c + c2 - '0'; /* update result */
314− if (lisdigit(c3)) {
315− c = 10*c + c3 - '0'; /* update result */
316− if (c > UCHAR_MAX) {
317− luaZ_resetbuffer(ls->buff); /* prepare error message */
318− save(ls, '\\');
319− save(ls, c1); save(ls, c2); save(ls, c3);
320− lexerror(ls, "decimal escape too large", TK_STRING);
321− }
322− return c;
316+ int c[3], r;
317+ int i = 2; /* at least two chars will be read */
318+ c[0] = ls->current; /* first char must be a digit */
319+ c[1] = next(ls); /* read second char */
320+ r = c[0] - '0'; /* partial result */
321+ if (lisdigit(c[1])) {
322+ c[i++] = next(ls); /* read third char */
323+ r = 10*r + c[1] - '0'; /* update result */
324+ if (lisdigit(c[2])) {
325+ r = 10*r + c[2] - '0'; /* update result */
326+ if (r > UCHAR_MAX)
327+ escerror(ls, c, i, "decimal escape too large");
328+ return r;
323329 }
324330 }
325331 /* else, has read one character that was not a digit */
326332 zungetc(ls->z); /* return it to input stream */
327− return c;
333+ return r;
328334 }
329335
330336
@@ -353,9 +359,10 @@ static void read_string (LexState *ls, int del, SemInfo *seminfo) { · 22 unmodified lines
353359 case 'x': c = readhexaesc(ls); break;
354360 case '\n':
355361 case '\r': save(ls, '\n'); inclinenumber(ls); continue;
362+ case '\\': case '\"': case '\'': c = ls->current; break;
356363 case EOZ: continue; /* will raise an error next loop */
357364 case 'z': { /* zap following span of spaces */
358− next(ls); /* skip the '*' */
365+ next(ls); /* skip the 'z' */
359366 while (lisspace(ls->current)) {
360367 if (currIsNewline(ls)) inclinenumber(ls);
361368 else next(ls);
@@ -364,9 +371,9 @@ static void read_string (LexState *ls, int del, SemInfo *seminfo) { · 2 unmodified lines
364371 }
365372 default: {
366373 if (!lisdigit(ls->current))
367− c = ls->current; /* handles \\, \", and \' */
368− else /* digital escape \ddd */
369− c = readdecesc(ls);
374+ escerror(ls, &ls->current, 1, "invalid escape sequence");
375+ /* digital escape \ddd */
376+ c = readdecesc(ls);
370377 break;
371378 }
372379 }
src/lua.hpp+9−0
@@ -0,0 +1,9 @@
1+// lua.hpp
2+// Lua header files for C++
3+// <<extern "C">> not supplied automatically because Lua also compiles as C++
4+
5+extern "C" {
6+#include "lua.h"
7+#include "lualib.h"
8+#include "lauxlib.h"
9+}
src/luaconf.h+5−7
@@ -1,5 +1,5 @@
11 /*
2−** $Id: luaconf.h,v 1.160 2011/06/28 17:14:12 roberto Exp $
2+** $Id: luaconf.h,v 1.161 2011/07/08 20:07:11 roberto Exp $
33 ** Configuration file for Lua
44 ** See Copyright Notice in lua.h
55 */
@@ -499,12 +499,12 @@ · 493 unmodified lines
499499 ** doubles with conventional endianess (12345678 or 87654321), in CPUs
500500 ** that do not produce signaling NaN values (all NaNs are quiet).
501501 */
502−#if defined(LUA_CORE) /* { */
503−
504−#if defined(LUA_NUMBER_DOUBLE) && !defined(LUA_ANSI) /* { */
502+#if defined(LUA_CORE) && \
503+ defined(LUA_NUMBER_DOUBLE) && !defined(LUA_ANSI) /* { */
505504
506505 /* little-endian architectures that satisfy those conditions */
507−#if defined(__i386__) || defined(__i386) || defined(__X86__)
506+#if defined(__i386__) || defined(__i386) || defined(__X86__) || \
507+ defined(_M_IX86)
508508
509509 #define LUA_NANTRICKLE
510510
@@ -512,8 +512,6 @@ · 1 unmodified line
512512
513513 #endif /* } */
514514
515−#endif /* } */
516−
517515
518516
519517

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t