block comment works
This commit is contained in:
parent
169877976e
commit
a235f62277
45
src/code.c
45
src/code.c
|
@ -404,24 +404,59 @@ static bool isWord(char symbol) {return isLetter(symbol) || isNumber(symbol);}
|
||||||
|
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
|
|
||||||
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)
|
static void parse(const char* start, u8* color)
|
||||||
{
|
{
|
||||||
const char* ptr = start;
|
const char* ptr = start;
|
||||||
|
|
||||||
const char* digitStart = NULL;
|
// const char* digitStart = NULL;
|
||||||
|
const char* blockCommentStart = NULL;
|
||||||
const char* singleCommentStart = 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)
|
while(true)
|
||||||
{
|
{
|
||||||
char c = *ptr;
|
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(singleCommentStart)
|
||||||
{
|
{
|
||||||
if(isLineEnd(c))
|
if(is_lineend(c))
|
||||||
{
|
{
|
||||||
memset(color + (singleCommentStart - start), getConfig()->theme.code.comment, ptr - singleCommentStart);
|
memset(color + (singleCommentStart - start), getConfig()->theme.code.comment, ptr - singleCommentStart);
|
||||||
singleCommentStart = NULL;
|
singleCommentStart = NULL;
|
||||||
|
@ -429,7 +464,7 @@ static void parse(const char* start, u8* color)
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if(c == Comment[1] && ptr > start && *(ptr-1) == Comment[0])
|
if(c == Comment && ptr > start && *(ptr-1) == Comment)
|
||||||
{
|
{
|
||||||
singleCommentStart = ptr-1;
|
singleCommentStart = ptr-1;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue