コード例 #1
0
ファイル: llex.c プロジェクト: TKr/Wive-ng-rt8186
/* LUA_NUMBER */
static void read_numeral (LexState *LS, int comma, SemInfo *seminfo) {
  size_t l = 0;
  checkbuffer(LS, l);
  if (comma) save(LS, '.', l);
  while (isdigit(LS->current)) {
    checkbuffer(LS, l);
    save_and_next(LS, l);
  }
  if (LS->current == '.') {
    save_and_next(LS, l);
    if (LS->current == '.') {
      save_and_next(LS, l);
      save(LS, '\0', l);
      luaX_lexerror(LS,
                 "ambiguous syntax (decimal point x string concatenation)",
                 TK_NUMBER);
    }
  }
  while (isdigit(LS->current)) {
    checkbuffer(LS, l);
    save_and_next(LS, l);
  }
  if (LS->current == 'e' || LS->current == 'E') {
    save_and_next(LS, l);  /* read `E' */
    if (LS->current == '+' || LS->current == '-')
      save_and_next(LS, l);  /* optional exponent sign */
    while (isdigit(LS->current)) {
      checkbuffer(LS, l);
      save_and_next(LS, l);
    }
  }
  save(LS, '\0', l);
  if (!luaO_str2d(luaZ_buffer(LS->buff), &seminfo->r))
    luaX_lexerror(LS, "malformed number", TK_NUMBER);
}
コード例 #2
0
ファイル: llex.c プロジェクト: TKr/Wive-ng-rt8186
static void read_string (LexState *LS, int del, SemInfo *seminfo) {
  size_t l = 0;
  checkbuffer(LS, l);
  save_and_next(LS, l);
  while (LS->current != del) {
    checkbuffer(LS, l);
    switch (LS->current) {
      case EOZ:
        save(LS, '\0', l);
        luaX_lexerror(LS, "unfinished string", TK_EOS);
        break;  /* to avoid warnings */
      case '\n':
        save(LS, '\0', l);
        luaX_lexerror(LS, "unfinished string", TK_STRING);
        break;  /* to avoid warnings */
      case '\\':
        next(LS);  /* do not save the `\' */
        switch (LS->current) {
          case 'a': save(LS, '\a', l); next(LS); break;
          case 'b': save(LS, '\b', l); next(LS); break;
          case 'f': save(LS, '\f', l); next(LS); break;
          case 'n': save(LS, '\n', l); next(LS); break;
          case 'r': save(LS, '\r', l); next(LS); break;
          case 't': save(LS, '\t', l); next(LS); break;
          case 'v': save(LS, '\v', l); next(LS); break;
          case '\n': save(LS, '\n', l); inclinenumber(LS); break;
          case EOZ: break;  /* will raise an error next loop */
          default: {
            if (!isdigit(LS->current))
              save_and_next(LS, l);  /* handles \\, \", \', and \? */
            else {  /* \xxx */
              int c = 0;
              int i = 0;
              do {
                c = 10*c + (LS->current-'0');
                next(LS);
              } while (++i<3 && isdigit(LS->current));
              if (c > UCHAR_MAX) {
                save(LS, '\0', l);
                luaX_lexerror(LS, "escape sequence too large", TK_STRING);
              }
              save(LS, c, l);
            }
          }
        }
        break;
      default:
        save_and_next(LS, l);
    }
  }
  save_and_next(LS, l);  /* skip delimiter */
  save(LS, '\0', l);
  seminfo->ts = luaS_newlstr(LS->L, luaZ_buffer(LS->buff) + 1, l - 3);
}
コード例 #3
0
ファイル: lparser.c プロジェクト: xiaofeng/Arcemu
static void errorlimit (FuncState *fs, int limit, const char *what) {
  const char *msg = (fs->f->linedefined == 0) ?
    luaO_pushfstring(fs->L, "main function has more than %d %s", limit, what) :
    luaO_pushfstring(fs->L, "function at line %d has more than %d %s",
                            fs->f->linedefined, limit, what);
  luaX_lexerror(fs->ls, msg, 0);
}
コード例 #4
0
static void save (LexState *ls, int c) {
  Mbuffer *b = ls->buff;
  if (b->n + 1 > b->buffsize) {
    size_t newsize;
    if (b->buffsize >= MAX_SIZET/2)
      luaX_lexerror(ls, "lexical element too long", 0);
    newsize = b->buffsize * 2;
    luaZ_resizebuffer(ls->L, b, newsize);
  }
  b->buffer[b->n++] = cast(char, c);
}
コード例 #5
0
ファイル: llex.c プロジェクト: LTears/rktotal
static void wsave (LexState *ls, int c) {
  Mbuffer *b = ls->buff;
  if (b->n + 2 > b->buffsize) {
    size_t newsize;
    if (b->buffsize >= MAX_SIZET/2)
      luaX_lexerror(ls, "lexical element too long", 0);
    newsize = b->buffsize * 4;
    luaZ_resizebuffer(ls->L, b, newsize);
  }
  *(lua_WChar*)(&b->buffer[b->n]) = cast(lua_WChar, c);
  b->n += 2;
}
コード例 #6
0
ファイル: llex.c プロジェクト: jjiezheng/pap_full
static void read_long_string (LexState *LS, SemInfo *seminfo) {
  int cont = 0;
  size_t l = 0;
  checkbuffer(LS, l);
  save(LS, '[', l);  /* save first `[' */
  save_and_next(LS, l);  /* pass the second `[' */
  if (LS->current == '\n')  /* string starts with a newline? */
    inclinenumber(LS);  /* skip it */
  for (;;) {
    checkbuffer(LS, l);
    switch (LS->current) {
      case EOZ:
        save(LS, '\0', l);
        luaX_lexerror(LS, (seminfo) ? "unfinished long string" :
                                   "unfinished long comment", TK_EOS);
        break;  /* to avoid warnings */
      case '[':
        save_and_next(LS, l);
        if (LS->current == '[') {
          cont++;
          save_and_next(LS, l);
        }
        continue;
      case ']':
        save_and_next(LS, l);
        if (LS->current == ']') {
          if (cont == 0) goto endloop;
          cont--;
          save_and_next(LS, l);
        }
        continue;
      case '\n':
        save(LS, '\n', l);
        inclinenumber(LS);
        if (!seminfo) l = 0;  /* reset buffer to avoid wasting space */
        continue;
      default:
        save_and_next(LS, l);
    }
  } endloop:
  save_and_next(LS, l);  /* skip the second `]' */
  save(LS, '\0', l);
  if (seminfo)
    seminfo->ts = luaS_newlstr(LS->L, luaZ_buffer(LS->buff) + 2, l - 5);
}
コード例 #7
0
ファイル: lparser.c プロジェクト: henryfung01/GameCode4
static int searchvar (FuncState *fs, TString *n) {
  int i;
  for (i=fs->nactvar-1; i >= 0; i--) {
#if LUA_EXT_CONTINUE
    if (n == getlocvar(fs, i).varname) {
      if (i >= fs->prohibitedloc) {
        BlockCnt *bl = fs->bl;
        int line;
        while (bl->continuelist == NO_JUMP)
          bl = bl->previous;
        line = fs->f->lineinfo[bl->continuelist];
        fs->ls->linenumber = fs->ls->lastline; /* Go back to the name token for the error message line number */
        luaX_lexerror(fs->ls, luaO_pushfstring(fs->L, "use of variable " LUA_QS " is not permitted in this context as its initialisation could have been skipped by the " LUA_QL("continue") " statement on line %d", n + 1, line), 0);
      }
      return i;
    }
#else
    if (n == getlocvar(fs, i).varname)
      return i;
#endif /* LUA_EXT_CONTINUE */
  }
  return -1;  /* not found */
}
コード例 #8
0
ファイル: lparser.c プロジェクト: xiaofeng/Arcemu
static void enterlevel (LexState *ls) {
  if (++ls->L->nCcalls > LUAI_MAXCCALLS)
	luaX_lexerror(ls, "chunk has too many syntax levels", 0);
}
コード例 #9
0
ファイル: llex.c プロジェクト: jjiezheng/pap_full
static void read_wstring (LexState *LS, int del, SemInfo *seminfo) {
  size_t l = 0;
  checkbuffer(LS, l * 2);
  wsave_and_next(LS, l);
  while (LS->current != del) {
    checkbuffer(LS, l * 2);
    switch (LS->current) {
      case EOZ:
        wsave(LS, '\0', l);
        luaX_lexerror(LS, "unfinished string", TK_EOS);
        break;  /* to avoid warnings */
      case '\n':
        wsave(LS, '\0', l);
        luaX_lexerror(LS, "unfinished string", TK_STRING);
        break;  /* to avoid warnings */
      case '\\':
        next(LS);  /* do not save the `\' */
        switch (LS->current) {
          case 'a': wsave(LS, '\a', l); next(LS); break;
          case 'b': wsave(LS, '\b', l); next(LS); break;
          case 'f': wsave(LS, '\f', l); next(LS); break;
          case 'n': wsave(LS, '\n', l); next(LS); break;
          case 'r': wsave(LS, '\r', l); next(LS); break;
          case 't': wsave(LS, '\t', l); next(LS); break;
          case 'v': wsave(LS, '\v', l); next(LS); break;
          case '\n': wsave(LS, '\n', l); inclinenumber(LS); break;
          case EOZ: break;  /* will raise an error next loop */
          case 'x': {
			  int ch;
			  next(LS);
			  ch = tolower(LS->current);
              if (!lex_isdigit(ch) && !(ch >= 'a' && ch <= 'f') )
		          save(LS, 'x', l);  /* handles \\, \", \', and \? */
			  else {  /* \xxx */
				  int c = 0;
				  int i = 0;
				  int numDigits = 4;
				  do {
					  ch = tolower(LS->current);
					  if (lex_isdigit(ch))
					    c = 16*c + (ch-'0');
					  else if (ch >= 'a' && ch <= 'f')
						c = 16*c + (ch-'a') + 10;
					  next(LS);
					  ch = tolower(LS->current);
				  } while (++i<numDigits && (lex_isdigit(ch) || (ch >= 'a' && ch <= 'f')));
				  wsave(LS, c, l);
			  }
			  break;
          }
          default: {
            if (!lex_isdigit(LS->current))
              wsave_and_next(LS, l);  /* handles \\, \", \', and \? */
            else {  /* \xxx */
              int c = 0;
              int i = 0;
              do {
                c = 10*c + (LS->current-'0');
                next(LS);
              } while (++i<3 && lex_isdigit(LS->current));
              if (c > UCHAR_MAX) {
                wsave(LS, '\0', l);
                luaX_lexerror(LS, "escape sequence too large", TK_STRING);
              }
              wsave(LS, c, l);
            }
          }
        }
        break;
      default:
        wsave_and_next(LS, l);
    }
  }
  wsave_and_next(LS, l);  /* skip delimiter */
  wsave(LS, '\0', l);
  seminfo->ts = luaS_newlwstr(LS->L, (const lua_WChar*)(luaZ_buffer(LS->buff) + 1 * 2), (l - 3 * 2) / 2);
}
コード例 #10
0
ファイル: llex.c プロジェクト: jjiezheng/pap_full
/* LUA_NUMBER */
static int read_numeral (LexState *LS, int period, SemInfo *seminfo) {
  int isReal = 0;
  int startsWithZero = LS->current == '0';
  size_t l = 0;
  checkbuffer(LS, l);
  if (period) {
	save(LS, '.', l);
	isReal = 1;
  }
  if (startsWithZero) {
	next(LS);
	if (LS->current == 'x') {
	  /* Process a hex number */
	  int ch = 0;
      int c = 0;
      int i = 0;
      int numDigits = 8;
	  next(LS);
      do {
        ch = tolower(LS->current);
        if (lex_isdigit(ch))
          c = 16*c + (ch-'0');
        else if (ch >= 'a' && ch <= 'f')
          c = 16*c + (ch-'a') + 10;
        next(LS);
        ch = tolower(LS->current);
      } while (++i<numDigits && (lex_isdigit(ch) || (ch >= 'a' && ch <= 'f')));
	  seminfo->r = c;
	  return TK_NUMBER;
	} else {
      checkbuffer(LS, 1);
      save(LS, '0', l);
	}
  }
  while (lex_isdigit(LS->current)) {
    checkbuffer(LS, l);
    save_and_next(LS, l);
  }
  if (LS->current == '.') {
    isReal = 1;
    save_and_next(LS, l);
    if (LS->current == '.') {
      save_and_next(LS, l);
      save(LS, '\0', l);
      luaX_lexerror(LS,
                 "ambiguous syntax (decimal point x string concatenation)",
                 TK_NUMBER);
    }
  }
  while (lex_isdigit(LS->current)) {
    checkbuffer(LS, l);
    save_and_next(LS, l);
  }
  if (LS->current == 'e' || LS->current == 'E') {
    isReal = 1;
    save_and_next(LS, l);  /* read `E' */
    if (LS->current == '+' || LS->current == '-')
      save_and_next(LS, l);  /* optional exponent sign */
    while (lex_isdigit(LS->current)) {
      checkbuffer(LS, l);
      save_and_next(LS, l);
    }
  }
  save(LS, '\0', l);
  if (isReal) {
    if (!luaO_str2d(luaZ_buffer(LS->buff), &seminfo->r))
      luaX_lexerror(LS, "malformed number", TK_NUMBER);
	return TK_NUMBER;
  } else {
    if (!luaO_str2d(luaZ_buffer(LS->buff), &seminfo->r))
      luaX_lexerror(LS, "malformed integer", TK_NUMBER);
	return TK_NUMBER;
  }
}