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