tree-sitter: style

This commit is contained in:
Björn Linse
2019-06-15 13:12:59 +02:00
parent a361e09cc5
commit c1dc1bedba
2 changed files with 58 additions and 56 deletions

View File

@@ -829,7 +829,6 @@ static int create_tslua_parser(lua_State *L)
} }
const char *lang_name = lua_tostring(L, 1); const char *lang_name = lua_tostring(L, 1);
return tslua_push_parser(L, lang_name); return tslua_push_parser(L, lang_name);
} }

View File

@@ -86,7 +86,6 @@ void build_meta(lua_State *L, const char* tname, const luaL_Reg *meta)
/// all global state is stored in the regirstry of the lua_State /// all global state is stored in the regirstry of the lua_State
void tslua_init(lua_State *L) void tslua_init(lua_State *L)
{ {
langs = pmap_new(cstr_t)(); langs = pmap_new(cstr_t)();
// type metatables // type metatables
@@ -129,12 +128,14 @@ int ts_lua_register_lang(lua_State *L)
// at exit, to keep LeakSanitizer happy. // at exit, to keep LeakSanitizer happy.
uv_lib_t lib; uv_lib_t lib;
if (uv_dlopen(path, &lib)) { if (uv_dlopen(path, &lib)) {
return luaL_error(L, "Failed to load parser: uv_dlopen: %s", uv_dlerror(&lib)); return luaL_error(L, "Failed to load parser: uv_dlopen: %s",
uv_dlerror(&lib));
} }
TSLanguage *(*lang_parser)(void); TSLanguage *(*lang_parser)(void);
if (uv_dlsym(&lib, symbol_buf, (void **)&lang_parser)) { if (uv_dlsym(&lib, symbol_buf, (void **)&lang_parser)) {
return luaL_error(L, "Failed to load parser: uv_dlsym: %s", uv_dlerror(&lib)); return luaL_error(L, "Failed to load parser: uv_dlsym: %s",
uv_dlerror(&lib));
} }
TSLanguage *lang = lang_parser(); TSLanguage *lang = lang_parser();
@@ -192,17 +193,19 @@ static int parser_tostring(lua_State *L)
return 1; return 1;
} }
static const char *input_cb(void *payload, uint32_t byte_index, TSPoint position, uint32_t *bytes_read) static const char *input_cb(void *payload, uint32_t byte_index,
TSPoint position, uint32_t *bytes_read)
{ {
buf_T *bp = payload; buf_T *bp = payload;
static char buf[200]; #define BUFSIZE 256
static char buf[BUFSIZE];
if ((linenr_T)position.row >= bp->b_ml.ml_line_count) { if ((linenr_T)position.row >= bp->b_ml.ml_line_count) {
*bytes_read = 0; *bytes_read = 0;
return ""; return "";
} }
char_u *line = ml_get_buf(bp, position.row+1, false); char_u *line = ml_get_buf(bp, position.row+1, false);
size_t len = STRLEN(line); size_t len = STRLEN(line);
size_t tocopy = MIN(len-position.column,200); size_t tocopy = MIN(len-position.column, BUFSIZE);
// TODO: translate embedded \n to \000 // TODO: translate embedded \n to \000
memcpy(buf, line+position.column, tocopy); memcpy(buf, line+position.column, tocopy);
@@ -212,6 +215,7 @@ static const char *input_cb(void *payload, uint32_t byte_index, TSPoint position
(*bytes_read)++; (*bytes_read)++;
} }
return buf; return buf;
#undef BUFSIZE
} }
static int parser_parse_buf(lua_State *L) static int parser_parse_buf(lua_State *L)
@@ -253,8 +257,7 @@ static int parser_edit(lua_State *L)
{ {
if (lua_gettop(L) < 10) { if (lua_gettop(L) < 10) {
lua_pushstring(L, "not enough args to parser:edit()"); lua_pushstring(L, "not enough args to parser:edit()");
lua_error(L); return lua_error(L);
return 0; // unreachable
} }
Tslua_parser *p = parser_check(L); Tslua_parser *p = parser_check(L);