forked from enlightenment/edi
syntax: don't slow down by repeating tokens
Clear out the token list before each parse callback loops
This commit is contained in:
parent
6e34ba51e8
commit
7489eb6e30
|
@ -57,3 +57,13 @@ EAPI void elm_code_line_token_add(Elm_Code_Line *line, int start, int end, int l
|
|||
elm_code_line_token_add(next_line, 1, end, lines - 1, type);
|
||||
}
|
||||
}
|
||||
|
||||
EAPI void elm_code_line_tokens_clear(Elm_Code_Line *line)
|
||||
{
|
||||
Elm_Code_Token *token;
|
||||
|
||||
EINA_LIST_FREE(line->tokens, token)
|
||||
free(token);
|
||||
line->tokens = NULL;
|
||||
}
|
||||
|
||||
|
|
|
@ -51,6 +51,8 @@ EAPI void elm_code_line_status_set(Elm_Code_Line *line, Elm_Code_Status_Type sta
|
|||
|
||||
EAPI void elm_code_line_token_add(Elm_Code_Line *line, int start, int end, int lines, Elm_Code_Token_Type type);
|
||||
|
||||
EAPI void elm_code_line_tokens_clear(Elm_Code_Line *line);
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
|
|
@ -22,6 +22,8 @@ _elm_code_parse_line(Elm_Code *code, Elm_Code_Line *line)
|
|||
Elm_Code_Parser *parser;
|
||||
Eina_List *item;
|
||||
|
||||
elm_code_line_tokens_clear(line);
|
||||
|
||||
EINA_LIST_FOREACH(code->parsers, item, parser)
|
||||
{
|
||||
if (parser->parse_line)
|
||||
|
@ -34,6 +36,12 @@ _elm_code_parse_file(Elm_Code *code, Elm_Code_File *file)
|
|||
{
|
||||
Elm_Code_Parser *parser;
|
||||
Eina_List *item;
|
||||
Elm_Code_Line *line;
|
||||
|
||||
EINA_LIST_FOREACH(file->lines, item, line)
|
||||
{
|
||||
elm_code_line_tokens_clear(line);
|
||||
}
|
||||
|
||||
EINA_LIST_FOREACH(code->parsers, item, parser)
|
||||
{
|
||||
|
|
|
@ -9,6 +9,7 @@ elm_code_suite_SOURCES = \
|
|||
elm_code_file_test_load.c \
|
||||
elm_code_file_test_memory.c \
|
||||
elm_code_test_basic.c \
|
||||
elm_code_test_line.c \
|
||||
elm_code_test_parse.c \
|
||||
elm_code_test_text.c \
|
||||
widget/elm_code_test_widget.c \
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
void elm_code_file_test_load(TCase *tc);
|
||||
void elm_code_file_test_memory(TCase *tc);
|
||||
void elm_code_test_basic(TCase *tc);
|
||||
void elm_code_test_line(TCase *tc);
|
||||
void elm_code_test_parse(TCase *tc);
|
||||
void elm_code_test_text(TCase *tc);
|
||||
void elm_code_test_widget(TCase *tc);
|
||||
|
|
|
@ -0,0 +1,52 @@
|
|||
#ifdef HAVE_CONFIG_H
|
||||
# include "config.h"
|
||||
#endif
|
||||
|
||||
#include "elm_code_suite.h"
|
||||
|
||||
START_TEST (elm_code_line_create_test)
|
||||
{
|
||||
Elm_Code *code;
|
||||
Elm_Code_File *file;
|
||||
Elm_Code_Line *line;
|
||||
|
||||
code = elm_code_create();
|
||||
file = elm_code_file_new(code);
|
||||
|
||||
elm_code_file_line_append(file, "a test string...", 16, NULL);
|
||||
line = elm_code_file_line_get(file, 1);
|
||||
|
||||
ck_assert(!!line);
|
||||
|
||||
elm_code_free(code);
|
||||
}
|
||||
END_TEST
|
||||
|
||||
START_TEST (elm_code_line_token_count_test)
|
||||
{
|
||||
Elm_Code *code;
|
||||
Elm_Code_File *file;
|
||||
Elm_Code_Line *line;
|
||||
|
||||
code = elm_code_create();
|
||||
file = elm_code_file_new(code);
|
||||
|
||||
elm_code_file_line_append(file, "a test string...", 16, NULL);
|
||||
line = elm_code_file_line_get(file, 1);
|
||||
|
||||
ck_assert_int_eq(0, eina_list_count(line->tokens));
|
||||
elm_code_line_token_add(line, 2, 5, 1, ELM_CODE_TOKEN_TYPE_COMMENT);
|
||||
ck_assert_int_eq(1, eina_list_count(line->tokens));
|
||||
elm_code_line_tokens_clear(line);
|
||||
ck_assert_int_eq(0, eina_list_count(line->tokens));
|
||||
|
||||
elm_code_free(code);
|
||||
}
|
||||
END_TEST
|
||||
|
||||
void elm_code_test_line(TCase *tc)
|
||||
{
|
||||
tcase_add_test(tc, elm_code_line_create_test);
|
||||
tcase_add_test(tc, elm_code_line_token_count_test);
|
||||
}
|
||||
|
Loading…
Reference in New Issue