misc/liblua/llex.c
author sheepluva
Wed, 17 Apr 2013 14:57:56 +0200
branch0.9.19
changeset 8902 a94c074fd483
parent 6039 d75329716a02
child 10017 de822cd3df3a
permissions -rw-r--r--
fix for issue #599: "Change graphics size settings to use qspinbox"? somebody ask unC0Rr if that's what he wanted :p
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 */
6039
d75329716a02 Removed the need for duplicate libraries, the android build now uses lua, freetype and tremor from misc/
Xeli
parents: 2812
diff changeset
   179
#ifndef ANDROID
2812
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   180
  struct lconv *cv = localeconv();
6039
d75329716a02 Removed the need for duplicate libraries, the android build now uses lua, freetype and tremor from misc/
Xeli
parents: 2812
diff changeset
   181
#endif
2812
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   182
  char old = ls->decpoint;
6039
d75329716a02 Removed the need for duplicate libraries, the android build now uses lua, freetype and tremor from misc/
Xeli
parents: 2812
diff changeset
   183
#ifdef ANDROID
d75329716a02 Removed the need for duplicate libraries, the android build now uses lua, freetype and tremor from misc/
Xeli
parents: 2812
diff changeset
   184
  ls->decpoint = '.';
d75329716a02 Removed the need for duplicate libraries, the android build now uses lua, freetype and tremor from misc/
Xeli
parents: 2812
diff changeset
   185
#else
2812
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   186
  ls->decpoint = (cv ? cv->decimal_point[0] : '.');
6039
d75329716a02 Removed the need for duplicate libraries, the android build now uses lua, freetype and tremor from misc/
Xeli
parents: 2812
diff changeset
   187
#endif
2812
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   188
  buffreplace(ls, old, ls->decpoint);  /* try updated decimal separator */
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   189
  if (!luaO_str2d(luaZ_buffer(ls->buff), &seminfo->r)) {
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   190
    /* format error with correct decimal point: no more options */
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   191
    buffreplace(ls, ls->decpoint, '.');  /* undo change (for error message) */
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   192
    luaX_lexerror(ls, "malformed number", TK_NUMBER);
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   193
  }
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   194
}
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   195
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   196
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   197
/* LUA_NUMBER */
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   198
static void read_numeral (LexState *ls, SemInfo *seminfo) {
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   199
  lua_assert(isdigit(ls->current));
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   200
  do {
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   201
    save_and_next(ls);
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   202
  } while (isdigit(ls->current) || ls->current == '.');
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   203
  if (check_next(ls, "Ee"))  /* `E'? */
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   204
    check_next(ls, "+-");  /* optional exponent sign */
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   205
  while (isalnum(ls->current) || ls->current == '_')
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   206
    save_and_next(ls);
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   207
  save(ls, '\0');
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   208
  buffreplace(ls, '.', ls->decpoint);  /* follow locale for decimal point */
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   209
  if (!luaO_str2d(luaZ_buffer(ls->buff), &seminfo->r))  /* format error? */
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   210
    trydecpoint(ls, seminfo); /* try to update decimal point separator */
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   211
}
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   212
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   213
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   214
static int skip_sep (LexState *ls) {
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   215
  int count = 0;
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   216
  int s = ls->current;
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   217
  lua_assert(s == '[' || s == ']');
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   218
  save_and_next(ls);
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   219
  while (ls->current == '=') {
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   220
    save_and_next(ls);
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   221
    count++;
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   222
  }
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   223
  return (ls->current == s) ? count : (-count) - 1;
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   224
}
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   225
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   226
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   227
static void read_long_string (LexState *ls, SemInfo *seminfo, int sep) {
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   228
  int cont = 0;
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   229
  (void)(cont);  /* avoid warnings when `cont' is not used */
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   230
  save_and_next(ls);  /* skip 2nd `[' */
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   231
  if (currIsNewline(ls))  /* string starts with a newline? */
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   232
    inclinenumber(ls);  /* skip it */
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   233
  for (;;) {
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   234
    switch (ls->current) {
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   235
      case EOZ:
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   236
        luaX_lexerror(ls, (seminfo) ? "unfinished long string" :
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   237
                                   "unfinished long comment", TK_EOS);
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   238
        break;  /* to avoid warnings */
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   239
#if defined(LUA_COMPAT_LSTR)
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   240
      case '[': {
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   241
        if (skip_sep(ls) == sep) {
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   242
          save_and_next(ls);  /* skip 2nd `[' */
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   243
          cont++;
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   244
#if LUA_COMPAT_LSTR == 1
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   245
          if (sep == 0)
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   246
            luaX_lexerror(ls, "nesting of [[...]] is deprecated", '[');
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   247
#endif
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   248
        }
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   249
        break;
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   250
      }
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   251
#endif
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   252
      case ']': {
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   253
        if (skip_sep(ls) == sep) {
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   254
          save_and_next(ls);  /* skip 2nd `]' */
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   255
#if defined(LUA_COMPAT_LSTR) && LUA_COMPAT_LSTR == 2
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   256
          cont--;
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   257
          if (sep == 0 && cont >= 0) break;
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   258
#endif
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   259
          goto endloop;
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   260
        }
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   261
        break;
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   262
      }
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   263
      case '\n':
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   264
      case '\r': {
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   265
        save(ls, '\n');
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   266
        inclinenumber(ls);
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   267
        if (!seminfo) luaZ_resetbuffer(ls->buff);  /* avoid wasting space */
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   268
        break;
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   269
      }
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   270
      default: {
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   271
        if (seminfo) save_and_next(ls);
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   272
        else next(ls);
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
  } endloop:
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   276
  if (seminfo)
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   277
    seminfo->ts = luaX_newstring(ls, luaZ_buffer(ls->buff) + (2 + sep),
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   278
                                     luaZ_bufflen(ls->buff) - 2*(2 + sep));
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   279
}
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   280
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   281
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   282
static void read_string (LexState *ls, int del, SemInfo *seminfo) {
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   283
  save_and_next(ls);
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   284
  while (ls->current != del) {
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   285
    switch (ls->current) {
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   286
      case EOZ:
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   287
        luaX_lexerror(ls, "unfinished string", TK_EOS);
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   288
        continue;  /* to avoid warnings */
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   289
      case '\n':
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   290
      case '\r':
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   291
        luaX_lexerror(ls, "unfinished string", TK_STRING);
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   292
        continue;  /* to avoid warnings */
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   293
      case '\\': {
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   294
        int c;
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   295
        next(ls);  /* do not save the `\' */
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   296
        switch (ls->current) {
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   297
          case 'a': c = '\a'; break;
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   298
          case 'b': c = '\b'; break;
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   299
          case 'f': c = '\f'; break;
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   300
          case 'n': c = '\n'; break;
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   301
          case 'r': c = '\r'; break;
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   302
          case 't': c = '\t'; break;
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   303
          case 'v': c = '\v'; break;
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   304
          case '\n':  /* go through */
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   305
          case '\r': save(ls, '\n'); inclinenumber(ls); continue;
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   306
          case EOZ: continue;  /* will raise an error next loop */
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   307
          default: {
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   308
            if (!isdigit(ls->current))
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   309
              save_and_next(ls);  /* handles \\, \", \', and \? */
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   310
            else {  /* \xxx */
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   311
              int i = 0;
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   312
              c = 0;
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   313
              do {
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   314
                c = 10*c + (ls->current-'0');
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   315
                next(ls);
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   316
              } while (++i<3 && isdigit(ls->current));
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   317
              if (c > UCHAR_MAX)
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   318
                luaX_lexerror(ls, "escape sequence too large", TK_STRING);
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   319
              save(ls, c);
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   320
            }
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   321
            continue;
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   322
          }
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   323
        }
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   324
        save(ls, c);
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   325
        next(ls);
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   326
        continue;
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   327
      }
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   328
      default:
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   329
        save_and_next(ls);
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
  save_and_next(ls);  /* skip delimiter */
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   333
  seminfo->ts = luaX_newstring(ls, luaZ_buffer(ls->buff) + 1,
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   334
                                   luaZ_bufflen(ls->buff) - 2);
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   335
}
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   336
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   337
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   338
static int llex (LexState *ls, SemInfo *seminfo) {
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   339
  luaZ_resetbuffer(ls->buff);
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   340
  for (;;) {
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   341
    switch (ls->current) {
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   342
      case '\n':
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   343
      case '\r': {
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   344
        inclinenumber(ls);
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   345
        continue;
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   346
      }
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   347
      case '-': {
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   348
        next(ls);
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   349
        if (ls->current != '-') return '-';
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   350
        /* else is a comment */
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   351
        next(ls);
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   352
        if (ls->current == '[') {
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   353
          int sep = skip_sep(ls);
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   354
          luaZ_resetbuffer(ls->buff);  /* `skip_sep' may dirty the buffer */
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   355
          if (sep >= 0) {
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   356
            read_long_string(ls, NULL, sep);  /* long comment */
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   357
            luaZ_resetbuffer(ls->buff);
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
        }
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   361
        /* else short comment */
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   362
        while (!currIsNewline(ls) && ls->current != EOZ)
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   363
          next(ls);
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   364
        continue;
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   365
      }
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   366
      case '[': {
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   367
        int sep = skip_sep(ls);
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   368
        if (sep >= 0) {
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   369
          read_long_string(ls, seminfo, sep);
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   370
          return TK_STRING;
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   371
        }
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   372
        else if (sep == -1) return '[';
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   373
        else luaX_lexerror(ls, "invalid long string delimiter", TK_STRING);
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   374
      }
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   375
      case '=': {
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   376
        next(ls);
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   377
        if (ls->current != '=') return '=';
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   378
        else { next(ls); return TK_EQ; }
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   379
      }
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   380
      case '<': {
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   381
        next(ls);
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   382
        if (ls->current != '=') return '<';
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   383
        else { next(ls); return TK_LE; }
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   384
      }
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   385
      case '>': {
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   386
        next(ls);
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   387
        if (ls->current != '=') return '>';
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   388
        else { next(ls); return TK_GE; }
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   389
      }
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
        next(ls);
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   392
        if (ls->current != '=') return '~';
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   393
        else { next(ls); return TK_NE; }
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   394
      }
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   395
      case '"':
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   396
      case '\'': {
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   397
        read_string(ls, ls->current, seminfo);
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   398
        return TK_STRING;
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   399
      }
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   400
      case '.': {
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   401
        save_and_next(ls);
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   402
        if (check_next(ls, ".")) {
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   403
          if (check_next(ls, "."))
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   404
            return TK_DOTS;   /* ... */
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   405
          else return TK_CONCAT;   /* .. */
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   406
        }
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   407
        else if (!isdigit(ls->current)) return '.';
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   408
        else {
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   409
          read_numeral(ls, seminfo);
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   410
          return TK_NUMBER;
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   411
        }
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   412
      }
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   413
      case EOZ: {
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   414
        return TK_EOS;
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   415
      }
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   416
      default: {
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   417
        if (isspace(ls->current)) {
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   418
          lua_assert(!currIsNewline(ls));
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   419
          next(ls);
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   420
          continue;
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   421
        }
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   422
        else if (isdigit(ls->current)) {
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   423
          read_numeral(ls, seminfo);
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   424
          return TK_NUMBER;
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   425
        }
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   426
        else if (isalpha(ls->current) || ls->current == '_') {
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   427
          /* identifier or reserved word */
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   428
          TString *ts;
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   429
          do {
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   430
            save_and_next(ls);
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   431
          } while (isalnum(ls->current) || ls->current == '_');
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   432
          ts = luaX_newstring(ls, luaZ_buffer(ls->buff),
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   433
                                  luaZ_bufflen(ls->buff));
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   434
          if (ts->tsv.reserved > 0)  /* reserved word? */
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   435
            return ts->tsv.reserved - 1 + FIRST_RESERVED;
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   436
          else {
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   437
            seminfo->ts = ts;
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   438
            return TK_NAME;
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
        else {
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   442
          int c = ls->current;
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   443
          next(ls);
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   444
          return c;  /* single-char tokens (+ - / ...) */
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   445
        }
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   446
      }
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   447
    }
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   448
  }
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   449
}
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   450
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   451
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   452
void luaX_next (LexState *ls) {
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   453
  ls->lastline = ls->linenumber;
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   454
  if (ls->lookahead.token != TK_EOS) {  /* is there a look-ahead token? */
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   455
    ls->t = ls->lookahead;  /* use this one */
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   456
    ls->lookahead.token = TK_EOS;  /* and discharge it */
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   457
  }
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   458
  else
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   459
    ls->t.token = llex(ls, &ls->t.seminfo);  /* read next token */
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   460
}
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   461
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   462
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   463
void luaX_lookahead (LexState *ls) {
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   464
  lua_assert(ls->lookahead.token == TK_EOS);
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   465
  ls->lookahead.token = llex(ls, &ls->lookahead.seminfo);
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   466
}
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   467