long string delimiter changed from `[*[' to `[=['

This commit is contained in:
Roberto Ierusalimschy 2004-09-22 11:02:00 -03:00
parent 8b5bb6056b
commit b2820f39a2
1 changed files with 16 additions and 16 deletions

32
llex.c
View File

@ -1,5 +1,5 @@
/* /*
** $Id: llex.c,v 2.2 2004/03/12 19:53:56 roberto Exp roberto $ ** $Id: llex.c,v 2.3 2004/04/30 20:13:38 roberto Exp roberto $
** Lexical Analyzer ** Lexical Analyzer
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@ -181,12 +181,12 @@ static void read_numeral (LexState *ls, SemInfo *seminfo) {
} }
static int skip_ast (LexState *ls) { static int skip_sep (LexState *ls) {
int count = 0; int count = 0;
int s = ls->current; int s = ls->current;
lua_assert(s == '[' || s == ']'); lua_assert(s == '[' || s == ']');
save_and_next(ls); save_and_next(ls);
while (ls->current == '*') { while (ls->current == '=') {
save_and_next(ls); save_and_next(ls);
count++; count++;
} }
@ -194,7 +194,7 @@ static int skip_ast (LexState *ls) {
} }
static void read_long_string (LexState *ls, SemInfo *seminfo, int ast) { static void read_long_string (LexState *ls, SemInfo *seminfo, int sep) {
int cont = 0; int cont = 0;
save_and_next(ls); /* skip 2nd `[' */ save_and_next(ls); /* skip 2nd `[' */
if (currIsNewline(ls)) /* string starts with a newline? */ if (currIsNewline(ls)) /* string starts with a newline? */
@ -206,13 +206,13 @@ static void read_long_string (LexState *ls, SemInfo *seminfo, int ast) {
"unfinished long comment", TK_EOS); "unfinished long comment", TK_EOS);
break; /* to avoid warnings */ break; /* to avoid warnings */
case '[': case '[':
if (skip_ast(ls) == ast) { if (skip_sep(ls) == sep) {
save_and_next(ls); /* skip 2nd `[' */ save_and_next(ls); /* skip 2nd `[' */
cont++; cont++;
} }
continue; continue;
case ']': case ']':
if (skip_ast(ls) == ast) { if (skip_sep(ls) == sep) {
save_and_next(ls); /* skip 2nd `]' */ save_and_next(ls); /* skip 2nd `]' */
if (cont-- == 0) goto endloop; if (cont-- == 0) goto endloop;
} }
@ -229,8 +229,8 @@ static void read_long_string (LexState *ls, SemInfo *seminfo, int ast) {
} }
} endloop: } endloop:
if (seminfo) if (seminfo)
seminfo->ts = luaX_newstring(ls, luaZ_buffer(ls->buff) + (2 + ast), seminfo->ts = luaX_newstring(ls, luaZ_buffer(ls->buff) + (2 + sep),
luaZ_bufflen(ls->buff) - 2*(2 + ast)); luaZ_bufflen(ls->buff) - 2*(2 + sep));
} }
@ -305,10 +305,10 @@ int luaX_lex (LexState *ls, SemInfo *seminfo) {
/* else is a comment */ /* else is a comment */
next(ls); next(ls);
if (ls->current == '[') { if (ls->current == '[') {
int ast = skip_ast(ls); int sep = skip_sep(ls);
luaZ_resetbuffer(ls->buff); /* `skip_ast' may dirty the buffer */ luaZ_resetbuffer(ls->buff); /* `skip_sep' may dirty the buffer */
if (ast >= 0) { if (sep >= 0) {
read_long_string(ls, NULL, ast); /* long comment */ read_long_string(ls, NULL, sep); /* long comment */
luaZ_resetbuffer(ls->buff); luaZ_resetbuffer(ls->buff);
continue; continue;
} }
@ -319,12 +319,12 @@ int luaX_lex (LexState *ls, SemInfo *seminfo) {
continue; continue;
} }
case '[': { case '[': {
int ast = skip_ast(ls); int sep = skip_sep(ls);
if (ast >= 0) { if (sep >= 0) {
read_long_string(ls, seminfo, ast); read_long_string(ls, seminfo, sep);
return TK_STRING; return TK_STRING;
} }
else if (ast == -1) return '['; else if (sep == -1) return '[';
else luaX_lexerror(ls, "invalid long string delimiter", TK_STRING); else luaX_lexerror(ls, "invalid long string delimiter", TK_STRING);
} }
case '=': { case '=': {