project_files/Android-build/SDL-android-project/jni/lua-5.1.4/llex.c
author Xeli
Sat, 16 Jul 2011 17:00:47 +0200
branchhedgeroid
changeset 5444 2b5eebaa31ff
permissions -rw-r--r--
Added support for LUA
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
5444
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
     1
/*
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
     2
** $Id: llex.c,v 2.20.1.1 2007/12/27 13:02:25 roberto Exp $
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
     3
** Lexical Analyzer
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
     4
** See Copyright Notice in lua.h
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
     5
*/
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
     6
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
     7
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
     8
#include <ctype.h>
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
     9
#include <locale.h>
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
    10
#include <string.h>
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
    11
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
    12
#define llex_c
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
    13
#define LUA_CORE
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
    14
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
    15
#include "lua.h"
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
    16
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
    17
#include "ldo.h"
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
    18
#include "llex.h"
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
    19
#include "lobject.h"
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
    20
#include "lparser.h"
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
    21
#include "lstate.h"
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
    22
#include "lstring.h"
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
    23
#include "ltable.h"
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
    24
#include "lzio.h"
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
    25
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
    26
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
    27
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
    28
#define next(ls) (ls->current = zgetc(ls->z))
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
    29
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
    30
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
    31
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
    32
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
    33
#define currIsNewline(ls)	(ls->current == '\n' || ls->current == '\r')
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
    34
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
    35
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
    36
/* ORDER RESERVED */
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
    37
const char *const luaX_tokens [] = {
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
    38
    "and", "break", "do", "else", "elseif",
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
    39
    "end", "false", "for", "function", "if",
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
    40
    "in", "local", "nil", "not", "or", "repeat",
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
    41
    "return", "then", "true", "until", "while",
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
    42
    "..", "...", "==", ">=", "<=", "~=",
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
    43
    "<number>", "<name>", "<string>", "<eof>",
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
    44
    NULL
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
    45
};
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
    46
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
    47
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
    48
#define save_and_next(ls) (save(ls, ls->current), next(ls))
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
    49
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
    50
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
    51
static void save (LexState *ls, int c) {
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
    52
  Mbuffer *b = ls->buff;
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
    53
  if (b->n + 1 > b->buffsize) {
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
    54
    size_t newsize;
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
    55
    if (b->buffsize >= MAX_SIZET/2)
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
    56
      luaX_lexerror(ls, "lexical element too long", 0);
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
    57
    newsize = b->buffsize * 2;
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
    58
    luaZ_resizebuffer(ls->L, b, newsize);
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
    59
  }
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
    60
  b->buffer[b->n++] = cast(char, c);
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
    61
}
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
    62
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
    63
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
    64
void luaX_init (lua_State *L) {
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
    65
  int i;
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
    66
  for (i=0; i<NUM_RESERVED; i++) {
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
    67
    TString *ts = luaS_new(L, luaX_tokens[i]);
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
    68
    luaS_fix(ts);  /* reserved words are never collected */
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
    69
    lua_assert(strlen(luaX_tokens[i])+1 <= TOKEN_LEN);
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
    70
    ts->tsv.reserved = cast_byte(i+1);  /* reserved word */
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
    71
  }
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
    72
}
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
    73
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
    74
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
    75
#define MAXSRC          80
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
    76
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
    77
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
    78
const char *luaX_token2str (LexState *ls, int token) {
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
    79
  if (token < FIRST_RESERVED) {
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
    80
    lua_assert(token == cast(unsigned char, token));
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
    81
    return (iscntrl(token)) ? luaO_pushfstring(ls->L, "char(%d)", token) :
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
    82
                              luaO_pushfstring(ls->L, "%c", token);
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
    83
  }
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
    84
  else
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
    85
    return luaX_tokens[token-FIRST_RESERVED];
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
    86
}
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
    87
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
    88
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
    89
static const char *txtToken (LexState *ls, int token) {
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
    90
  switch (token) {
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
    91
    case TK_NAME:
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
    92
    case TK_STRING:
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
    93
    case TK_NUMBER:
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
    94
      save(ls, '\0');
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
    95
      return luaZ_buffer(ls->buff);
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
    96
    default:
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
    97
      return luaX_token2str(ls, token);
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
    98
  }
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
    99
}
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   100
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   101
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   102
void luaX_lexerror (LexState *ls, const char *msg, int token) {
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   103
  char buff[MAXSRC];
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   104
  luaO_chunkid(buff, getstr(ls->source), MAXSRC);
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   105
  msg = luaO_pushfstring(ls->L, "%s:%d: %s", buff, ls->linenumber, msg);
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   106
  if (token)
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   107
    luaO_pushfstring(ls->L, "%s near " LUA_QS, msg, txtToken(ls, token));
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   108
  luaD_throw(ls->L, LUA_ERRSYNTAX);
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   109
}
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   110
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   111
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   112
void luaX_syntaxerror (LexState *ls, const char *msg) {
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   113
  luaX_lexerror(ls, msg, ls->t.token);
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   114
}
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   115
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   116
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   117
TString *luaX_newstring (LexState *ls, const char *str, size_t l) {
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   118
  lua_State *L = ls->L;
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   119
  TString *ts = luaS_newlstr(L, str, l);
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   120
  TValue *o = luaH_setstr(L, ls->fs->h, ts);  /* entry for `str' */
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   121
  if (ttisnil(o))
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   122
    setbvalue(o, 1);  /* make sure `str' will not be collected */
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   123
  return ts;
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   124
}
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   125
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   126
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   127
static void inclinenumber (LexState *ls) {
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   128
  int old = ls->current;
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   129
  lua_assert(currIsNewline(ls));
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   130
  next(ls);  /* skip `\n' or `\r' */
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   131
  if (currIsNewline(ls) && ls->current != old)
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   132
    next(ls);  /* skip `\n\r' or `\r\n' */
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   133
  if (++ls->linenumber >= MAX_INT)
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   134
    luaX_syntaxerror(ls, "chunk has too many lines");
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   135
}
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   136
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   137
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   138
void luaX_setinput (lua_State *L, LexState *ls, ZIO *z, TString *source) {
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   139
  ls->decpoint = '.';
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   140
  ls->L = L;
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   141
  ls->lookahead.token = TK_EOS;  /* no look-ahead token */
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   142
  ls->z = z;
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   143
  ls->fs = NULL;
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   144
  ls->linenumber = 1;
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   145
  ls->lastline = 1;
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   146
  ls->source = source;
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   147
  luaZ_resizebuffer(ls->L, ls->buff, LUA_MINBUFFER);  /* initialize buffer */
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   148
  next(ls);  /* read first char */
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   149
}
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   150
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   151
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   152
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   153
/*
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   154
** =======================================================
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   155
** LEXICAL ANALYZER
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   156
** =======================================================
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   157
*/
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   158
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   159
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   160
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   161
static int check_next (LexState *ls, const char *set) {
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   162
  if (!strchr(set, ls->current))
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   163
    return 0;
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   164
  save_and_next(ls);
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   165
  return 1;
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   166
}
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   167
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   168
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   169
static void buffreplace (LexState *ls, char from, char to) {
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   170
  size_t n = luaZ_bufflen(ls->buff);
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   171
  char *p = luaZ_buffer(ls->buff);
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   172
  while (n--)
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   173
    if (p[n] == from) p[n] = to;
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   174
}
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   175
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   176
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   177
static void trydecpoint (LexState *ls, SemInfo *seminfo) {
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   178
  /* format error: try to update decimal point separator */
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   179
  //struct lconv *cv = localeconv();
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   180
  char old = ls->decpoint;
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   181
  //ls->decpoint = (cv ? cv->decimal_point[0] : '.');
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   182
  ls->decpoint = '.';
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   183
  buffreplace(ls, old, ls->decpoint);  /* try updated decimal separator */
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   184
  if (!luaO_str2d(luaZ_buffer(ls->buff), &seminfo->r)) {
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   185
    /* format error with correct decimal point: no more options */
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   186
    buffreplace(ls, ls->decpoint, '.');  /* undo change (for error message) */
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   187
    luaX_lexerror(ls, "malformed number", TK_NUMBER);
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   188
  }
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   189
}
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   190
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   191
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   192
/* LUA_NUMBER */
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   193
static void read_numeral (LexState *ls, SemInfo *seminfo) {
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   194
  lua_assert(isdigit(ls->current));
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   195
  do {
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   196
    save_and_next(ls);
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   197
  } while (isdigit(ls->current) || ls->current == '.');
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   198
  if (check_next(ls, "Ee"))  /* `E'? */
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   199
    check_next(ls, "+-");  /* optional exponent sign */
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   200
  while (isalnum(ls->current) || ls->current == '_')
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   201
    save_and_next(ls);
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   202
  save(ls, '\0');
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   203
  buffreplace(ls, '.', ls->decpoint);  /* follow locale for decimal point */
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   204
  if (!luaO_str2d(luaZ_buffer(ls->buff), &seminfo->r))  /* format error? */
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   205
    trydecpoint(ls, seminfo); /* try to update decimal point separator */
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   206
}
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   207
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   208
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   209
static int skip_sep (LexState *ls) {
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   210
  int count = 0;
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   211
  int s = ls->current;
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   212
  lua_assert(s == '[' || s == ']');
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   213
  save_and_next(ls);
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   214
  while (ls->current == '=') {
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   215
    save_and_next(ls);
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   216
    count++;
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   217
  }
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   218
  return (ls->current == s) ? count : (-count) - 1;
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   219
}
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   220
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   221
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   222
static void read_long_string (LexState *ls, SemInfo *seminfo, int sep) {
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   223
  int cont = 0;
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   224
  (void)(cont);  /* avoid warnings when `cont' is not used */
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   225
  save_and_next(ls);  /* skip 2nd `[' */
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   226
  if (currIsNewline(ls))  /* string starts with a newline? */
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   227
    inclinenumber(ls);  /* skip it */
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   228
  for (;;) {
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   229
    switch (ls->current) {
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   230
      case EOZ:
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   231
        luaX_lexerror(ls, (seminfo) ? "unfinished long string" :
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   232
                                   "unfinished long comment", TK_EOS);
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   233
        break;  /* to avoid warnings */
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   234
#if defined(LUA_COMPAT_LSTR)
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   235
      case '[': {
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   236
        if (skip_sep(ls) == sep) {
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   237
          save_and_next(ls);  /* skip 2nd `[' */
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   238
          cont++;
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   239
#if LUA_COMPAT_LSTR == 1
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   240
          if (sep == 0)
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   241
            luaX_lexerror(ls, "nesting of [[...]] is deprecated", '[');
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   242
#endif
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   243
        }
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   244
        break;
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   245
      }
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   246
#endif
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   247
      case ']': {
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   248
        if (skip_sep(ls) == sep) {
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   249
          save_and_next(ls);  /* skip 2nd `]' */
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   250
#if defined(LUA_COMPAT_LSTR) && LUA_COMPAT_LSTR == 2
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   251
          cont--;
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   252
          if (sep == 0 && cont >= 0) break;
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   253
#endif
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   254
          goto endloop;
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   255
        }
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   256
        break;
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   257
      }
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   258
      case '\n':
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   259
      case '\r': {
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   260
        save(ls, '\n');
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   261
        inclinenumber(ls);
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   262
        if (!seminfo) luaZ_resetbuffer(ls->buff);  /* avoid wasting space */
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   263
        break;
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   264
      }
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   265
      default: {
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   266
        if (seminfo) save_and_next(ls);
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   267
        else next(ls);
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   268
      }
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   269
    }
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   270
  } endloop:
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   271
  if (seminfo)
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   272
    seminfo->ts = luaX_newstring(ls, luaZ_buffer(ls->buff) + (2 + sep),
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   273
                                     luaZ_bufflen(ls->buff) - 2*(2 + sep));
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   274
}
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   275
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   276
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   277
static void read_string (LexState *ls, int del, SemInfo *seminfo) {
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   278
  save_and_next(ls);
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   279
  while (ls->current != del) {
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   280
    switch (ls->current) {
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   281
      case EOZ:
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   282
        luaX_lexerror(ls, "unfinished string", TK_EOS);
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   283
        continue;  /* to avoid warnings */
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   284
      case '\n':
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   285
      case '\r':
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   286
        luaX_lexerror(ls, "unfinished string", TK_STRING);
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   287
        continue;  /* to avoid warnings */
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   288
      case '\\': {
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   289
        int c;
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   290
        next(ls);  /* do not save the `\' */
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   291
        switch (ls->current) {
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   292
          case 'a': c = '\a'; break;
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   293
          case 'b': c = '\b'; break;
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   294
          case 'f': c = '\f'; break;
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   295
          case 'n': c = '\n'; break;
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   296
          case 'r': c = '\r'; break;
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   297
          case 't': c = '\t'; break;
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   298
          case 'v': c = '\v'; break;
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   299
          case '\n':  /* go through */
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   300
          case '\r': save(ls, '\n'); inclinenumber(ls); continue;
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   301
          case EOZ: continue;  /* will raise an error next loop */
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   302
          default: {
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   303
            if (!isdigit(ls->current))
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   304
              save_and_next(ls);  /* handles \\, \", \', and \? */
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   305
            else {  /* \xxx */
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   306
              int i = 0;
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   307
              c = 0;
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   308
              do {
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   309
                c = 10*c + (ls->current-'0');
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   310
                next(ls);
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   311
              } while (++i<3 && isdigit(ls->current));
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   312
              if (c > UCHAR_MAX)
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   313
                luaX_lexerror(ls, "escape sequence too large", TK_STRING);
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   314
              save(ls, c);
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   315
            }
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   316
            continue;
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   317
          }
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   318
        }
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   319
        save(ls, c);
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   320
        next(ls);
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   321
        continue;
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   322
      }
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   323
      default:
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   324
        save_and_next(ls);
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   325
    }
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   326
  }
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   327
  save_and_next(ls);  /* skip delimiter */
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   328
  seminfo->ts = luaX_newstring(ls, luaZ_buffer(ls->buff) + 1,
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   329
                                   luaZ_bufflen(ls->buff) - 2);
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   330
}
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   331
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   332
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   333
static int llex (LexState *ls, SemInfo *seminfo) {
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   334
  luaZ_resetbuffer(ls->buff);
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   335
  for (;;) {
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   336
    switch (ls->current) {
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   337
      case '\n':
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   338
      case '\r': {
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   339
        inclinenumber(ls);
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   340
        continue;
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   341
      }
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   342
      case '-': {
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   343
        next(ls);
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   344
        if (ls->current != '-') return '-';
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   345
        /* else is a comment */
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   346
        next(ls);
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   347
        if (ls->current == '[') {
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   348
          int sep = skip_sep(ls);
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   349
          luaZ_resetbuffer(ls->buff);  /* `skip_sep' may dirty the buffer */
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   350
          if (sep >= 0) {
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   351
            read_long_string(ls, NULL, sep);  /* long comment */
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   352
            luaZ_resetbuffer(ls->buff);
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   353
            continue;
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   354
          }
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   355
        }
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   356
        /* else short comment */
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   357
        while (!currIsNewline(ls) && ls->current != EOZ)
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   358
          next(ls);
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   359
        continue;
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   360
      }
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   361
      case '[': {
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   362
        int sep = skip_sep(ls);
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   363
        if (sep >= 0) {
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   364
          read_long_string(ls, seminfo, sep);
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   365
          return TK_STRING;
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   366
        }
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   367
        else if (sep == -1) return '[';
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   368
        else luaX_lexerror(ls, "invalid long string delimiter", TK_STRING);
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   369
      }
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   370
      case '=': {
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   371
        next(ls);
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   372
        if (ls->current != '=') return '=';
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   373
        else { next(ls); return TK_EQ; }
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   374
      }
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   375
      case '<': {
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   376
        next(ls);
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   377
        if (ls->current != '=') return '<';
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   378
        else { next(ls); return TK_LE; }
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   379
      }
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   380
      case '>': {
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   381
        next(ls);
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   382
        if (ls->current != '=') return '>';
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   383
        else { next(ls); return TK_GE; }
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   384
      }
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   385
      case '~': {
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   386
        next(ls);
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   387
        if (ls->current != '=') return '~';
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   388
        else { next(ls); return TK_NE; }
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   389
      }
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   390
      case '"':
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   391
      case '\'': {
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   392
        read_string(ls, ls->current, seminfo);
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   393
        return TK_STRING;
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   394
      }
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   395
      case '.': {
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   396
        save_and_next(ls);
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   397
        if (check_next(ls, ".")) {
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   398
          if (check_next(ls, "."))
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   399
            return TK_DOTS;   /* ... */
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   400
          else return TK_CONCAT;   /* .. */
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   401
        }
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   402
        else if (!isdigit(ls->current)) return '.';
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   403
        else {
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   404
          read_numeral(ls, seminfo);
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   405
          return TK_NUMBER;
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   406
        }
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   407
      }
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   408
      case EOZ: {
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   409
        return TK_EOS;
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   410
      }
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   411
      default: {
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   412
        if (isspace(ls->current)) {
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   413
          lua_assert(!currIsNewline(ls));
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   414
          next(ls);
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   415
          continue;
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   416
        }
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   417
        else if (isdigit(ls->current)) {
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   418
          read_numeral(ls, seminfo);
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   419
          return TK_NUMBER;
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   420
        }
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   421
        else if (isalpha(ls->current) || ls->current == '_') {
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   422
          /* identifier or reserved word */
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   423
          TString *ts;
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   424
          do {
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   425
            save_and_next(ls);
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   426
          } while (isalnum(ls->current) || ls->current == '_');
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   427
          ts = luaX_newstring(ls, luaZ_buffer(ls->buff),
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   428
                                  luaZ_bufflen(ls->buff));
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   429
          if (ts->tsv.reserved > 0)  /* reserved word? */
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   430
            return ts->tsv.reserved - 1 + FIRST_RESERVED;
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   431
          else {
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   432
            seminfo->ts = ts;
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   433
            return TK_NAME;
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   434
          }
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   435
        }
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   436
        else {
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   437
          int c = ls->current;
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   438
          next(ls);
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   439
          return c;  /* single-char tokens (+ - / ...) */
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   440
        }
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   441
      }
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   442
    }
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   443
  }
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   444
}
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   445
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   446
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   447
void luaX_next (LexState *ls) {
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   448
  ls->lastline = ls->linenumber;
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   449
  if (ls->lookahead.token != TK_EOS) {  /* is there a look-ahead token? */
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   450
    ls->t = ls->lookahead;  /* use this one */
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   451
    ls->lookahead.token = TK_EOS;  /* and discharge it */
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   452
  }
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   453
  else
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   454
    ls->t.token = llex(ls, &ls->t.seminfo);  /* read next token */
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   455
}
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   456
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   457
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   458
void luaX_lookahead (LexState *ls) {
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   459
  lua_assert(ls->lookahead.token == TK_EOS);
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   460
  ls->lookahead.token = llex(ls, &ls->lookahead.seminfo);
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   461
}
2b5eebaa31ff Added support for LUA
Xeli
parents:
diff changeset
   462