1997-09-16 23:25:59 +04:00
|
|
|
/*
|
1999-02-04 20:47:59 +03:00
|
|
|
** $Id: llex.c,v 1.27 1998/12/28 13:44:54 roberto Exp roberto $
|
1997-09-16 23:25:59 +04:00
|
|
|
** Lexical Analizer
|
|
|
|
** See Copyright Notice in lua.h
|
|
|
|
*/
|
1996-05-30 18:04:07 +04:00
|
|
|
|
1993-12-23 00:15:16 +03:00
|
|
|
|
|
|
|
#include <ctype.h>
|
1993-12-28 19:42:29 +03:00
|
|
|
#include <string.h>
|
1993-12-23 00:15:16 +03:00
|
|
|
|
1997-12-17 23:48:58 +03:00
|
|
|
#include "lauxlib.h"
|
1997-09-16 23:25:59 +04:00
|
|
|
#include "llex.h"
|
|
|
|
#include "lmem.h"
|
|
|
|
#include "lobject.h"
|
|
|
|
#include "lparser.h"
|
1997-11-19 20:29:23 +03:00
|
|
|
#include "lstate.h"
|
1997-09-16 23:25:59 +04:00
|
|
|
#include "lstring.h"
|
1996-02-07 17:14:40 +03:00
|
|
|
#include "luadebug.h"
|
1997-09-16 23:25:59 +04:00
|
|
|
#include "lzio.h"
|
1993-12-23 00:15:16 +03:00
|
|
|
|
1995-09-16 00:48:26 +04:00
|
|
|
|
1996-05-30 18:04:07 +04:00
|
|
|
|
1997-11-21 22:00:46 +03:00
|
|
|
#define next(LS) (LS->current = zgetc(LS->lex_z))
|
1997-09-16 23:25:59 +04:00
|
|
|
|
|
|
|
|
1998-05-27 17:08:34 +04:00
|
|
|
#define save(c) luaL_addchar(c)
|
|
|
|
#define save_and_next(LS) (save(LS->current), next(LS))
|
|
|
|
|
|
|
|
|
|
|
|
char *reserved [] = {"and", "do", "else", "elseif", "end", "function",
|
|
|
|
"if", "local", "nil", "not", "or", "repeat", "return", "then",
|
|
|
|
"until", "while"};
|
|
|
|
|
1997-09-16 23:25:59 +04:00
|
|
|
|
1997-11-04 18:27:53 +03:00
|
|
|
void luaX_init (void)
|
1997-09-16 23:25:59 +04:00
|
|
|
{
|
1997-11-04 18:27:53 +03:00
|
|
|
int i;
|
|
|
|
for (i=0; i<(sizeof(reserved)/sizeof(reserved[0])); i++) {
|
1998-05-27 17:08:34 +04:00
|
|
|
TaggedString *ts = luaS_new(reserved[i]);
|
|
|
|
ts->head.marked = FIRST_RESERVED+i; /* reserved word (always > 255) */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void luaX_syntaxerror (LexState *ls, char *s, char *token) {
|
1998-12-27 23:25:20 +03:00
|
|
|
if (token[0] == '\0')
|
1998-05-27 17:08:34 +04:00
|
|
|
token = "<eof>";
|
1998-06-19 22:47:06 +04:00
|
|
|
luaL_verror("%.100s;\n last token read: `%.50s' at line %d in chunk `%.50s'",
|
1998-05-27 17:08:34 +04:00
|
|
|
s, token, ls->linenumber, zname(ls->lex_z));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void luaX_error (LexState *ls, char *s) {
|
1998-12-27 23:25:20 +03:00
|
|
|
save('\0');
|
1998-05-27 17:08:34 +04:00
|
|
|
luaX_syntaxerror(ls, s, luaL_buffer());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1998-07-24 22:02:38 +04:00
|
|
|
void luaX_token2str (int token, char *s) {
|
1998-05-27 17:08:34 +04:00
|
|
|
if (token < 255) {
|
1998-12-28 16:44:54 +03:00
|
|
|
s[0] = (char)token;
|
1998-12-27 23:25:20 +03:00
|
|
|
s[1] = '\0';
|
1997-09-16 23:25:59 +04:00
|
|
|
}
|
1998-05-27 17:08:34 +04:00
|
|
|
else
|
|
|
|
strcpy(s, reserved[token-FIRST_RESERVED]);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void luaX_invalidchar (LexState *ls, int c) {
|
|
|
|
char buff[10];
|
|
|
|
sprintf(buff, "0x%X", c);
|
|
|
|
luaX_syntaxerror(ls, "invalid control char", buff);
|
1997-09-16 23:25:59 +04:00
|
|
|
}
|
|
|
|
|
1997-04-12 19:01:49 +04:00
|
|
|
|
1997-11-21 22:00:46 +03:00
|
|
|
static void firstline (LexState *LS)
|
1997-07-29 17:33:15 +04:00
|
|
|
{
|
1997-11-21 22:00:46 +03:00
|
|
|
int c = zgetc(LS->lex_z);
|
1998-01-19 23:18:02 +03:00
|
|
|
if (c == '#')
|
1997-11-21 22:00:46 +03:00
|
|
|
while ((c=zgetc(LS->lex_z)) != '\n' && c != EOZ) /* skip first line */;
|
|
|
|
zungetc(LS->lex_z);
|
1997-07-29 17:33:15 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1998-05-27 17:08:34 +04:00
|
|
|
void luaX_setinput (LexState *LS, ZIO *z)
|
1993-12-23 00:15:16 +03:00
|
|
|
{
|
1997-11-21 22:00:46 +03:00
|
|
|
LS->current = '\n';
|
|
|
|
LS->linenumber = 0;
|
|
|
|
LS->iflevel = 0;
|
|
|
|
LS->ifstate[0].skip = 0;
|
|
|
|
LS->ifstate[0].elsepart = 1; /* to avoid a free $else */
|
|
|
|
LS->lex_z = z;
|
1998-05-27 17:08:34 +04:00
|
|
|
LS->fs = NULL;
|
1997-11-21 22:00:46 +03:00
|
|
|
firstline(LS);
|
1997-12-17 23:48:58 +03:00
|
|
|
luaL_resetbuffer();
|
1993-12-23 00:15:16 +03:00
|
|
|
}
|
|
|
|
|
1997-04-12 19:01:49 +04:00
|
|
|
|
1997-04-07 18:48:53 +04:00
|
|
|
|
1997-04-12 19:01:49 +04:00
|
|
|
/*
|
1997-09-16 23:25:59 +04:00
|
|
|
** =======================================================
|
|
|
|
** PRAGMAS
|
|
|
|
** =======================================================
|
1997-04-12 19:01:49 +04:00
|
|
|
*/
|
|
|
|
|
|
|
|
#define PRAGMASIZE 20
|
|
|
|
|
1997-11-21 22:00:46 +03:00
|
|
|
static void skipspace (LexState *LS)
|
1997-04-12 19:01:49 +04:00
|
|
|
{
|
1997-11-21 22:00:46 +03:00
|
|
|
while (LS->current == ' ' || LS->current == '\t' || LS->current == '\r')
|
|
|
|
next(LS);
|
1997-04-12 19:01:49 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1998-05-27 17:08:34 +04:00
|
|
|
static int checkcond (LexState *LS, char *buff)
|
1997-04-12 19:01:49 +04:00
|
|
|
{
|
1997-11-07 18:09:49 +03:00
|
|
|
static char *opts[] = {"nil", "1", NULL};
|
1998-06-18 20:57:03 +04:00
|
|
|
int i = luaL_findstring(buff, opts);
|
1997-06-11 22:56:02 +04:00
|
|
|
if (i >= 0) return i;
|
1997-04-14 19:30:29 +04:00
|
|
|
else if (isalpha((unsigned char)buff[0]) || buff[0] == '_')
|
1997-09-26 19:02:26 +04:00
|
|
|
return luaS_globaldefined(buff);
|
1997-04-12 19:01:49 +04:00
|
|
|
else {
|
1998-05-27 17:08:34 +04:00
|
|
|
luaX_syntaxerror(LS, "invalid $if condition", buff);
|
1997-04-12 19:01:49 +04:00
|
|
|
return 0; /* to avoid warnings */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1997-11-21 22:00:46 +03:00
|
|
|
static void readname (LexState *LS, char *buff)
|
1996-09-26 01:52:00 +04:00
|
|
|
{
|
1997-04-07 18:48:53 +04:00
|
|
|
int i = 0;
|
1997-11-21 22:00:46 +03:00
|
|
|
skipspace(LS);
|
|
|
|
while (isalnum(LS->current) || LS->current == '_') {
|
1997-04-12 19:01:49 +04:00
|
|
|
if (i >= PRAGMASIZE) {
|
|
|
|
buff[PRAGMASIZE] = 0;
|
1998-05-27 17:08:34 +04:00
|
|
|
luaX_syntaxerror(LS, "pragma too long", buff);
|
1997-04-12 19:01:49 +04:00
|
|
|
}
|
1998-12-28 16:44:54 +03:00
|
|
|
buff[i++] = (char)LS->current;
|
1997-11-21 22:00:46 +03:00
|
|
|
next(LS);
|
1997-04-07 18:48:53 +04:00
|
|
|
}
|
|
|
|
buff[i] = 0;
|
|
|
|
}
|
|
|
|
|
1997-04-12 19:01:49 +04:00
|
|
|
|
1997-11-21 22:00:46 +03:00
|
|
|
static void inclinenumber (LexState *LS);
|
1997-04-12 19:01:49 +04:00
|
|
|
|
|
|
|
|
1997-11-21 22:00:46 +03:00
|
|
|
static void ifskip (LexState *LS)
|
1997-04-12 19:01:49 +04:00
|
|
|
{
|
1997-11-21 22:00:46 +03:00
|
|
|
while (LS->ifstate[LS->iflevel].skip) {
|
|
|
|
if (LS->current == '\n')
|
|
|
|
inclinenumber(LS);
|
|
|
|
else if (LS->current == EOZ)
|
1998-05-27 17:08:34 +04:00
|
|
|
luaX_error(LS, "input ends inside a $if");
|
1997-11-21 22:00:46 +03:00
|
|
|
else next(LS);
|
1997-04-12 19:01:49 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1997-11-21 22:00:46 +03:00
|
|
|
static void inclinenumber (LexState *LS)
|
1997-04-07 18:48:53 +04:00
|
|
|
{
|
1997-09-16 23:25:59 +04:00
|
|
|
static char *pragmas [] =
|
1997-06-11 22:56:02 +04:00
|
|
|
{"debug", "nodebug", "endinput", "end", "ifnot", "if", "else", NULL};
|
1997-11-21 22:00:46 +03:00
|
|
|
next(LS); /* skip '\n' */
|
|
|
|
++LS->linenumber;
|
|
|
|
if (LS->current == '$') { /* is a pragma? */
|
1997-04-12 19:01:49 +04:00
|
|
|
char buff[PRAGMASIZE+1];
|
|
|
|
int ifnot = 0;
|
1997-11-21 22:00:46 +03:00
|
|
|
int skip = LS->ifstate[LS->iflevel].skip;
|
|
|
|
next(LS); /* skip $ */
|
|
|
|
readname(LS, buff);
|
1998-06-18 20:57:03 +04:00
|
|
|
switch (luaL_findstring(buff, pragmas)) {
|
1997-04-07 18:48:53 +04:00
|
|
|
case 0: /* debug */
|
1999-02-04 20:47:59 +03:00
|
|
|
if (!skip) L->debug = 1;
|
1997-04-07 18:48:53 +04:00
|
|
|
break;
|
|
|
|
case 1: /* nodebug */
|
1999-02-04 20:47:59 +03:00
|
|
|
if (!skip) L->debug = 0;
|
1997-06-11 22:56:02 +04:00
|
|
|
break;
|
|
|
|
case 2: /* endinput */
|
|
|
|
if (!skip) {
|
1997-11-21 22:00:46 +03:00
|
|
|
LS->current = EOZ;
|
|
|
|
LS->iflevel = 0; /* to allow $endinput inside a $if */
|
1997-06-11 22:56:02 +04:00
|
|
|
}
|
1997-04-07 18:48:53 +04:00
|
|
|
break;
|
1997-06-11 22:56:02 +04:00
|
|
|
case 3: /* end */
|
1997-11-21 22:00:46 +03:00
|
|
|
if (LS->iflevel-- == 0)
|
1998-05-27 17:08:34 +04:00
|
|
|
luaX_syntaxerror(LS, "unmatched $end", "$end");
|
1997-04-07 18:48:53 +04:00
|
|
|
break;
|
1997-06-11 22:56:02 +04:00
|
|
|
case 4: /* ifnot */
|
1997-04-12 19:01:49 +04:00
|
|
|
ifnot = 1;
|
1997-04-07 18:48:53 +04:00
|
|
|
/* go through */
|
1997-06-11 22:56:02 +04:00
|
|
|
case 5: /* if */
|
1997-11-21 22:00:46 +03:00
|
|
|
if (LS->iflevel == MAX_IFS-1)
|
1998-05-27 17:08:34 +04:00
|
|
|
luaX_syntaxerror(LS, "too many nested $ifs", "$if");
|
1997-11-21 22:00:46 +03:00
|
|
|
readname(LS, buff);
|
|
|
|
LS->iflevel++;
|
|
|
|
LS->ifstate[LS->iflevel].elsepart = 0;
|
1998-05-27 17:08:34 +04:00
|
|
|
LS->ifstate[LS->iflevel].condition = checkcond(LS, buff) ? !ifnot : ifnot;
|
1997-11-21 22:00:46 +03:00
|
|
|
LS->ifstate[LS->iflevel].skip = skip || !LS->ifstate[LS->iflevel].condition;
|
1997-04-12 19:01:49 +04:00
|
|
|
break;
|
1997-06-11 22:56:02 +04:00
|
|
|
case 6: /* else */
|
1997-11-21 22:00:46 +03:00
|
|
|
if (LS->ifstate[LS->iflevel].elsepart)
|
1998-05-27 17:08:34 +04:00
|
|
|
luaX_syntaxerror(LS, "unmatched $else", "$else");
|
1997-11-21 22:00:46 +03:00
|
|
|
LS->ifstate[LS->iflevel].elsepart = 1;
|
|
|
|
LS->ifstate[LS->iflevel].skip = LS->ifstate[LS->iflevel-1].skip ||
|
|
|
|
LS->ifstate[LS->iflevel].condition;
|
1997-04-14 23:08:09 +04:00
|
|
|
break;
|
1997-04-12 19:01:49 +04:00
|
|
|
default:
|
1998-05-27 17:08:34 +04:00
|
|
|
luaX_syntaxerror(LS, "unknown pragma", buff);
|
1996-09-26 01:52:00 +04:00
|
|
|
}
|
1997-11-21 22:00:46 +03:00
|
|
|
skipspace(LS);
|
|
|
|
if (LS->current == '\n') /* pragma must end with a '\n' ... */
|
|
|
|
inclinenumber(LS);
|
|
|
|
else if (LS->current != EOZ) /* or eof */
|
1998-05-27 17:08:34 +04:00
|
|
|
luaX_syntaxerror(LS, "invalid pragma format", buff);
|
1997-11-21 22:00:46 +03:00
|
|
|
ifskip(LS);
|
1996-09-26 01:52:00 +04:00
|
|
|
}
|
|
|
|
}
|
1993-12-23 00:15:16 +03:00
|
|
|
|
1997-09-16 23:25:59 +04:00
|
|
|
|
1998-12-27 23:25:20 +03:00
|
|
|
|
1997-09-16 23:25:59 +04:00
|
|
|
/*
|
|
|
|
** =======================================================
|
|
|
|
** LEXICAL ANALIZER
|
|
|
|
** =======================================================
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
1998-12-27 23:25:20 +03:00
|
|
|
static int read_long_string (LexState *LS) {
|
1995-07-06 21:47:08 +04:00
|
|
|
int cont = 0;
|
1998-12-03 18:45:15 +03:00
|
|
|
for (;;) {
|
1997-11-21 22:00:46 +03:00
|
|
|
switch (LS->current) {
|
1997-06-16 20:50:22 +04:00
|
|
|
case EOZ:
|
1998-05-27 17:08:34 +04:00
|
|
|
luaX_error(LS, "unfinished long string");
|
|
|
|
return EOS; /* to avoid warnings */
|
1995-07-06 21:47:08 +04:00
|
|
|
case '[':
|
1997-11-21 22:00:46 +03:00
|
|
|
save_and_next(LS);
|
|
|
|
if (LS->current == '[') {
|
1995-07-06 21:47:08 +04:00
|
|
|
cont++;
|
1997-11-21 22:00:46 +03:00
|
|
|
save_and_next(LS);
|
1995-07-06 21:47:08 +04:00
|
|
|
}
|
1996-05-30 18:04:07 +04:00
|
|
|
continue;
|
1995-07-06 21:47:08 +04:00
|
|
|
case ']':
|
1997-11-21 22:00:46 +03:00
|
|
|
save_and_next(LS);
|
|
|
|
if (LS->current == ']') {
|
1996-05-30 18:04:07 +04:00
|
|
|
if (cont == 0) goto endloop;
|
1995-07-06 21:47:08 +04:00
|
|
|
cont--;
|
1997-11-21 22:00:46 +03:00
|
|
|
save_and_next(LS);
|
1995-07-06 21:47:08 +04:00
|
|
|
}
|
1996-05-30 18:04:07 +04:00
|
|
|
continue;
|
1995-09-16 00:48:26 +04:00
|
|
|
case '\n':
|
1997-12-17 23:48:58 +03:00
|
|
|
save('\n');
|
1997-11-21 22:00:46 +03:00
|
|
|
inclinenumber(LS);
|
1996-09-26 01:52:00 +04:00
|
|
|
continue;
|
1995-07-06 21:47:08 +04:00
|
|
|
default:
|
1997-11-21 22:00:46 +03:00
|
|
|
save_and_next(LS);
|
1995-07-06 21:47:08 +04:00
|
|
|
}
|
1996-05-30 18:04:07 +04:00
|
|
|
} endloop:
|
1998-12-27 23:25:20 +03:00
|
|
|
save_and_next(LS); /* skip the second ']' */
|
1998-05-27 17:08:34 +04:00
|
|
|
LS->seminfo.ts = luaS_newlstr(L->Mbuffbase+2,
|
1998-03-09 20:22:49 +03:00
|
|
|
L->Mbuffnext-(L->Mbuffbase-L->Mbuffer)-4);
|
1996-05-30 18:04:07 +04:00
|
|
|
return STRING;
|
1995-07-06 21:47:08 +04:00
|
|
|
}
|
|
|
|
|
1997-09-16 23:25:59 +04:00
|
|
|
|
1998-05-27 17:08:34 +04:00
|
|
|
int luaX_lex (LexState *LS) {
|
1997-12-17 23:48:58 +03:00
|
|
|
luaL_resetbuffer();
|
1998-12-03 18:45:15 +03:00
|
|
|
for (;;) {
|
1997-11-21 22:00:46 +03:00
|
|
|
switch (LS->current) {
|
1993-12-23 00:39:15 +03:00
|
|
|
|
1996-09-26 01:52:00 +04:00
|
|
|
case ' ': case '\t': case '\r': /* CR: to avoid problems with DOS */
|
1997-11-21 22:00:46 +03:00
|
|
|
next(LS);
|
1996-09-26 01:52:00 +04:00
|
|
|
continue;
|
1994-09-22 16:44:00 +04:00
|
|
|
|
1998-01-09 17:44:55 +03:00
|
|
|
case '\n':
|
|
|
|
inclinenumber(LS);
|
|
|
|
continue;
|
|
|
|
|
1993-12-23 00:15:16 +03:00
|
|
|
case '-':
|
1997-11-21 22:00:46 +03:00
|
|
|
save_and_next(LS);
|
|
|
|
if (LS->current != '-') return '-';
|
|
|
|
do { next(LS); } while (LS->current != '\n' && LS->current != EOZ);
|
1997-12-17 23:48:58 +03:00
|
|
|
luaL_resetbuffer();
|
1993-12-23 00:15:16 +03:00
|
|
|
continue;
|
1994-09-22 16:44:00 +04:00
|
|
|
|
1995-07-06 21:47:08 +04:00
|
|
|
case '[':
|
1997-11-21 22:00:46 +03:00
|
|
|
save_and_next(LS);
|
|
|
|
if (LS->current != '[') return '[';
|
1997-09-16 23:25:59 +04:00
|
|
|
else {
|
1997-11-21 22:00:46 +03:00
|
|
|
save_and_next(LS); /* pass the second '[' */
|
1998-05-27 17:08:34 +04:00
|
|
|
return read_long_string(LS);
|
1995-07-06 21:47:08 +04:00
|
|
|
}
|
|
|
|
|
1994-09-26 19:21:52 +03:00
|
|
|
case '=':
|
1997-11-21 22:00:46 +03:00
|
|
|
save_and_next(LS);
|
|
|
|
if (LS->current != '=') return '=';
|
|
|
|
else { save_and_next(LS); return EQ; }
|
1994-09-26 19:21:52 +03:00
|
|
|
|
1993-12-23 00:15:16 +03:00
|
|
|
case '<':
|
1997-11-21 22:00:46 +03:00
|
|
|
save_and_next(LS);
|
|
|
|
if (LS->current != '=') return '<';
|
|
|
|
else { save_and_next(LS); return LE; }
|
1994-09-22 16:44:00 +04:00
|
|
|
|
1993-12-23 00:15:16 +03:00
|
|
|
case '>':
|
1997-11-21 22:00:46 +03:00
|
|
|
save_and_next(LS);
|
|
|
|
if (LS->current != '=') return '>';
|
|
|
|
else { save_and_next(LS); return GE; }
|
1994-09-22 16:44:00 +04:00
|
|
|
|
1993-12-23 00:15:16 +03:00
|
|
|
case '~':
|
1997-11-21 22:00:46 +03:00
|
|
|
save_and_next(LS);
|
|
|
|
if (LS->current != '=') return '~';
|
|
|
|
else { save_and_next(LS); return NE; }
|
1993-12-23 00:15:16 +03:00
|
|
|
|
|
|
|
case '"':
|
1997-09-16 23:25:59 +04:00
|
|
|
case '\'': {
|
1997-11-21 22:00:46 +03:00
|
|
|
int del = LS->current;
|
|
|
|
save_and_next(LS);
|
|
|
|
while (LS->current != del) {
|
|
|
|
switch (LS->current) {
|
1997-06-16 20:50:22 +04:00
|
|
|
case EOZ:
|
1994-09-22 16:44:00 +04:00
|
|
|
case '\n':
|
1998-05-27 17:08:34 +04:00
|
|
|
luaX_error(LS, "unfinished string");
|
|
|
|
return EOS; /* to avoid warnings */
|
1993-12-23 00:15:16 +03:00
|
|
|
case '\\':
|
1997-11-21 22:00:46 +03:00
|
|
|
next(LS); /* do not save the '\' */
|
|
|
|
switch (LS->current) {
|
1998-03-20 17:18:18 +03:00
|
|
|
case 'a': save('\a'); next(LS); break;
|
|
|
|
case 'b': save('\b'); next(LS); break;
|
|
|
|
case 'f': save('\f'); next(LS); break;
|
1997-12-17 23:48:58 +03:00
|
|
|
case 'n': save('\n'); next(LS); break;
|
|
|
|
case 'r': save('\r'); next(LS); break;
|
1998-03-20 17:18:18 +03:00
|
|
|
case 't': save('\t'); next(LS); break;
|
|
|
|
case 'v': save('\v'); next(LS); break;
|
1997-12-17 23:48:58 +03:00
|
|
|
case '\n': save('\n'); inclinenumber(LS); break;
|
1998-02-11 23:56:46 +03:00
|
|
|
default : {
|
|
|
|
if (isdigit(LS->current)) {
|
|
|
|
int c = 0;
|
|
|
|
int i = 0;
|
|
|
|
do {
|
|
|
|
c = 10*c + (LS->current-'0');
|
|
|
|
next(LS);
|
1998-03-20 17:18:18 +03:00
|
|
|
} while (++i<3 && isdigit(LS->current));
|
1998-12-28 16:44:54 +03:00
|
|
|
if (c != (unsigned char)c)
|
1998-05-27 17:08:34 +04:00
|
|
|
luaX_error(LS, "escape sequence too large");
|
1998-02-11 23:56:46 +03:00
|
|
|
save(c);
|
|
|
|
}
|
1998-06-07 00:44:05 +04:00
|
|
|
else { /* handles \, ", ', and ? */
|
1998-02-11 23:56:46 +03:00
|
|
|
save(LS->current);
|
1998-06-07 00:44:05 +04:00
|
|
|
next(LS);
|
1998-02-11 23:56:46 +03:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
1993-12-23 00:15:16 +03:00
|
|
|
}
|
|
|
|
break;
|
1994-09-22 16:44:00 +04:00
|
|
|
default:
|
1997-11-21 22:00:46 +03:00
|
|
|
save_and_next(LS);
|
1993-12-23 00:15:16 +03:00
|
|
|
}
|
|
|
|
}
|
1998-03-09 20:22:49 +03:00
|
|
|
save_and_next(LS); /* skip delimiter */
|
1998-05-27 17:08:34 +04:00
|
|
|
LS->seminfo.ts = luaS_newlstr(L->Mbuffbase+1,
|
1998-03-09 20:22:49 +03:00
|
|
|
L->Mbuffnext-(L->Mbuffbase-L->Mbuffer)-2);
|
1993-12-23 00:15:16 +03:00
|
|
|
return STRING;
|
|
|
|
}
|
|
|
|
|
|
|
|
case '.':
|
1997-11-21 22:00:46 +03:00
|
|
|
save_and_next(LS);
|
|
|
|
if (LS->current == '.')
|
1994-09-22 16:44:00 +04:00
|
|
|
{
|
1997-11-21 22:00:46 +03:00
|
|
|
save_and_next(LS);
|
|
|
|
if (LS->current == '.')
|
1996-05-29 01:07:32 +04:00
|
|
|
{
|
1997-11-21 22:00:46 +03:00
|
|
|
save_and_next(LS);
|
1996-05-29 01:07:32 +04:00
|
|
|
return DOTS; /* ... */
|
|
|
|
}
|
1996-05-30 18:04:07 +04:00
|
|
|
else return CONC; /* .. */
|
1993-12-23 00:15:16 +03:00
|
|
|
}
|
1997-11-21 22:00:46 +03:00
|
|
|
else if (!isdigit(LS->current)) return '.';
|
1998-12-27 23:25:20 +03:00
|
|
|
goto fraction; /* LS->current is a digit: goes through to number */
|
1993-12-23 00:15:16 +03:00
|
|
|
|
|
|
|
case '0': case '1': case '2': case '3': case '4':
|
|
|
|
case '5': case '6': case '7': case '8': case '9':
|
1996-05-30 18:04:07 +04:00
|
|
|
do {
|
1997-11-21 22:00:46 +03:00
|
|
|
save_and_next(LS);
|
|
|
|
} while (isdigit(LS->current));
|
|
|
|
if (LS->current == '.') {
|
|
|
|
save_and_next(LS);
|
|
|
|
if (LS->current == '.') {
|
1998-02-11 23:56:46 +03:00
|
|
|
save('.');
|
1998-05-27 17:08:34 +04:00
|
|
|
luaX_error(LS,
|
1996-11-08 15:49:35 +03:00
|
|
|
"ambiguous syntax (decimal point x string concatenation)");
|
1997-09-16 23:25:59 +04:00
|
|
|
}
|
1996-11-08 15:49:35 +03:00
|
|
|
}
|
1996-05-30 18:04:07 +04:00
|
|
|
fraction:
|
1998-12-27 23:25:20 +03:00
|
|
|
while (isdigit(LS->current))
|
|
|
|
save_and_next(LS);
|
|
|
|
if (toupper(LS->current) == 'E') {
|
|
|
|
save_and_next(LS); /* read 'E' */
|
|
|
|
save_and_next(LS); /* read '+', '-' or first digit */
|
|
|
|
while (isdigit(LS->current))
|
1997-11-21 22:00:46 +03:00
|
|
|
save_and_next(LS);
|
1993-12-23 00:15:16 +03:00
|
|
|
}
|
1998-12-27 23:25:20 +03:00
|
|
|
save('\0');
|
|
|
|
LS->seminfo.r = luaO_str2d(L->Mbuffbase);
|
|
|
|
if (LS->seminfo.r < 0)
|
|
|
|
luaX_error(LS, "invalid numeric format");
|
|
|
|
return NUMBER;
|
1994-11-13 17:39:04 +03:00
|
|
|
|
1997-06-16 20:50:22 +04:00
|
|
|
case EOZ:
|
1997-11-21 22:00:46 +03:00
|
|
|
if (LS->iflevel > 0)
|
1998-05-27 17:08:34 +04:00
|
|
|
luaX_error(LS, "input ends inside a $if");
|
|
|
|
return EOS;
|
1997-04-02 01:23:20 +04:00
|
|
|
|
|
|
|
default:
|
1997-11-21 22:00:46 +03:00
|
|
|
if (LS->current != '_' && !isalpha(LS->current)) {
|
1997-12-17 23:48:58 +03:00
|
|
|
int c = LS->current;
|
1998-05-27 17:08:34 +04:00
|
|
|
if (iscntrl(c))
|
|
|
|
luaX_invalidchar(LS, c);
|
1997-11-21 22:00:46 +03:00
|
|
|
save_and_next(LS);
|
1997-12-17 23:48:58 +03:00
|
|
|
return c;
|
1997-07-01 23:32:41 +04:00
|
|
|
}
|
|
|
|
else { /* identifier or reserved word */
|
|
|
|
TaggedString *ts;
|
|
|
|
do {
|
1997-11-21 22:00:46 +03:00
|
|
|
save_and_next(LS);
|
|
|
|
} while (isalnum(LS->current) || LS->current == '_');
|
1998-12-27 23:25:20 +03:00
|
|
|
save('\0');
|
1997-12-17 23:48:58 +03:00
|
|
|
ts = luaS_new(L->Mbuffbase);
|
1998-12-27 23:25:20 +03:00
|
|
|
if (ts->head.marked >= FIRST_RESERVED)
|
1997-09-26 19:02:26 +04:00
|
|
|
return ts->head.marked; /* reserved word */
|
1998-05-27 17:08:34 +04:00
|
|
|
LS->seminfo.ts = ts;
|
1997-07-01 23:32:41 +04:00
|
|
|
return NAME;
|
|
|
|
}
|
1993-12-23 00:15:16 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
1996-05-30 18:04:07 +04:00
|
|
|
|