From 169877976e6329bd2270d5d8a27806e97329219d Mon Sep 17 00:00:00 2001 From: "BADIM-PC\\Vadim" Date: Wed, 20 Dec 2017 20:53:19 +0300 Subject: [PATCH 01/10] single comments works --- src/code.c | 590 ++++++++++++++++++++++++++++++++--------------------- 1 file changed, 358 insertions(+), 232 deletions(-) diff --git a/src/code.c b/src/code.c index fa31e14..da3e90b 100644 --- a/src/code.c +++ b/src/code.c @@ -188,256 +188,382 @@ static void updateEditor(Code* code) static bool isLetter(char symbol) {return (symbol >= 'A' && symbol <= 'Z') || (symbol >= 'a' && symbol <= 'z') || (symbol == '_');} static bool isNumber(char symbol) {return (symbol >= '0' && symbol <= '9');} static bool isWord(char symbol) {return isLetter(symbol) || isNumber(symbol);} -static bool isDot(char symbol) {return (symbol == '.');} +// static bool isDot(char symbol) {return (symbol == '.');} -static void highlightStrings(Code* code, const char* text, u8* color, char separator) +// static void highlightStrings(Code* code, const char* text, u8* color, char separator) +// { +// char* start = SDL_strchr(text, separator); + +// if(start) +// { +// char* end = SDL_strchr(start + 1, separator); + +// if(end) +// { +// end++; +// u8* colorPtr = color + (start - text); + +// if(*colorPtr != getConfig()->theme.code.comment) +// memset(colorPtr, getConfig()->theme.code.string, end - start); + +// highlightStrings(code, end, color + (end - text), separator); +// } +// } +// } + +// static void highlightNumbers(Code* code, u8* color) +// { +// const char* text = code->src; +// const char* pointer = text; + +// while(*pointer) +// { +// char symbol = *pointer; + +// if(isLetter(symbol)) +// while(symbol && (isLetter(symbol) || isNumber(symbol) || isDot(symbol))) +// symbol = *++pointer; + +// const char* start = pointer; +// while(symbol && (isNumber(symbol) || isDot(symbol))) symbol = *++pointer; + +// if(!isLetter(symbol)) memset(color + (start - text), getConfig()->theme.code.number, pointer - start); + +// pointer++; +// } +// } + +// static void highlightWords(const char* text, u8* color, const char* const strings[], s32 count, u8 wordColor) +// { +// const char* pointer = text; + +// while(*pointer) +// { +// char symbol = *pointer; + +// const char* start = pointer; +// while(symbol && (isLetter(symbol) || isNumber(symbol))) +// symbol = *++pointer; + +// size_t size = pointer - start; + +// if(size) +// { +// for(s32 i = 0; i < count; i++) +// { +// const char* keyword = strings[i]; +// if(size == strlen(keyword) && memcmp(start, keyword, size) == 0) +// { +// memset(color + (start - text), wordColor, size); +// break; +// } +// } +// } + +// pointer++; +// } + +// } + +// static void highlightMoonKeywords(Code* code, u8* color) +// { +// const char* text = code->src; + +// static const char* const MoonKeywords [] = +// { +// "false", "true", "nil", "return", +// "break", "continue", "for", "while", +// "if", "else", "elseif", "unless", "switch", +// "when", "and", "or", "in", "do", +// "not", "super", "try", "catch", +// "with", "export", "import", "then", +// "from", "class", "extends", "new" +// }; + +// highlightWords(text, color, MoonKeywords, COUNT_OF(MoonKeywords), getConfig()->theme.code.keyword); +// } + +// static void highlightLuaKeywords(Code* code, u8* color) +// { +// const char* text = code->src; + +// static const char* const LuaKeywords [] = +// { +// "and", "break", "do", "else", "elseif", +// "end", "false", "for", "function", "goto", "if", +// "in", "local", "nil", "not", "or", "repeat", +// "return", "then", "true", "until", "while" +// }; + +// highlightWords(text, color, LuaKeywords, COUNT_OF(LuaKeywords), getConfig()->theme.code.keyword); +// } + +// static void highlightJsKeywords(Code* code, u8* color) +// { +// const char* text = code->src; + +// static const char* const JsKeywords [] = +// { +// "break", "do", "instanceof", "typeof", "case", "else", "new", +// "var", "catch", "finally", "return", "void", "continue", "for", +// "switch", "while", "debugger", "function", "this", "with", +// "default", "if", "throw", "delete", "in", "try", "const" +// }; + +// highlightWords(text, color, JsKeywords, COUNT_OF(JsKeywords), getConfig()->theme.code.keyword); +// } + +// static void highlightApi(Code* code, u8* color) +// { +// static const char* const ApiKeywords[] = API_KEYWORDS; + +// const char* text = code->src; +// highlightWords(text, color, ApiKeywords, COUNT_OF(ApiKeywords), getConfig()->theme.code.api); +// } + +// static void highlightNonChars(Code* code, u8* color) +// { +// const char* text = code->src; + +// while(*text) +// { +// if(*text <= 32) +// *color = getConfig()->theme.code.other; + +// text++; +// color++; +// } +// } + +// static void highlightSigns(Code* code, u8* color) +// { +// const char* text = code->src; + +// static const char* const LuaSigns [] = +// { +// "+", "-", "*", "/", "%", "^", "#", +// "&", "~", "|", "<<", ">>", "//", +// "==", "~=", "<=", ">=", "<", ">", "=", +// "(", ")", "{", "}", "[", "]", "::", +// ";", ":", ",", ".", "..", "...", +// }; + +// for(s32 i = 0; i < COUNT_OF(LuaSigns); i++) +// { +// const char* sign = LuaSigns[i]; +// const char* start = text; + +// while((start = strstr(start, sign))) +// { +// size_t size = strlen(sign); +// memset(color + (start - text), getConfig()->theme.code.sign, size); +// start += size; +// } +// } +// } + +// static void highlightCommentsBase(Code* code, u8* color, const char* pattern1, const char* pattern2, s32 extraSize) +// { +// const char* text = code->src; +// const char* pointer = text; + +// while(*pointer) +// { +// char* start = strstr(pointer, pattern1); + +// if(start) +// { +// char* end = strstr(start + strlen(pattern1), pattern2); + +// if(!end) end = start + strlen(start); + +// if(end) +// { +// end += extraSize; + +// memset(color + (start - text), getConfig()->theme.code.comment, end - start); +// pointer = end; +// } +// } + +// pointer++; +// } +// } + +// static void highlightComments(Code* code, u8* color) +// { +// highlightCommentsBase(code, color, "--", "\n", 0); +// highlightCommentsBase(code, color, "--[[", "]]", 2); +// } + +// static void highlightJsComments(Code* code, u8* color) +// { +// highlightCommentsBase(code, color, "//", "\n", 0); +// highlightCommentsBase(code, color, "/*", "*/", 2); +// } + +#include + +static inline bool isLineEnd(char c) {return c == '\n' || c == '\0';} + +static void parse(const char* start, u8* color) { - char* start = SDL_strchr(text, separator); + const char* ptr = start; - if(start) + const char* digitStart = NULL; + const char* singleCommentStart = NULL; + + static const char Comment[] = "--"; + + while(true) { - char* end = SDL_strchr(start + 1, separator); + char c = *ptr; - if(end) + if(singleCommentStart) { - end++; - u8* colorPtr = color + (start - text); - - if(*colorPtr != getConfig()->theme.code.comment) - memset(colorPtr, getConfig()->theme.code.string, end - start); - - highlightStrings(code, end, color + (end - text), separator); - } - } -} - -static void highlightNumbers(Code* code, u8* color) -{ - const char* text = code->src; - const char* pointer = text; - - while(*pointer) - { - char symbol = *pointer; - - if(isLetter(symbol)) - while(symbol && (isLetter(symbol) || isNumber(symbol) || isDot(symbol))) - symbol = *++pointer; - - const char* start = pointer; - while(symbol && (isNumber(symbol) || isDot(symbol))) symbol = *++pointer; - - if(!isLetter(symbol)) memset(color + (start - text), getConfig()->theme.code.number, pointer - start); - - pointer++; - } -} - -static void highlightWords(const char* text, u8* color, const char* const strings[], s32 count, u8 wordColor) -{ - const char* pointer = text; - - while(*pointer) - { - char symbol = *pointer; - - const char* start = pointer; - while(symbol && (isLetter(symbol) || isNumber(symbol))) - symbol = *++pointer; - - size_t size = pointer - start; - - if(size) - { - for(s32 i = 0; i < count; i++) + if(isLineEnd(c)) { - const char* keyword = strings[i]; - if(size == strlen(keyword) && memcmp(start, keyword, size) == 0) - { - memset(color + (start - text), wordColor, size); - break; - } + memset(color + (singleCommentStart - start), getConfig()->theme.code.comment, ptr - singleCommentStart); + singleCommentStart = NULL; + } + } + else + { + if(c == Comment[1] && ptr > start && *(ptr-1) == Comment[0]) + { + singleCommentStart = ptr-1; + } + else + { + + // if(!isprint(c)) + // { + // digitStart = NULL; + // ptr++; + // continue; + // } + } } - pointer++; + if(!c) break; + + bool digit = false; + + // if(digitStart) + // { + // if(digitStart[0] == '0' && digitStart[1] == 'x') + // { + // if(ptr - digitStart <= 2) + // digit = true; + // else if(ptr - digitStart > 2 && isxdigit(c)) + // digit = true; + // else digitStart = NULL; + // } + // else if(isdigit(c)) + // { + // digit = true; + // } + // else if(c == '.') + // { + // digit = true; + // } + // else + // { + // digitStart = NULL; + // } + // } + // else + // { + // if(isdigit(c)) + // { + // digitStart = ptr; + // digit = true; + // } + // } + + if(digit) color[ptr - start] = getConfig()->theme.code.number; + + ptr++; } - -} - -static void highlightMoonKeywords(Code* code, u8* color) -{ - const char* text = code->src; - - static const char* const MoonKeywords [] = - { - "false", "true", "nil", "return", - "break", "continue", "for", "while", - "if", "else", "elseif", "unless", "switch", - "when", "and", "or", "in", "do", - "not", "super", "try", "catch", - "with", "export", "import", "then", - "from", "class", "extends", "new" - }; - - highlightWords(text, color, MoonKeywords, COUNT_OF(MoonKeywords), getConfig()->theme.code.keyword); -} - -static void highlightLuaKeywords(Code* code, u8* color) -{ - const char* text = code->src; - - static const char* const LuaKeywords [] = - { - "and", "break", "do", "else", "elseif", - "end", "false", "for", "function", "goto", "if", - "in", "local", "nil", "not", "or", "repeat", - "return", "then", "true", "until", "while" - }; - - highlightWords(text, color, LuaKeywords, COUNT_OF(LuaKeywords), getConfig()->theme.code.keyword); -} - -static void highlightJsKeywords(Code* code, u8* color) -{ - const char* text = code->src; - - static const char* const JsKeywords [] = - { - "break", "do", "instanceof", "typeof", "case", "else", "new", - "var", "catch", "finally", "return", "void", "continue", "for", - "switch", "while", "debugger", "function", "this", "with", - "default", "if", "throw", "delete", "in", "try", "const" - }; - - highlightWords(text, color, JsKeywords, COUNT_OF(JsKeywords), getConfig()->theme.code.keyword); -} - -static void highlightApi(Code* code, u8* color) -{ - static const char* const ApiKeywords[] = API_KEYWORDS; - - const char* text = code->src; - highlightWords(text, color, ApiKeywords, COUNT_OF(ApiKeywords), getConfig()->theme.code.api); -} - -static void highlightNonChars(Code* code, u8* color) -{ - const char* text = code->src; - - while(*text) - { - if(*text <= 32) - *color = getConfig()->theme.code.other; - - text++; - color++; - } -} - -static void highlightSigns(Code* code, u8* color) -{ - const char* text = code->src; - - static const char* const LuaSigns [] = - { - "+", "-", "*", "/", "%", "^", "#", - "&", "~", "|", "<<", ">>", "//", - "==", "~=", "<=", ">=", "<", ">", "=", - "(", ")", "{", "}", "[", "]", "::", - ";", ":", ",", ".", "..", "...", - }; - - for(s32 i = 0; i < COUNT_OF(LuaSigns); i++) - { - const char* sign = LuaSigns[i]; - const char* start = text; - - while((start = strstr(start, sign))) - { - size_t size = strlen(sign); - memset(color + (start - text), getConfig()->theme.code.sign, size); - start += size; - } - } -} - -static void highlightCommentsBase(Code* code, u8* color, const char* pattern1, const char* pattern2, s32 extraSize) -{ - const char* text = code->src; - const char* pointer = text; - - while(*pointer) - { - char* start = strstr(pointer, pattern1); - - if(start) - { - char* end = strstr(start + strlen(pattern1), pattern2); - - if(!end) end = start + strlen(start); - - if(end) - { - end += extraSize; - - memset(color + (start - text), getConfig()->theme.code.comment, end - start); - pointer = end; - } - } - - pointer++; - } -} - -static void highlightComments(Code* code, u8* color) -{ - highlightCommentsBase(code, color, "--", "\n", 0); - highlightCommentsBase(code, color, "--[[", "]]", 2); -} - -static void highlightJsComments(Code* code, u8* color) -{ - highlightCommentsBase(code, color, "//", "\n", 0); - highlightCommentsBase(code, color, "/*", "*/", 2); } static void parseSyntaxColor(Code* code) { memset(code->colorBuffer, getConfig()->theme.code.var, sizeof(code->colorBuffer)); - u8* color = code->colorBuffer; + parse(code->src, code->colorBuffer); - switch(code->tic->api.get_script(code->tic)) - { - case tic_script_moon: - highlightNonChars(code, color); - highlightMoonKeywords(code, color); - highlightApi(code, color); - highlightNumbers(code, color); - highlightSigns(code, color); - highlightCommentsBase(code, color, "--", "\n", 0); - highlightStrings(code, code->src, color, '"'); - break; - case tic_script_lua: - highlightNonChars(code, color); - highlightLuaKeywords(code, color); - highlightApi(code, color); - highlightNumbers(code, color); - highlightSigns(code, color); - highlightComments(code, color); - highlightStrings(code, code->src, color, '"'); - break; - case tic_script_js: - highlightNonChars(code, color); - highlightJsKeywords(code, color); - highlightApi(code, color); - highlightNumbers(code, color); - highlightSigns(code, color); - highlightJsComments(code, color); - highlightStrings(code, code->src, color, '"'); - break; - } + // u8* color = code->colorBuffer; + // const char* ptr = code->src; + + // char* digitStart = NULL; + + // while(true) + // { + // char c = *ptr; + + // if(!c) break; + + // if(digitStart) + // { + // if(isxdigit(c)) + // { + // *color = getConfig()->theme.code.number; + // } + // else + // } + // else + // { + // if(isdigit(c)) + // { + // *color = getConfig()->theme.code.number; + + // if(digitStart == NULL) + // { + // digitStart = ptr; + // } + // } + // else + // { + // digitStart = NULL; + // } + // } + + // ptr++; + // color++; + // } + + // switch(code->tic->api.get_script(code->tic)) + // { + // case tic_script_moon: + // highlightNonChars(code, color); + // highlightMoonKeywords(code, color); + // highlightApi(code, color); + // highlightNumbers(code, color); + // highlightSigns(code, color); + // highlightCommentsBase(code, color, "--", "\n", 0); + // highlightStrings(code, code->src, color, '"'); + // break; + // case tic_script_lua: + // highlightNonChars(code, color); + // highlightLuaKeywords(code, color); + // highlightApi(code, color); + // highlightNumbers(code, color); + // highlightSigns(code, color); + // highlightComments(code, color); + // highlightStrings(code, code->src, color, '"'); + // break; + // case tic_script_js: + // highlightNonChars(code, color); + // highlightJsKeywords(code, color); + // highlightApi(code, color); + // highlightNumbers(code, color); + // highlightSigns(code, color); + // highlightJsComments(code, color); + // highlightStrings(code, code->src, color, '"'); + // break; + // } } static char* getLineByPos(Code* code, char* pos) From a235f62277d88738802ec06dd2d4e876be9bd6a7 Mon Sep 17 00:00:00 2001 From: "BADIM-PC\\Vadim" Date: Wed, 20 Dec 2017 21:15:44 +0300 Subject: [PATCH 02/10] block comment works --- src/code.c | 45 ++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 40 insertions(+), 5 deletions(-) diff --git a/src/code.c b/src/code.c index da3e90b..23bf523 100644 --- a/src/code.c +++ b/src/code.c @@ -404,24 +404,59 @@ static bool isWord(char symbol) {return isLetter(symbol) || isNumber(symbol);} #include -static inline bool isLineEnd(char c) {return c == '\n' || c == '\0';} +static inline bool is_lineend(char c) {return c == '\n' || c == '\0';} static void parse(const char* start, u8* color) { const char* ptr = start; - const char* digitStart = NULL; + // const char* digitStart = NULL; + const char* blockCommentStart = NULL; const char* singleCommentStart = NULL; - static const char Comment[] = "--"; + static const char Comment = '-'; + static const char BlockCommentStart[] = "--[["; + static const char BlockCommentEnd[] = "]]"; + + enum{BlockCommentStartSize = sizeof BlockCommentStart - 1}; while(true) { char c = *ptr; + if(blockCommentStart) + { + const char* end = strstr(ptr, BlockCommentEnd); + + if(end) + { + ptr = end = end + strlen(BlockCommentEnd); + } + else + { + ptr = end = blockCommentStart + strlen(blockCommentStart); + } + + memset(color + (blockCommentStart - start), getConfig()->theme.code.comment, end - blockCommentStart); + blockCommentStart = NULL; + } + else + { + if(c == BlockCommentStart[0] && memcmp(ptr, BlockCommentStart, BlockCommentStartSize) == 0) + { + blockCommentStart = ptr; + ptr += BlockCommentStartSize; + continue; + } + else + { + // do other stuff + } + } + if(singleCommentStart) { - if(isLineEnd(c)) + if(is_lineend(c)) { memset(color + (singleCommentStart - start), getConfig()->theme.code.comment, ptr - singleCommentStart); singleCommentStart = NULL; @@ -429,7 +464,7 @@ static void parse(const char* start, u8* color) } else { - if(c == Comment[1] && ptr > start && *(ptr-1) == Comment[0]) + if(c == Comment && ptr > start && *(ptr-1) == Comment) { singleCommentStart = ptr-1; } From 0e35b785088cad2d29c6e789d69f72ae7910d999 Mon Sep 17 00:00:00 2001 From: "BADIM-PC\\Vadim" Date: Wed, 20 Dec 2017 21:23:59 +0300 Subject: [PATCH 03/10] no message --- src/code.c | 77 ++++++++++++++++++++++++------------------------------ 1 file changed, 34 insertions(+), 43 deletions(-) diff --git a/src/code.c b/src/code.c index 23bf523..ee19394 100644 --- a/src/code.c +++ b/src/code.c @@ -410,16 +410,11 @@ static void parse(const char* start, u8* color) { const char* ptr = start; - // const char* digitStart = NULL; const char* blockCommentStart = NULL; - const char* singleCommentStart = NULL; - static const char Comment = '-'; static const char BlockCommentStart[] = "--[["; static const char BlockCommentEnd[] = "]]"; - enum{BlockCommentStartSize = sizeof BlockCommentStart - 1}; - while(true) { char c = *ptr; @@ -428,24 +423,17 @@ static void parse(const char* start, u8* color) { const char* end = strstr(ptr, BlockCommentEnd); - if(end) - { - ptr = end = end + strlen(BlockCommentEnd); - } - else - { - ptr = end = blockCommentStart + strlen(blockCommentStart); - } - - memset(color + (blockCommentStart - start), getConfig()->theme.code.comment, end - blockCommentStart); + ptr = end ? end + strlen(BlockCommentEnd) : blockCommentStart + strlen(blockCommentStart); + memset(color + (blockCommentStart - start), getConfig()->theme.code.comment, ptr - blockCommentStart); blockCommentStart = NULL; } else { - if(c == BlockCommentStart[0] && memcmp(ptr, BlockCommentStart, BlockCommentStartSize) == 0) + s32 blockCommentStartSize = strlen(BlockCommentStart); + if(c == BlockCommentStart[0] && memcmp(ptr, BlockCommentStart, blockCommentStartSize) == 0) { blockCommentStart = ptr; - ptr += BlockCommentStartSize; + ptr += blockCommentStartSize; continue; } else @@ -454,36 +442,39 @@ static void parse(const char* start, u8* color) } } - if(singleCommentStart) - { - if(is_lineend(c)) - { - memset(color + (singleCommentStart - start), getConfig()->theme.code.comment, ptr - singleCommentStart); - singleCommentStart = NULL; - } - } - else - { - if(c == Comment && ptr > start && *(ptr-1) == Comment) - { - singleCommentStart = ptr-1; - } - else - { + // static const char Comment = '-'; + // const char* singleCommentStart = NULL; + // if(singleCommentStart) + // { + // if(is_lineend(c)) + // { + // memset(color + (singleCommentStart - start), getConfig()->theme.code.comment, ptr - singleCommentStart); + // singleCommentStart = NULL; + // } + // } + // else + // { + // if(c == Comment && ptr > start && *(ptr-1) == Comment) + // { + // singleCommentStart = ptr-1; + // } + // else + // { - // if(!isprint(c)) - // { - // digitStart = NULL; - // ptr++; - // continue; - // } + // // if(!isprint(c)) + // // { + // // digitStart = NULL; + // // ptr++; + // // continue; + // // } - } - } + // } + // } if(!c) break; - bool digit = false; + // const char* digitStart = NULL; + // bool digit = false; // if(digitStart) // { @@ -517,7 +508,7 @@ static void parse(const char* start, u8* color) // } // } - if(digit) color[ptr - start] = getConfig()->theme.code.number; + // if(digit) color[ptr - start] = getConfig()->theme.code.number; ptr++; } From d77aa85d4e03201e5e069e2ee5b74909d8c7e054 Mon Sep 17 00:00:00 2001 From: "BADIM-PC\\Vadim" Date: Wed, 20 Dec 2017 21:57:29 +0300 Subject: [PATCH 04/10] string block works --- src/code.c | 42 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/src/code.c b/src/code.c index ee19394..46e42f3 100644 --- a/src/code.c +++ b/src/code.c @@ -411,6 +411,7 @@ static void parse(const char* start, u8* color) const char* ptr = start; const char* blockCommentStart = NULL; + const char* blockStringStart = NULL; static const char BlockCommentStart[] = "--[["; static const char BlockCommentEnd[] = "]]"; @@ -427,6 +428,36 @@ static void parse(const char* start, u8* color) memset(color + (blockCommentStart - start), getConfig()->theme.code.comment, ptr - blockCommentStart); blockCommentStart = NULL; } + else if(blockStringStart) + { + const char* blockStart = blockStringStart+1; + + while(true) + { + const char* pos = strchr(blockStart, *blockStringStart); + + if(pos) + { + if(*(pos-1) == '\\' && *(pos-2) != '\\') + { + blockStart = pos + 1; + } + else + { + ptr = pos + 1; + break; + } + } + else + { + ptr = blockStringStart + strlen(blockStringStart); + break; + } + } + + memset(color + (blockStringStart - start), getConfig()->theme.code.string, ptr - blockStringStart); + blockStringStart = NULL; + } else { s32 blockCommentStartSize = strlen(BlockCommentStart); @@ -438,7 +469,16 @@ static void parse(const char* start, u8* color) } else { - // do other stuff + if(c == '"' || c == '\'') + { + blockStringStart = ptr; + ptr += 1; + continue; + } + else + { + // do other stuff + } } } From e449656d57e92b8adbe325d46b3dc839ed16d361 Mon Sep 17 00:00:00 2001 From: "BADIM-PC\\Vadim" Date: Wed, 20 Dec 2017 22:06:43 +0300 Subject: [PATCH 05/10] single comment work --- src/code.c | 130 +++++++++-------------------------------------------- 1 file changed, 21 insertions(+), 109 deletions(-) diff --git a/src/code.c b/src/code.c index 46e42f3..323df9b 100644 --- a/src/code.c +++ b/src/code.c @@ -404,17 +404,17 @@ static bool isWord(char symbol) {return isLetter(symbol) || isNumber(symbol);} #include -static inline bool is_lineend(char c) {return c == '\n' || c == '\0';} - static void parse(const char* start, u8* color) { const char* ptr = start; const char* blockCommentStart = NULL; const char* blockStringStart = NULL; + const char* singleCommentStart = NULL; static const char BlockCommentStart[] = "--[["; static const char BlockCommentEnd[] = "]]"; + static const char SingleCommentStart[] = "--"; while(true) { @@ -458,6 +458,13 @@ static void parse(const char* start, u8* color) memset(color + (blockStringStart - start), getConfig()->theme.code.string, ptr - blockStringStart); blockStringStart = NULL; } + else if(singleCommentStart) + { + while(*ptr != '\0' && *ptr != '\n')ptr++; + + memset(color + (singleCommentStart - start), getConfig()->theme.code.comment, ptr - singleCommentStart); + singleCommentStart = NULL; + } else { s32 blockCommentStartSize = strlen(BlockCommentStart); @@ -477,79 +484,24 @@ static void parse(const char* start, u8* color) } else { - // do other stuff + s32 singleCommentStartSize = strlen(SingleCommentStart); + + if(c == SingleCommentStart[0] && memcmp(ptr, SingleCommentStart, singleCommentStartSize) == 0) + { + singleCommentStart = ptr; + ptr += singleCommentStartSize; + continue; + } + else + { + // do other stuff + } } } } - // static const char Comment = '-'; - // const char* singleCommentStart = NULL; - // if(singleCommentStart) - // { - // if(is_lineend(c)) - // { - // memset(color + (singleCommentStart - start), getConfig()->theme.code.comment, ptr - singleCommentStart); - // singleCommentStart = NULL; - // } - // } - // else - // { - // if(c == Comment && ptr > start && *(ptr-1) == Comment) - // { - // singleCommentStart = ptr-1; - // } - // else - // { - - // // if(!isprint(c)) - // // { - // // digitStart = NULL; - // // ptr++; - // // continue; - // // } - - // } - // } - if(!c) break; - // const char* digitStart = NULL; - // bool digit = false; - - // if(digitStart) - // { - // if(digitStart[0] == '0' && digitStart[1] == 'x') - // { - // if(ptr - digitStart <= 2) - // digit = true; - // else if(ptr - digitStart > 2 && isxdigit(c)) - // digit = true; - // else digitStart = NULL; - // } - // else if(isdigit(c)) - // { - // digit = true; - // } - // else if(c == '.') - // { - // digit = true; - // } - // else - // { - // digitStart = NULL; - // } - // } - // else - // { - // if(isdigit(c)) - // { - // digitStart = ptr; - // digit = true; - // } - // } - - // if(digit) color[ptr - start] = getConfig()->theme.code.number; - ptr++; } } @@ -560,46 +512,6 @@ static void parseSyntaxColor(Code* code) parse(code->src, code->colorBuffer); - // u8* color = code->colorBuffer; - // const char* ptr = code->src; - - // char* digitStart = NULL; - - // while(true) - // { - // char c = *ptr; - - // if(!c) break; - - // if(digitStart) - // { - // if(isxdigit(c)) - // { - // *color = getConfig()->theme.code.number; - // } - // else - // } - // else - // { - // if(isdigit(c)) - // { - // *color = getConfig()->theme.code.number; - - // if(digitStart == NULL) - // { - // digitStart = ptr; - // } - // } - // else - // { - // digitStart = NULL; - // } - // } - - // ptr++; - // color++; - // } - // switch(code->tic->api.get_script(code->tic)) // { // case tic_script_moon: From b4b002464ddd8ac5bb2a29aaaf63ffc38ff21c89 Mon Sep 17 00:00:00 2001 From: "BADIM-PC\\Vadim" Date: Wed, 20 Dec 2017 22:46:08 +0300 Subject: [PATCH 06/10] digit syntax works detects 0x 0X .5 5e8 --- src/code.c | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 56 insertions(+), 2 deletions(-) diff --git a/src/code.c b/src/code.c index 323df9b..9ce9122 100644 --- a/src/code.c +++ b/src/code.c @@ -404,6 +404,8 @@ static bool isWord(char symbol) {return isLetter(symbol) || isNumber(symbol);} #include +static inline bool islineend(char c) {return c == '\n' || c == '\0';} + static void parse(const char* start, u8* color) { const char* ptr = start; @@ -411,6 +413,7 @@ static void parse(const char* start, u8* color) const char* blockCommentStart = NULL; const char* blockStringStart = NULL; const char* singleCommentStart = NULL; + const char* numberStart = NULL; static const char BlockCommentStart[] = "--[["; static const char BlockCommentEnd[] = "]]"; @@ -460,11 +463,57 @@ static void parse(const char* start, u8* color) } else if(singleCommentStart) { - while(*ptr != '\0' && *ptr != '\n')ptr++; + while(!islineend(*ptr))ptr++; memset(color + (singleCommentStart - start), getConfig()->theme.code.comment, ptr - singleCommentStart); singleCommentStart = NULL; } + else if(numberStart) + { + bool digit = true; + while(!islineend(*ptr)) + { + char c = *ptr; + + if(isdigit(c)) + { + ptr++; + } + else if(numberStart[0] == '0' && (numberStart[1] == 'x' || numberStart[1] == 'X')) + { + if(ptr - numberStart <= 2) + { + ptr++; + } + else if(ptr - numberStart > 2 && isxdigit(c)) + { + ptr++; + } + else + { + digit = false; + break; + } + } + else if(c == '.' || c == 'e') + { + if(isdigit(ptr[1])) + ptr++; + else break; + } + else if(isalpha(c) || c == '_') + { + digit = false; + break; + } + else break; + } + + if(digit) + memset(color + (numberStart - start), getConfig()->theme.code.number, ptr - numberStart); + + numberStart = NULL; + } else { s32 blockCommentStartSize = strlen(BlockCommentStart); @@ -494,7 +543,12 @@ static void parse(const char* start, u8* color) } else { - // do other stuff + if(isdigit(c) || (c == '.' && isdigit(ptr[1]))) + { + numberStart = ptr; + ptr += 1; + continue; + } } } } From 354c0a47016030024b1ab81ff0b914f3e800c0c5 Mon Sep 17 00:00:00 2001 From: "BADIM-PC\\Vadim" Date: Wed, 20 Dec 2017 22:59:45 +0300 Subject: [PATCH 07/10] numbers parsing optimisation --- src/code.c | 47 +++++++++++++++++------------------------------ 1 file changed, 17 insertions(+), 30 deletions(-) diff --git a/src/code.c b/src/code.c index 9ce9122..c49dd93 100644 --- a/src/code.c +++ b/src/code.c @@ -430,6 +430,7 @@ static void parse(const char* start, u8* color) ptr = end ? end + strlen(BlockCommentEnd) : blockCommentStart + strlen(blockCommentStart); memset(color + (blockCommentStart - start), getConfig()->theme.code.comment, ptr - blockCommentStart); blockCommentStart = NULL; + continue; } else if(blockStringStart) { @@ -460,6 +461,7 @@ static void parse(const char* start, u8* color) memset(color + (blockStringStart - start), getConfig()->theme.code.string, ptr - blockStringStart); blockStringStart = NULL; + continue; } else if(singleCommentStart) { @@ -467,52 +469,33 @@ static void parse(const char* start, u8* color) memset(color + (singleCommentStart - start), getConfig()->theme.code.comment, ptr - singleCommentStart); singleCommentStart = NULL; + continue; } else if(numberStart) { - bool digit = true; while(!islineend(*ptr)) { char c = *ptr; - if(isdigit(c)) + if(isdigit(c)) ptr++; + else if(numberStart[0] == '0' + && (numberStart[1] == 'x' || numberStart[1] == 'X') + && isxdigit(numberStart[2])) { - ptr++; - } - else if(numberStart[0] == '0' && (numberStart[1] == 'x' || numberStart[1] == 'X')) - { - if(ptr - numberStart <= 2) - { - ptr++; - } - else if(ptr - numberStart > 2 && isxdigit(c)) - { - ptr++; - } - else - { - digit = false; - break; - } - } - else if(c == '.' || c == 'e') - { - if(isdigit(ptr[1])) - ptr++; + if((ptr - numberStart < 2) || (ptr - numberStart >= 2 && isxdigit(c))) ptr++; else break; } - else if(isalpha(c) || c == '_') + else if(c == '.' || c == 'e' || c == 'E') { - digit = false; - break; + if(isdigit(ptr[1])) ptr++; + else break; } else break; } - if(digit) - memset(color + (numberStart - start), getConfig()->theme.code.number, ptr - numberStart); - + memset(color + (numberStart - start), getConfig()->theme.code.number, ptr - numberStart); numberStart = NULL; + continue; } else { @@ -549,6 +532,10 @@ static void parse(const char* start, u8* color) ptr += 1; continue; } + else + { + // other stuff + } } } } From d5035caf474829a7bb98f325927d93ffbf14bbb5 Mon Sep 17 00:00:00 2001 From: "BADIM-PC\\Vadim" Date: Wed, 20 Dec 2017 23:14:41 +0300 Subject: [PATCH 08/10] added api and keywords syntax --- src/code.c | 60 +++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 55 insertions(+), 5 deletions(-) diff --git a/src/code.c b/src/code.c index c49dd93..d7fefc2 100644 --- a/src/code.c +++ b/src/code.c @@ -405,6 +405,8 @@ static bool isWord(char symbol) {return isLetter(symbol) || isNumber(symbol);} #include static inline bool islineend(char c) {return c == '\n' || c == '\0';} +static inline bool isalpha_(char c) {return isalpha(c) || c == '_';} +static inline bool isalnum_(char c) {return isalnum(c) || c == '_';} static void parse(const char* start, u8* color) { @@ -413,6 +415,7 @@ static void parse(const char* start, u8* color) const char* blockCommentStart = NULL; const char* blockStringStart = NULL; const char* singleCommentStart = NULL; + const char* wordStart = NULL; const char* numberStart = NULL; static const char BlockCommentStart[] = "--[["; @@ -471,6 +474,44 @@ static void parse(const char* start, u8* color) singleCommentStart = NULL; continue; } + else if(wordStart) + { + while(!islineend(*ptr) && isalnum_(*ptr)) ptr++; + + bool keyword = false; + { + static const char* const Keywords [] = + { + "and", "break", "do", "else", "elseif", + "end", "false", "for", "function", "goto", "if", + "in", "local", "nil", "not", "or", "repeat", + "return", "then", "true", "until", "while" + }; + + for(s32 i = 0; i < COUNT_OF(Keywords); i++) + if(memcmp(wordStart, Keywords[i], strlen(Keywords[i])) == 0) + { + memset(color + (wordStart - start), getConfig()->theme.code.keyword, ptr - wordStart); + keyword = true; + break; + } + } + + if(!keyword) + { + static const char* const Api[] = API_KEYWORDS; + + for(s32 i = 0; i < COUNT_OF(Api); i++) + if(memcmp(wordStart, Api[i], strlen(Api[i])) == 0) + { + memset(color + (wordStart - start), getConfig()->theme.code.api, ptr - wordStart); + break; + } + } + + wordStart = NULL; + continue; + } else if(numberStart) { while(!islineend(*ptr)) @@ -511,7 +552,7 @@ static void parse(const char* start, u8* color) if(c == '"' || c == '\'') { blockStringStart = ptr; - ptr += 1; + ptr++; continue; } else @@ -526,15 +567,24 @@ static void parse(const char* start, u8* color) } else { - if(isdigit(c) || (c == '.' && isdigit(ptr[1]))) + if(isalpha_(c)) { - numberStart = ptr; - ptr += 1; + wordStart = ptr; + ptr++; continue; } else { - // other stuff + if(isdigit(c) || (c == '.' && isdigit(ptr[1]))) + { + numberStart = ptr; + ptr++; + continue; + } + else + { + // other stuff + } } } } From 77158e1b6f792127587b3d9d7db8ea63ea379460 Mon Sep 17 00:00:00 2001 From: "BADIM-PC\\Vadim" Date: Wed, 20 Dec 2017 23:20:11 +0300 Subject: [PATCH 09/10] no message --- src/code.c | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/src/code.c b/src/code.c index d7fefc2..e4e82d8 100644 --- a/src/code.c +++ b/src/code.c @@ -408,8 +408,12 @@ static inline bool islineend(char c) {return c == '\n' || c == '\0';} static inline bool isalpha_(char c) {return isalpha(c) || c == '_';} static inline bool isalnum_(char c) {return isalnum(c) || c == '_';} -static void parse(const char* start, u8* color) +static void parseSyntaxColor(Code* code) { + u8* color = code->colorBuffer; + memset(color, getConfig()->theme.code.var, sizeof(code->colorBuffer)); + + const char* start = code->src; const char* ptr = start; const char* blockCommentStart = NULL; @@ -581,10 +585,8 @@ static void parse(const char* start, u8* color) ptr++; continue; } - else - { - // other stuff - } + else if(ispunct(c)) + color[ptr - start] = getConfig()->theme.code.sign; } } } @@ -595,13 +597,6 @@ static void parse(const char* start, u8* color) ptr++; } -} - -static void parseSyntaxColor(Code* code) -{ - memset(code->colorBuffer, getConfig()->theme.code.var, sizeof(code->colorBuffer)); - - parse(code->src, code->colorBuffer); // switch(code->tic->api.get_script(code->tic)) // { From 838f676569edfefa42969225ac12c45fc4156056 Mon Sep 17 00:00:00 2001 From: "BADIM-PC\\Vadim" Date: Wed, 20 Dec 2017 23:39:21 +0300 Subject: [PATCH 10/10] added JS and Moon syntax --- src/code.c | 372 +++++++++++++---------------------------------------- 1 file changed, 92 insertions(+), 280 deletions(-) diff --git a/src/code.c b/src/code.c index e4e82d8..a6436be 100644 --- a/src/code.c +++ b/src/code.c @@ -23,6 +23,8 @@ #include "code.h" #include "history.h" +#include + #define TEXT_CURSOR_DELAY (TIC_FRAMERATE / 2) #define TEXT_CURSOR_BLINK_PERIOD TIC_FRAMERATE #define TEXT_BUFFER_WIDTH STUDIO_TEXT_BUFFER_WIDTH @@ -185,235 +187,76 @@ static void updateEditor(Code* code) } } -static bool isLetter(char symbol) {return (symbol >= 'A' && symbol <= 'Z') || (symbol >= 'a' && symbol <= 'z') || (symbol == '_');} -static bool isNumber(char symbol) {return (symbol >= '0' && symbol <= '9');} -static bool isWord(char symbol) {return isLetter(symbol) || isNumber(symbol);} -// static bool isDot(char symbol) {return (symbol == '.');} - -// static void highlightStrings(Code* code, const char* text, u8* color, char separator) -// { -// char* start = SDL_strchr(text, separator); - -// if(start) -// { -// char* end = SDL_strchr(start + 1, separator); - -// if(end) -// { -// end++; -// u8* colorPtr = color + (start - text); - -// if(*colorPtr != getConfig()->theme.code.comment) -// memset(colorPtr, getConfig()->theme.code.string, end - start); - -// highlightStrings(code, end, color + (end - text), separator); -// } -// } -// } - -// static void highlightNumbers(Code* code, u8* color) -// { -// const char* text = code->src; -// const char* pointer = text; - -// while(*pointer) -// { -// char symbol = *pointer; - -// if(isLetter(symbol)) -// while(symbol && (isLetter(symbol) || isNumber(symbol) || isDot(symbol))) -// symbol = *++pointer; - -// const char* start = pointer; -// while(symbol && (isNumber(symbol) || isDot(symbol))) symbol = *++pointer; - -// if(!isLetter(symbol)) memset(color + (start - text), getConfig()->theme.code.number, pointer - start); - -// pointer++; -// } -// } - -// static void highlightWords(const char* text, u8* color, const char* const strings[], s32 count, u8 wordColor) -// { -// const char* pointer = text; - -// while(*pointer) -// { -// char symbol = *pointer; - -// const char* start = pointer; -// while(symbol && (isLetter(symbol) || isNumber(symbol))) -// symbol = *++pointer; - -// size_t size = pointer - start; - -// if(size) -// { -// for(s32 i = 0; i < count; i++) -// { -// const char* keyword = strings[i]; -// if(size == strlen(keyword) && memcmp(start, keyword, size) == 0) -// { -// memset(color + (start - text), wordColor, size); -// break; -// } -// } -// } - -// pointer++; -// } - -// } - -// static void highlightMoonKeywords(Code* code, u8* color) -// { -// const char* text = code->src; - -// static const char* const MoonKeywords [] = -// { -// "false", "true", "nil", "return", -// "break", "continue", "for", "while", -// "if", "else", "elseif", "unless", "switch", -// "when", "and", "or", "in", "do", -// "not", "super", "try", "catch", -// "with", "export", "import", "then", -// "from", "class", "extends", "new" -// }; - -// highlightWords(text, color, MoonKeywords, COUNT_OF(MoonKeywords), getConfig()->theme.code.keyword); -// } - -// static void highlightLuaKeywords(Code* code, u8* color) -// { -// const char* text = code->src; - -// static const char* const LuaKeywords [] = -// { -// "and", "break", "do", "else", "elseif", -// "end", "false", "for", "function", "goto", "if", -// "in", "local", "nil", "not", "or", "repeat", -// "return", "then", "true", "until", "while" -// }; - -// highlightWords(text, color, LuaKeywords, COUNT_OF(LuaKeywords), getConfig()->theme.code.keyword); -// } - -// static void highlightJsKeywords(Code* code, u8* color) -// { -// const char* text = code->src; - -// static const char* const JsKeywords [] = -// { -// "break", "do", "instanceof", "typeof", "case", "else", "new", -// "var", "catch", "finally", "return", "void", "continue", "for", -// "switch", "while", "debugger", "function", "this", "with", -// "default", "if", "throw", "delete", "in", "try", "const" -// }; - -// highlightWords(text, color, JsKeywords, COUNT_OF(JsKeywords), getConfig()->theme.code.keyword); -// } - -// static void highlightApi(Code* code, u8* color) -// { -// static const char* const ApiKeywords[] = API_KEYWORDS; - -// const char* text = code->src; -// highlightWords(text, color, ApiKeywords, COUNT_OF(ApiKeywords), getConfig()->theme.code.api); -// } - -// static void highlightNonChars(Code* code, u8* color) -// { -// const char* text = code->src; - -// while(*text) -// { -// if(*text <= 32) -// *color = getConfig()->theme.code.other; - -// text++; -// color++; -// } -// } - -// static void highlightSigns(Code* code, u8* color) -// { -// const char* text = code->src; - -// static const char* const LuaSigns [] = -// { -// "+", "-", "*", "/", "%", "^", "#", -// "&", "~", "|", "<<", ">>", "//", -// "==", "~=", "<=", ">=", "<", ">", "=", -// "(", ")", "{", "}", "[", "]", "::", -// ";", ":", ",", ".", "..", "...", -// }; - -// for(s32 i = 0; i < COUNT_OF(LuaSigns); i++) -// { -// const char* sign = LuaSigns[i]; -// const char* start = text; - -// while((start = strstr(start, sign))) -// { -// size_t size = strlen(sign); -// memset(color + (start - text), getConfig()->theme.code.sign, size); -// start += size; -// } -// } -// } - -// static void highlightCommentsBase(Code* code, u8* color, const char* pattern1, const char* pattern2, s32 extraSize) -// { -// const char* text = code->src; -// const char* pointer = text; - -// while(*pointer) -// { -// char* start = strstr(pointer, pattern1); - -// if(start) -// { -// char* end = strstr(start + strlen(pattern1), pattern2); - -// if(!end) end = start + strlen(start); - -// if(end) -// { -// end += extraSize; - -// memset(color + (start - text), getConfig()->theme.code.comment, end - start); -// pointer = end; -// } -// } - -// pointer++; -// } -// } - -// static void highlightComments(Code* code, u8* color) -// { -// highlightCommentsBase(code, color, "--", "\n", 0); -// highlightCommentsBase(code, color, "--[[", "]]", 2); -// } - -// static void highlightJsComments(Code* code, u8* color) -// { -// highlightCommentsBase(code, color, "//", "\n", 0); -// highlightCommentsBase(code, color, "/*", "*/", 2); -// } - -#include - static inline bool islineend(char c) {return c == '\n' || c == '\0';} static inline bool isalpha_(char c) {return isalpha(c) || c == '_';} static inline bool isalnum_(char c) {return isalnum(c) || c == '_';} -static void parseSyntaxColor(Code* code) +typedef struct { - u8* color = code->colorBuffer; - memset(color, getConfig()->theme.code.var, sizeof(code->colorBuffer)); + const char* blockCommentStart; + const char* blockCommentEnd; + const char* singleCommentStart; - const char* start = code->src; + const char* const * keywords; + s32 keywordsCount; +} SyntaxConfig; + +static const char* const LuaKeywords [] = +{ + "and", "break", "do", "else", "elseif", + "end", "false", "for", "function", "goto", "if", + "in", "local", "nil", "not", "or", "repeat", + "return", "then", "true", "until", "while" +}; + +static const SyntaxConfig LuaSyntaxConfig = +{ + .blockCommentStart = "--[[", + .blockCommentEnd = "]]", + .singleCommentStart = "--", + .keywords = LuaKeywords, + .keywordsCount = COUNT_OF(LuaKeywords), +}; + +static const char* const MoonKeywords [] = +{ + "false", "true", "nil", "return", + "break", "continue", "for", "while", + "if", "else", "elseif", "unless", "switch", + "when", "and", "or", "in", "do", + "not", "super", "try", "catch", + "with", "export", "import", "then", + "from", "class", "extends", "new" +}; + +static const SyntaxConfig MoonSyntaxConfig = +{ + .blockCommentStart = "--[[", + .blockCommentEnd = "]]", + .singleCommentStart = "--", + .keywords = MoonKeywords, + .keywordsCount = COUNT_OF(MoonKeywords), +}; + +static const char* const JsKeywords [] = +{ + "break", "do", "instanceof", "typeof", "case", "else", "new", + "var", "catch", "finally", "return", "void", "continue", "for", + "switch", "while", "debugger", "function", "this", "with", + "default", "if", "throw", "delete", "in", "try", "const" +}; + +static const SyntaxConfig JsSyntaxConfig = +{ + .blockCommentStart = "/*", + .blockCommentEnd = "*/", + .singleCommentStart = "//", + .keywords = JsKeywords, + .keywordsCount = COUNT_OF(JsKeywords), +}; + +static void parse(const char* start, u8* color, const SyntaxConfig* config) +{ const char* ptr = start; const char* blockCommentStart = NULL; @@ -422,19 +265,15 @@ static void parseSyntaxColor(Code* code) const char* wordStart = NULL; const char* numberStart = NULL; - static const char BlockCommentStart[] = "--[["; - static const char BlockCommentEnd[] = "]]"; - static const char SingleCommentStart[] = "--"; - while(true) { char c = *ptr; if(blockCommentStart) { - const char* end = strstr(ptr, BlockCommentEnd); + const char* end = strstr(ptr, config->blockCommentEnd); - ptr = end ? end + strlen(BlockCommentEnd) : blockCommentStart + strlen(blockCommentStart); + ptr = end ? end + strlen(config->blockCommentEnd) : blockCommentStart + strlen(blockCommentStart); memset(color + (blockCommentStart - start), getConfig()->theme.code.comment, ptr - blockCommentStart); blockCommentStart = NULL; continue; @@ -484,16 +323,8 @@ static void parseSyntaxColor(Code* code) bool keyword = false; { - static const char* const Keywords [] = - { - "and", "break", "do", "else", "elseif", - "end", "false", "for", "function", "goto", "if", - "in", "local", "nil", "not", "or", "repeat", - "return", "then", "true", "until", "while" - }; - - for(s32 i = 0; i < COUNT_OF(Keywords); i++) - if(memcmp(wordStart, Keywords[i], strlen(Keywords[i])) == 0) + for(s32 i = 0; i < config->keywordsCount; i++) + if(memcmp(wordStart, config->keywords[i], strlen(config->keywords[i])) == 0) { memset(color + (wordStart - start), getConfig()->theme.code.keyword, ptr - wordStart); keyword = true; @@ -544,8 +375,8 @@ static void parseSyntaxColor(Code* code) } else { - s32 blockCommentStartSize = strlen(BlockCommentStart); - if(c == BlockCommentStart[0] && memcmp(ptr, BlockCommentStart, blockCommentStartSize) == 0) + s32 blockCommentStartSize = strlen(config->blockCommentStart); + if(c == config->blockCommentStart[0] && memcmp(ptr, config->blockCommentStart, blockCommentStartSize) == 0) { blockCommentStart = ptr; ptr += blockCommentStartSize; @@ -561,9 +392,9 @@ static void parseSyntaxColor(Code* code) } else { - s32 singleCommentStartSize = strlen(SingleCommentStart); + s32 singleCommentStartSize = strlen(config->singleCommentStart); - if(c == SingleCommentStart[0] && memcmp(ptr, SingleCommentStart, singleCommentStartSize) == 0) + if(c == config->singleCommentStart[0] && memcmp(ptr, config->singleCommentStart, singleCommentStartSize) == 0) { singleCommentStart = ptr; ptr += singleCommentStartSize; @@ -597,37 +428,18 @@ static void parseSyntaxColor(Code* code) ptr++; } +} - // switch(code->tic->api.get_script(code->tic)) - // { - // case tic_script_moon: - // highlightNonChars(code, color); - // highlightMoonKeywords(code, color); - // highlightApi(code, color); - // highlightNumbers(code, color); - // highlightSigns(code, color); - // highlightCommentsBase(code, color, "--", "\n", 0); - // highlightStrings(code, code->src, color, '"'); - // break; - // case tic_script_lua: - // highlightNonChars(code, color); - // highlightLuaKeywords(code, color); - // highlightApi(code, color); - // highlightNumbers(code, color); - // highlightSigns(code, color); - // highlightComments(code, color); - // highlightStrings(code, code->src, color, '"'); - // break; - // case tic_script_js: - // highlightNonChars(code, color); - // highlightJsKeywords(code, color); - // highlightApi(code, color); - // highlightNumbers(code, color); - // highlightSigns(code, color); - // highlightJsComments(code, color); - // highlightStrings(code, code->src, color, '"'); - // break; - // } +static void parseSyntaxColor(Code* code) +{ + memset(code->colorBuffer, getConfig()->theme.code.var, sizeof(code->colorBuffer)); + + switch(code->tic->api.get_script(code->tic)) + { + case tic_script_moon: parse(code->src, code->colorBuffer, &MoonSyntaxConfig); break; + case tic_script_lua: parse(code->src, code->colorBuffer, &LuaSyntaxConfig); break; + case tic_script_js: parse(code->src, code->colorBuffer, &JsSyntaxConfig); break; + } } static char* getLineByPos(Code* code, char* pos) @@ -774,8 +586,8 @@ static void leftWord(Code* code) if(pos > start) { - if(isWord(*pos)) while(pos > start && isWord(*(pos-1))) pos--; - else while(pos > start && !isWord(*(pos-1))) pos--; + if(isalnum_(*pos)) while(pos > start && isalnum_(*(pos-1))) pos--; + else while(pos > start && !isalnum_(*(pos-1))) pos--; code->cursor.position = pos; @@ -790,8 +602,8 @@ static void rightWord(Code* code) if(pos < end) { - if(isWord(*pos)) while(pos < end && isWord(*pos)) pos++; - else while(pos < end && !isWord(*pos)) pos++; + if(isalnum_(*pos)) while(pos < end && isalnum_(*pos)) pos++; + else while(pos < end && !isalnum_(*pos)) pos++; code->cursor.position = pos; updateColumn(code); @@ -1130,7 +942,7 @@ static char* getFuncName(const char* start, char* buffer) { char sym = *ptr; - if(isLetter(sym) || isNumber(sym) || sym == ':'){} + if(isalpha_(sym) || isdigit(sym) || sym == ':'){} else if(sym == '(') break; else return NULL; @@ -1215,11 +1027,11 @@ static void setMoonscriptOutlineMode(Code* code) char* endPtr = ptr; ptr += sizeof FuncString - 1; - while(endPtr >= code->src && !isLetter(*endPtr) && !isNumber(*endPtr)) endPtr--; + while(endPtr >= code->src && !isalpha_(*endPtr) && !isdigit(*endPtr)) endPtr--; char* start = endPtr; - for (const char* val = start-1; val >= code->src && (isLetter(*val) || isNumber(*val)); val--, start--); + for (const char* val = start-1; val >= code->src && (isalpha_(*val) || isdigit(*val)); val--, start--); if(start >= code->src) {