Browse Source

added a few functions, and I think fixed a few things

master
Marrub 6 years ago
parent
commit
cdf32f3453
3 changed files with 49 additions and 5 deletions
  1. +10
    -0
      lua/tokenizer.lua
  2. +37
    -5
      src/lt.c
  3. +2
    -0
      src/lt.h

+ 10
- 0
lua/tokenizer.lua View File

@@ -70,7 +70,9 @@ char *LT_ReadNumber(void);
void LT_ReadString(LT_Token *tk, char term);
char *LT_Escaper(char *str, size_t pos, char escape);
LT_Token LT_GetToken(void);
char *LT_ReadLiteral(void);
void LT_SkipWhite(void);
void LT_SkipWhite2(void);
]])

local pReturn
@@ -141,6 +143,10 @@ function tokenizer:getToken()
return lt
end

function tokenizer:readLiteral()
return ffi.string(loveToken.LT_ReadLiteral())
end

function tokenizer:setPos(newPos)
loveToken.LT_SetPos(newPos)
tokenizer:checkError()
@@ -150,4 +156,8 @@ function tokenizer:skipWhite()
loveToken.LT_SkipWhite()
end

function tokenizer:skipWhite2()
loveToken.LT_SkipWhite2()
end

return tokenizer

+ 37
- 5
src/lt.c View File

@@ -396,6 +396,8 @@ void LT_Quit()
}
#endif
LT_CloseFile();
#ifndef __GDCC__
gbRover = gbHead;
@@ -514,7 +516,7 @@ char *LT_ReadNumber()
{
c = fgetc(parseFile);
if(!isalnum(c))
if(!isalnum(c) && c != '.')
{
ungetc(c, parseFile);
break;
@@ -625,7 +627,7 @@ void LT_ReadString(LT_Token *tk, char term)
char *LT_Escaper(char *str, size_t pos, char escape)
{
unsigned i;
LT_BOOL exitloop;
LT_BOOL exitloop = LT_FALSE;
switch(escape)
{
@@ -639,7 +641,6 @@ char *LT_Escaper(char *str, size_t pos, char escape)
case 'v': str[pos] = '\v'; break;
case 'x': // [marrub] THIS ONE IS FUN
i = 0;
exitloop = LT_FALSE;
while(!exitloop)
{
int c = fgetc(parseFile);
@@ -739,7 +740,7 @@ LT_Token LT_GetToken()
}
}
tk.pos = ftell(parseFile);
tk.pos = ftell(parseFile) - 1;
switch(c)
{
@@ -1027,11 +1028,30 @@ LT_Token LT_GetToken()
tk.string[0] = c;
tk.string[1] = '\0';
LT_SetGarbage(tk.string);
tk.string = LT_SetGarbage(tk.string);
return tk;
}
char *LT_ReadLiteral()
{
size_t i = 0;
int c;
char *str = LT_Alloc(4096);
while(LT_TRUE)
{
c = fgetc(parseFile);
if(c == '\r' || c == '\n' || c == EOF) break;
str[i++] = c;
}
str[i++] = '\0';
return LT_SetGarbage(LT_ReAlloc(str, i));
}
void LT_SkipWhite()
{
char c = fgetc(parseFile);
@@ -1043,3 +1063,15 @@ void LT_SkipWhite()
ungetc(c, parseFile);
}
void LT_SkipWhite2()
{
char c = fgetc(parseFile);
while(isspace(c) && c != EOF && c != '\r' && c != '\n')
{
c = fgetc(parseFile);
}
ungetc(c, parseFile);
}

+ 2
- 0
src/lt.h View File

@@ -153,7 +153,9 @@ LT_DLLEXPORT char *LT_EXPORT LT_ReadNumber(void);
LT_DLLEXPORT void LT_EXPORT LT_ReadString(LT_Token *tk, char term);
LT_DLLEXPORT char *LT_EXPORT LT_Escaper(char *str, size_t pos, char escape);
LT_DLLEXPORT LT_Token LT_EXPORT LT_GetToken(void);
LT_DLLEXPORT char *LT_EXPORT LT_ReadLiteral(void);
LT_DLLEXPORT void LT_EXPORT LT_SkipWhite(void);
LT_DLLEXPORT void LT_EXPORT LT_SkipWhite2(void);
#ifdef __cplusplus
}


Loading…
Cancel
Save