aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2005-04-27 15:37:51 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2005-04-27 15:37:51 -0300
commitcf5d1bdd761d5f9c7be45dd193094b52a2723f00 (patch)
treeb3fd8aa832acbe3f9162d2a090ef36f51357cf0c
parent8718fda9b24fa148ffe1a06fb36a7aa2ed628bdc (diff)
downloadlua-cf5d1bdd761d5f9c7be45dd193094b52a2723f00.tar.gz
lua-cf5d1bdd761d5f9c7be45dd193094b52a2723f00.tar.bz2
lua-cf5d1bdd761d5f9c7be45dd193094b52a2723f00.zip
nesting of long strings only in compatibility mode
-rw-r--r--llex.c33
-rw-r--r--luaconf.h9
2 files changed, 32 insertions, 10 deletions
diff --git a/llex.c b/llex.c
index e7c37efa..58125080 100644
--- a/llex.c
+++ b/llex.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: llex.c,v 2.8 2004/12/03 20:44:19 roberto Exp roberto $ 2** $Id: llex.c,v 2.9 2004/12/03 20:54:12 roberto Exp roberto $
3** Lexical Analyzer 3** Lexical Analyzer
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -202,6 +202,7 @@ static int skip_sep (LexState *ls) {
202 202
203static void read_long_string (LexState *ls, SemInfo *seminfo, int sep) { 203static void read_long_string (LexState *ls, SemInfo *seminfo, int sep) {
204 int cont = 0; 204 int cont = 0;
205 (void)(cont); /* avoid warnings when `cont' is not used */
205 save_and_next(ls); /* skip 2nd `[' */ 206 save_and_next(ls); /* skip 2nd `[' */
206 if (currIsNewline(ls)) /* string starts with a newline? */ 207 if (currIsNewline(ls)) /* string starts with a newline? */
207 inclinenumber(ls); /* skip it */ 208 inclinenumber(ls); /* skip it */
@@ -211,27 +212,41 @@ static void read_long_string (LexState *ls, SemInfo *seminfo, int sep) {
211 luaX_lexerror(ls, (seminfo) ? "unfinished long string" : 212 luaX_lexerror(ls, (seminfo) ? "unfinished long string" :
212 "unfinished long comment", TK_EOS); 213 "unfinished long comment", TK_EOS);
213 break; /* to avoid warnings */ 214 break; /* to avoid warnings */
214 case '[': 215#if defined(LUA_COMPAT_LSTR)
216 case '[': {
215 if (skip_sep(ls) == sep) { 217 if (skip_sep(ls) == sep) {
216 save_and_next(ls); /* skip 2nd `[' */ 218 save_and_next(ls); /* skip 2nd `[' */
217 cont++; 219 cont++;
220#if LUA_COMPAT_LSTR == 1
221 if (sep == 0)
222 luaX_lexerror(ls, "nesting of [[...]] is deprecated", '[');
223#endif
218 } 224 }
219 continue; 225 break;
220 case ']': 226 }
227#endif
228 case ']': {
221 if (skip_sep(ls) == sep) { 229 if (skip_sep(ls) == sep) {
222 save_and_next(ls); /* skip 2nd `]' */ 230 save_and_next(ls); /* skip 2nd `]' */
223 if (cont-- == 0) goto endloop; 231#if defined(LUA_COMPAT_LSTR) && LUA_COMPAT_LSTR == 2
232 cont--;
233 if (sep == 0 && cont >= 0) break;
234#endif
235 goto endloop;
224 } 236 }
225 continue; 237 break;
238 }
226 case '\n': 239 case '\n':
227 case '\r': 240 case '\r': {
228 save(ls, '\n'); 241 save(ls, '\n');
229 inclinenumber(ls); 242 inclinenumber(ls);
230 if (!seminfo) luaZ_resetbuffer(ls->buff); /* avoid wasting space */ 243 if (!seminfo) luaZ_resetbuffer(ls->buff); /* avoid wasting space */
231 continue; 244 break;
232 default: 245 }
246 default: {
233 if (seminfo) save_and_next(ls); 247 if (seminfo) save_and_next(ls);
234 else next(ls); 248 else next(ls);
249 }
235 } 250 }
236 } endloop: 251 } endloop:
237 if (seminfo) 252 if (seminfo)
diff --git a/luaconf.h b/luaconf.h
index f7a6c0ec..8b25f23b 100644
--- a/luaconf.h
+++ b/luaconf.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: luaconf.h,v 1.43 2005/04/07 13:52:45 roberto Exp roberto $ 2** $Id: luaconf.h,v 1.44 2005/04/25 19:24:10 roberto Exp roberto $
3** Configuration file for Lua 3** Configuration file for Lua
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -267,6 +267,13 @@
267*/ 267*/
268#define LUA_COMPAT_VARARG 1 268#define LUA_COMPAT_VARARG 1
269 269
270/*
271@@ LUA_COMPAT_LSTR controls compatibility with old long string nesting
272@* facility.
273** CHANGE it to 2 if you want the old behaviour, or undefine it to turn
274** off the advisory error when nesting [[...]].
275*/
276#define LUA_COMPAT_LSTR 1
270 277
271/* 278/*
272@@ luai_apicheck is the assert macro used by the Lua-C API. 279@@ luai_apicheck is the assert macro used by the Lua-C API.