From a235f62277d88738802ec06dd2d4e876be9bd6a7 Mon Sep 17 00:00:00 2001 From: "BADIM-PC\\Vadim" Date: Wed, 20 Dec 2017 21:15:44 +0300 Subject: [PATCH] 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; }