diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2014-05-11 11:45:43 -0300 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2014-05-11 11:45:43 -0300 |
| commit | 5018104a60671d7b37bf1fc64c70b73753d76c65 (patch) | |
| tree | 875a1054e1445604995aad2df5ab9326a2d84e99 | |
| parent | ec11d132db52703e7b131ce56ad9dba3154bc363 (diff) | |
| download | lua-5018104a60671d7b37bf1fc64c70b73753d76c65.tar.gz lua-5018104a60671d7b37bf1fc64c70b73753d76c65.tar.bz2 lua-5018104a60671d7b37bf1fc64c70b73753d76c65.zip | |
better error message for unfinished long strings/comments
| -rw-r--r-- | llex.c | 12 |
1 files changed, 8 insertions, 4 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: llex.c,v 2.75 2014/04/30 16:48:44 roberto Exp roberto $ | 2 | ** $Id: llex.c,v 2.76 2014/05/01 18:18:06 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 | */ |
| @@ -284,15 +284,19 @@ static int skip_sep (LexState *ls) { | |||
| 284 | 284 | ||
| 285 | 285 | ||
| 286 | static void read_long_string (LexState *ls, SemInfo *seminfo, int sep) { | 286 | static void read_long_string (LexState *ls, SemInfo *seminfo, int sep) { |
| 287 | int line = ls->linenumber; /* initial line (for error message) */ | ||
| 287 | save_and_next(ls); /* skip 2nd `[' */ | 288 | save_and_next(ls); /* skip 2nd `[' */ |
| 288 | if (currIsNewline(ls)) /* string starts with a newline? */ | 289 | if (currIsNewline(ls)) /* string starts with a newline? */ |
| 289 | inclinenumber(ls); /* skip it */ | 290 | inclinenumber(ls); /* skip it */ |
| 290 | for (;;) { | 291 | for (;;) { |
| 291 | switch (ls->current) { | 292 | switch (ls->current) { |
| 292 | case EOZ: | 293 | case EOZ: { /* error */ |
| 293 | lexerror(ls, (seminfo) ? "unfinished long string" : | 294 | const char *what = (seminfo ? "string" : "comment"); |
| 294 | "unfinished long comment", TK_EOS); | 295 | const char *msg = luaO_pushfstring(ls->L, |
| 296 | "unfinished long %s (starting at line %d)", what, line); | ||
| 297 | lexerror(ls, msg, TK_EOS); | ||
| 295 | break; /* to avoid warnings */ | 298 | break; /* to avoid warnings */ |
| 299 | } | ||
| 296 | case ']': { | 300 | case ']': { |
| 297 | if (skip_sep(ls) == sep) { | 301 | if (skip_sep(ls) == sep) { |
| 298 | save_and_next(ls); /* skip 2nd `]' */ | 302 | save_and_next(ls); /* skip 2nd `]' */ |
