#477 outline func moved to TIC module

This commit is contained in:
BADIM-PC\Vadim
2017-12-22 14:20:15 +03:00
parent f8af6390ab
commit ef502b2496
6 changed files with 237 additions and 146 deletions

View File

@@ -25,6 +25,7 @@
#include <lua.h>
#include <lauxlib.h>
#include <lualib.h>
#include <ctype.h>
#include "machine.h"
#include "ext/moonscript.h"
@@ -1314,16 +1315,78 @@ static const char* const LuaKeywords [] =
"return", "then", "true", "until", "while"
};
static inline bool isalnum_(char c) {return isalnum(c) || c == '_';}
static const tic_outline_item* getLuaOutline(const char* code, s32* size)
{
enum{Size = sizeof(tic_outline_item)};
*size = 0;
static tic_outline_item* items = NULL;
if(items)
{
free(items);
items = NULL;
}
const char* ptr = code;
while(true)
{
static const char FuncString[] = "function ";
ptr = strstr(ptr, FuncString);
if(ptr)
{
ptr += sizeof FuncString - 1;
const char* start = ptr;
const char* end = start;
while(*ptr)
{
char c = *ptr;
if(isalnum_(c) || c == ':');
else if(c == '(')
{
end = ptr;
break;
}
else break;
ptr++;
}
if(end > start)
{
items = items ? realloc(items, (*size + 1) * Size) : malloc(Size);
items[*size].pos = start - code;
items[*size].size = end - start;
(*size)++;
}
}
else break;
}
return items;
}
static const tic_script_config LuaSyntaxConfig =
{
.lang = tic_script_lua,
.init = initLua,
.close = closeLua,
.tick = callLuaTick,
.scanline = callLuaScanline,
.overlap = callLuaOverlap,
.getOutline = getLuaOutline,
.blockCommentStart = "--[[",
.blockCommentEnd = "]]",
.singleComment = "--",
@@ -1353,16 +1416,66 @@ static const char* const MoonKeywords [] =
"from", "class", "extends", "new"
};
static const tic_outline_item* getMoonOutline(const char* code, s32* size)
{
enum{Size = sizeof(tic_outline_item)};
*size = 0;
static tic_outline_item* items = NULL;
if(items)
{
free(items);
items = NULL;
}
const char* ptr = code;
while(true)
{
static const char FuncString[] = "=->";
ptr = strstr(ptr, FuncString);
if(ptr)
{
const char* end = ptr;
ptr += sizeof FuncString - 1;
while(end >= code && !isalnum_(*end)) end--;
const char* start = end;
for (const char* val = start-1; val >= code && (isalnum_(*val)); val--, start--);
if(end > start)
{
items = items ? realloc(items, (*size + 1) * Size) : malloc(Size);
items[*size].pos = start - code;
items[*size].size = end - start + 1;
(*size)++;
}
}
else break;
}
return items;
}
static const tic_script_config MoonSyntaxConfig =
{
.lang = tic_script_moon,
.init = initMoonscript,
.close = closeLua,
.tick = callLuaTick,
.scanline = callLuaScanline,
.overlap = callLuaOverlap,
.getOutline = getMoonOutline,
.blockCommentStart = NULL,
.blockCommentEnd = NULL,
.blockStringStart = NULL,