Archived
1
0

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

This commit is contained in:
Marrub 2015-08-24 07:10:25 -04:00
parent 188e71ccda
commit cdf32f3453
3 changed files with 49 additions and 5 deletions

View File

@ -70,7 +70,9 @@ char *LT_ReadNumber(void);
void LT_ReadString(LT_Token *tk, char term); void LT_ReadString(LT_Token *tk, char term);
char *LT_Escaper(char *str, size_t pos, char escape); char *LT_Escaper(char *str, size_t pos, char escape);
LT_Token LT_GetToken(void); LT_Token LT_GetToken(void);
char *LT_ReadLiteral(void);
void LT_SkipWhite(void); void LT_SkipWhite(void);
void LT_SkipWhite2(void);
]]) ]])
local pReturn local pReturn
@ -141,6 +143,10 @@ function tokenizer:getToken()
return lt return lt
end end
function tokenizer:readLiteral()
return ffi.string(loveToken.LT_ReadLiteral())
end
function tokenizer:setPos(newPos) function tokenizer:setPos(newPos)
loveToken.LT_SetPos(newPos) loveToken.LT_SetPos(newPos)
tokenizer:checkError() tokenizer:checkError()
@ -150,4 +156,8 @@ function tokenizer:skipWhite()
loveToken.LT_SkipWhite() loveToken.LT_SkipWhite()
end end
function tokenizer:skipWhite2()
loveToken.LT_SkipWhite2()
end
return tokenizer return tokenizer

View File

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

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 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 char *LT_EXPORT LT_Escaper(char *str, size_t pos, char escape);
LT_DLLEXPORT LT_Token LT_EXPORT LT_GetToken(void); 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_SkipWhite(void);
LT_DLLEXPORT void LT_EXPORT LT_SkipWhite2(void);
#ifdef __cplusplus #ifdef __cplusplus
} }