diff --git a/lua/tokenizer.lua b/lua/tokenizer.lua index e828665..e6183c9 100644 --- a/lua/tokenizer.lua +++ b/lua/tokenizer.lua @@ -35,6 +35,8 @@ typedef struct bool doConvert; const char *fromCode; const char *toCode; + const char *stringChars; + const char *charChars; // [marrub] heh } LT_InitInfo; typedef struct diff --git a/src/lt.c b/src/lt.c index edddd4a..1985a08 100644 --- a/src/lt.c +++ b/src/lt.c @@ -40,6 +40,12 @@ static LT_InitInfo info; static iconv_t icDesc; static bool assertError = false; static const char *assertString; +static char *stringChars, *charChars; + +static const char *errors[] = { + "LT_Error: Syntax error", + "LT_Error: Unknown operation" +}; char *LT_TkNames[] = { // [marrub] So, this was an interesting bug. This was completely misordered from the enum. @@ -53,11 +59,6 @@ char *LT_TkNames[] = { "TOK_Identi", "TOK_EOF", "TOK_ChrSeq" }; -static const char *errors[] = { - "LT_Error: Syntax error", - "LT_Error: Unknown operation" -}; - /* * Functions */ @@ -83,16 +84,6 @@ void LT_Init(LT_InitInfo initInfo) if(info.doConvert && info.fromCode != NULL && info.toCode != NULL) { - if(strcmp(info.fromCode, "UTF8")) - { - info.fromCode = "UTF-8"; - } - - if(strcmp(info.toCode, "UTF8")) - { - info.toCode = "UTF-8"; - } - icDesc = iconv_open(info.toCode, info.fromCode); if(icDesc == (iconv_t) -1) @@ -110,6 +101,62 @@ void LT_Init(LT_InitInfo initInfo) info.stripInvalid = false; } + if(info.stringChars != NULL) + { + int i; + + stringChars = malloc(6); + + for(i = 0; i < 6; i++) + { + char c = info.stringChars[i]; + + if(c != '\0') + { + stringChars[i] = c; + } + else + { + break; + } + } + + stringChars[i] = '\0'; + info.stringChars = NULL; // [marrub] don't use this after init + } + else + { + stringChars = "\""; + } + + if(info.charChars != NULL) + { + int i; + + charChars = malloc(6); + + for(i = 0; i < 6; i++) + { + char c = info.charChars[i]; + + if(c != '\0') + { + charChars[i] = c; + } + else + { + break; + } + } + + charChars[i] = '\0'; + info.charChars = NULL; // [marrub] don't use this after init + } + else + { + charChars = "'"; + } + gbHead = malloc(sizeof(LT_GarbageList)); gbHead->next = NULL; gbHead->ptr = NULL; @@ -124,6 +171,8 @@ void LT_Quit() iconv_close(icDesc); } + free(stringChars); + gbRover = gbHead; while(gbRover != NULL) @@ -538,19 +587,38 @@ LT_Token LT_GetToken() } return tk; - case '"': case '\'': - tk.string = LT_ReadString(c); + } + + for(size_t i = 0; i < 6;) + { + char cc = stringChars[i++]; - if(c == '"') + if(cc == '\0') { + break; + } + else if(c == cc) + { + tk.string = LT_ReadString(c); tk.token = LT_TkNames[TOK_String]; + return tk; } - else - { - tk.token = LT_TkNames[TOK_Charac]; - } + } + + for(size_t i = 0; i < 6;) + { + char cc = charChars[i++]; - return tk; + if(cc == '\0') + { + break; + } + else if(c == cc) + { + tk.string = LT_ReadString(c); + tk.token = LT_TkNames[TOK_Charac]; + return tk; + } } if(isdigit(c)) diff --git a/src/lt.h b/src/lt.h index 6095f54..59bbd20 100644 --- a/src/lt.h +++ b/src/lt.h @@ -72,6 +72,8 @@ typedef struct bool doConvert; const char *fromCode; const char *toCode; + const char *stringChars; + const char *charChars; // [marrub] heh } LT_InitInfo; typedef struct