#477 added block string [[ string ]] highlight
This commit is contained in:
parent
63c0c77ea5
commit
b26eb6bd1c
76
src/code.c
76
src/code.c
|
@ -198,6 +198,8 @@ typedef struct
|
||||||
{
|
{
|
||||||
const char* blockCommentStart;
|
const char* blockCommentStart;
|
||||||
const char* blockCommentEnd;
|
const char* blockCommentEnd;
|
||||||
|
const char* blockStringStart;
|
||||||
|
const char* blockStringEnd;
|
||||||
const char* singleCommentStart;
|
const char* singleCommentStart;
|
||||||
|
|
||||||
const char* const * keywords;
|
const char* const * keywords;
|
||||||
|
@ -217,6 +219,8 @@ static const SyntaxConfig LuaSyntaxConfig =
|
||||||
.blockCommentStart = "--[[",
|
.blockCommentStart = "--[[",
|
||||||
.blockCommentEnd = "]]",
|
.blockCommentEnd = "]]",
|
||||||
.singleCommentStart = "--",
|
.singleCommentStart = "--",
|
||||||
|
.blockStringStart = "[[",
|
||||||
|
.blockStringEnd = "]]",
|
||||||
.keywords = LuaKeywords,
|
.keywords = LuaKeywords,
|
||||||
.keywordsCount = COUNT_OF(LuaKeywords),
|
.keywordsCount = COUNT_OF(LuaKeywords),
|
||||||
};
|
};
|
||||||
|
@ -234,8 +238,10 @@ static const char* const MoonKeywords [] =
|
||||||
|
|
||||||
static const SyntaxConfig MoonSyntaxConfig =
|
static const SyntaxConfig MoonSyntaxConfig =
|
||||||
{
|
{
|
||||||
.blockCommentStart = "--[[",
|
.blockCommentStart = NULL,
|
||||||
.blockCommentEnd = "]]",
|
.blockCommentEnd = NULL,
|
||||||
|
.blockStringStart = NULL,
|
||||||
|
.blockStringEnd = NULL,
|
||||||
.singleCommentStart = "--",
|
.singleCommentStart = "--",
|
||||||
.keywords = MoonKeywords,
|
.keywords = MoonKeywords,
|
||||||
.keywordsCount = COUNT_OF(MoonKeywords),
|
.keywordsCount = COUNT_OF(MoonKeywords),
|
||||||
|
@ -253,6 +259,8 @@ static const SyntaxConfig JsSyntaxConfig =
|
||||||
{
|
{
|
||||||
.blockCommentStart = "/*",
|
.blockCommentStart = "/*",
|
||||||
.blockCommentEnd = "*/",
|
.blockCommentEnd = "*/",
|
||||||
|
.blockStringStart = NULL,
|
||||||
|
.blockStringEnd = NULL,
|
||||||
.singleCommentStart = "//",
|
.singleCommentStart = "//",
|
||||||
.keywords = JsKeywords,
|
.keywords = JsKeywords,
|
||||||
.keywordsCount = COUNT_OF(JsKeywords),
|
.keywordsCount = COUNT_OF(JsKeywords),
|
||||||
|
@ -264,6 +272,7 @@ static void parse(const char* start, u8* color, const SyntaxConfig* config)
|
||||||
|
|
||||||
const char* blockCommentStart = NULL;
|
const char* blockCommentStart = NULL;
|
||||||
const char* blockStringStart = NULL;
|
const char* blockStringStart = NULL;
|
||||||
|
const char* blockStdStringStart = NULL;
|
||||||
const char* singleCommentStart = NULL;
|
const char* singleCommentStart = NULL;
|
||||||
const char* wordStart = NULL;
|
const char* wordStart = NULL;
|
||||||
const char* numberStart = NULL;
|
const char* numberStart = NULL;
|
||||||
|
@ -283,18 +292,24 @@ static void parse(const char* start, u8* color, const SyntaxConfig* config)
|
||||||
}
|
}
|
||||||
else if(blockStringStart)
|
else if(blockStringStart)
|
||||||
{
|
{
|
||||||
const char* blockStart = blockStringStart+1;
|
const char* end = strstr(ptr, config->blockStringEnd);
|
||||||
|
|
||||||
|
ptr = end ? end + strlen(config->blockStringEnd) : blockStringStart + strlen(blockStringStart);
|
||||||
|
memset(color + (blockStringStart - start), getConfig()->theme.code.string, ptr - blockStringStart);
|
||||||
|
blockStringStart = NULL;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
else if(blockStdStringStart)
|
||||||
|
{
|
||||||
|
const char* blockStart = blockStdStringStart+1;
|
||||||
|
|
||||||
while(true)
|
while(true)
|
||||||
{
|
{
|
||||||
const char* pos = strchr(blockStart, *blockStringStart);
|
const char* pos = strchr(blockStart, *blockStdStringStart);
|
||||||
|
|
||||||
if(pos)
|
if(pos)
|
||||||
{
|
{
|
||||||
if(*(pos-1) == '\\' && *(pos-2) != '\\')
|
if(*(pos-1) == '\\' && *(pos-2) != '\\') blockStart = pos + 1;
|
||||||
{
|
|
||||||
blockStart = pos + 1;
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
ptr = pos + 1;
|
ptr = pos + 1;
|
||||||
|
@ -303,13 +318,13 @@ static void parse(const char* start, u8* color, const SyntaxConfig* config)
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
ptr = blockStringStart + strlen(blockStringStart);
|
ptr = blockStdStringStart + strlen(blockStdStringStart);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
memset(color + (blockStringStart - start), getConfig()->theme.code.string, ptr - blockStringStart);
|
memset(color + (blockStdStringStart - start), getConfig()->theme.code.string, ptr - blockStdStringStart);
|
||||||
blockStringStart = NULL;
|
blockStdStringStart = NULL;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
else if(singleCommentStart)
|
else if(singleCommentStart)
|
||||||
|
@ -379,53 +394,44 @@ static void parse(const char* start, u8* color, const SyntaxConfig* config)
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
s32 blockCommentStartSize = strlen(config->blockCommentStart);
|
if(config->blockCommentStart && memcmp(ptr, config->blockCommentStart, strlen(config->blockCommentStart)) == 0)
|
||||||
if(c == config->blockCommentStart[0] && memcmp(ptr, config->blockCommentStart, blockCommentStartSize) == 0)
|
|
||||||
{
|
{
|
||||||
blockCommentStart = ptr;
|
blockCommentStart = ptr;
|
||||||
ptr += blockCommentStartSize;
|
ptr += strlen(config->blockCommentStart);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
else
|
if(config->blockStringStart && memcmp(ptr, config->blockStringStart, strlen(config->blockStringStart)) == 0)
|
||||||
{
|
|
||||||
if(c == '"' || c == '\'')
|
|
||||||
{
|
{
|
||||||
blockStringStart = ptr;
|
blockStringStart = ptr;
|
||||||
|
ptr += strlen(config->blockStringStart);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
else if(c == '"' || c == '\'')
|
||||||
|
{
|
||||||
|
blockStdStringStart = ptr;
|
||||||
ptr++;
|
ptr++;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
else
|
else if(config->singleCommentStart && memcmp(ptr, config->singleCommentStart, strlen(config->singleCommentStart)) == 0)
|
||||||
{
|
|
||||||
s32 singleCommentStartSize = strlen(config->singleCommentStart);
|
|
||||||
|
|
||||||
if(c == config->singleCommentStart[0] && memcmp(ptr, config->singleCommentStart, singleCommentStartSize) == 0)
|
|
||||||
{
|
{
|
||||||
singleCommentStart = ptr;
|
singleCommentStart = ptr;
|
||||||
ptr += singleCommentStartSize;
|
ptr += strlen(config->singleCommentStart);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
else
|
else if(isalpha_(c))
|
||||||
{
|
|
||||||
if(isalpha_(c))
|
|
||||||
{
|
{
|
||||||
wordStart = ptr;
|
wordStart = ptr;
|
||||||
ptr++;
|
ptr++;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
else
|
else if(isdigit(c) || (c == '.' && isdigit(ptr[1])))
|
||||||
{
|
|
||||||
if(isdigit(c) || (c == '.' && isdigit(ptr[1])))
|
|
||||||
{
|
{
|
||||||
numberStart = ptr;
|
numberStart = ptr;
|
||||||
ptr++;
|
ptr++;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
else if(ispunct(c))
|
else if(ispunct(c)) color[ptr - start] = getConfig()->theme.code.sign;
|
||||||
color[ptr - start] = getConfig()->theme.code.sign;
|
else if(iscntrl(c)) color[ptr - start] = getConfig()->theme.code.other;
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!c) break;
|
if(!c) break;
|
||||||
|
|
Loading…
Reference in New Issue