8#ifndef PRINTLINES_ALLOWED
9#define PRINTLINES_ALLOWED 1
12static const char *FNAME =
"kest_eff_parser.c";
55 size_t len = strnlen(str, n);
59 if (!new_str)
return NULL;
60 memcpy(new_str, str, len);
97 int section_start_score = 0;
98 int next_section_start_score;
103 while (current_token)
107 if (current_token->
data)
117 if (section_start_score == 2)
119 if (next_section_start_score == 3)
127 next_section->
data = NULL;
128 next_section->
next = NULL;
129 next_section->
child = NULL;
147 next_section->
data = (
void*)ns;
149 if (current_section && cs)
152 current_section->
next = next_section;
156 root->
child = next_section;
159 current_section = next_section;
160 current_sec_start = current_token;
169 section_start_score = 0;
173 section_start_score = next_section_start_score;
177 prev_tokens[0] = current_token;
178 prev_tokens[1] = prev_tokens[0];
179 prev_tokens[2] = prev_tokens[1];
180 prev_tokens[3] = prev_tokens[2];
182 current_token = current_token->
next;
192 current_section = root->
child;
205 while (current_section)
211 current_section = current_section->
next;
215 if (strcmp(sect->
name,
"INFO") == 0)
221 info_section = current_section;
223 else if (strcmp(sect->
name,
"RESOURCES") == 0)
229 resources_section = current_section;
231 else if (strcmp(sect->
name,
"PARAMETERS") == 0)
237 parameters_section = current_section;
239 else if (strcmp(sect->
name,
"SETTINGS") == 0)
245 settings_section = current_section;
247 else if (strcmp(sect->
name,
"DEFS") == 0)
253 defs_section = current_section;
255 else if (strcmp(sect->
name,
"CODE") == 0)
257 code_section = current_section;
268 current_section = current_section->
next;
304 if (resources_section)
314 if (parameters_section)
325 if (settings_section)
399 for (
int i = 0; i < ps->
n_lines; i++)
435 kest_dsp_resource_pll *res = ps->
resources;
461 printf(
"kest_read_eff_desc_from_file\n");
479 FILE *src = fopen(fname,
"r");
483 KEST_PRINTF(
"Failed to open file \"%s\"!\n", fname);
487 fseek(src, 0, SEEK_END);
489 fseek(src, SEEK_SET, 0);
515 KEST_PRINTF(
"File \"%s\" ignored due to errors.\n", fname);
525 KEST_PRINTF(
"File \"%s\" ignored due to errors.\n", fname);
532 kest_dsp_resource_pll_free(ps.
resources);
536 kest_block_pll_free(ps.
blocks);
543 KEST_PRINTF(
"File \"%s\" parsed sucessfully\n", fname);
581#define KEST_PARSER_PRINT_BUFLEN 1024
582#define KEST_PARSER_PRINT_LOC_BUFLEN 128
589#define PR_LINE_INDENT 4
601 buf[buf_pos++] =
' ';
603 for (i = 0; i < index && buf_pos + 1 < buf_len && line[i] != 0; i++)
604 buf[buf_pos++] = line[i];
608 for (j = 0;
err_colour[j] != 0 && buf_pos + 1 < buf_len; j++)
609 buf[buf_pos++] = colour[j];
612 for (j = 0; j < length && buf_pos < buf_len; j++)
613 buf[buf_pos++] = line[i++];
617 for (j = 0;
reset_colour[j] != 0 && buf_pos + 1 < buf_len; j++)
621 for (j = 0; line[i] != 0 && buf_pos + 1 < buf_len; j++)
622 buf[buf_pos++] = line[i++];
626 buf[buf_pos < buf_len ? buf_pos : buf_len - 1] = 0;
631 buf[buf_pos++] =
'\n';
635 buf[buf_pos++] =
'~';
637 buf[buf_pos++] =
'^';
648 vsnprintf(buf,
sizeof(buf), msg, args);
652 if (ps->
fname && token)
676 vsnprintf(buf,
sizeof(buf), msg, args);
680 if (ps->
fname && token)
687 KEST_PRINTF_(
"\e[01;32mWARNING%s\e[0m: %s\n", loc_string, buf);
709 vsnprintf(buf,
sizeof(buf), msg, args);
713 if (ps->
fname && token)
738 vsnprintf(buf,
sizeof(buf), msg, args);
749 KEST_PRINTF_(
"\e[01;36mINFO%s\e[0m: %s\n", loc_string, buf);
757 vsnprintf(buf,
sizeof(buf), msg, args);
768 KEST_PRINTF_(
"\e[01;32mWARNING%s\e[0m: %s\n", loc_string, buf);
776 vsnprintf(buf,
sizeof(buf), msg, args);
788 KEST_PRINTF_(
"\e[01;31mERROR%s\e[0m: %s\n", loc_string, buf);
796 vsnprintf(buf,
sizeof(buf), msg, args);
800 if (ps->
fname && node)
807 KEST_PRINTF_(
"\e[01;36mINFO%s\e[0m: %s\n", loc_string, buf);
815 vsnprintf(buf,
sizeof(buf), msg, args);
819 if (ps->
fname && node)
826 KEST_PRINTF_(
"\e[01;32mWARNING%s\e[0m: %s\n", loc_string, buf);
834 vsnprintf(buf,
sizeof(buf), msg, args);
838 if (ps->
fname && node)
846 KEST_PRINTF_(
"\e[01;31mERROR%s\e[0m: %s\n", loc_string, buf);
854 vsnprintf(buf,
sizeof(buf), msg, args);
865 KEST_PRINTF_(
"\e[01;36INFO%s\e[0m: %s\n", loc_string, buf);
873 vsnprintf(buf,
sizeof(buf), msg, args);
884 KEST_PRINTF_(
"\e[01;32mWARNING%s\e[0m: %s\n", loc_string, buf);
892 vsnprintf(buf,
sizeof(buf), msg, args);
905 KEST_PRINTF_(
"\e[01;31mERROR%s\e[0m: %s\n", loc_string, buf);
void * kest_alloc(size_t size)
char * kest_strndup(const char *str, size_t n)
int kest_process_asm_lines(kest_eff_parsing_state *ps)
int kest_bump_arena_reset(kest_bump_arena *arena)
int kest_bump_arena_init(kest_bump_arena *arena, size_t capacity)
void * kest_bump_arena_alloc(kest_bump_arena *arena, size_t size)
int kest_bump_arena_destroy(kest_bump_arena *arena)
int kest_init_effect_desc(kest_effect_desc *eff)
int kest_effect_desc_generate_res_rpt(kest_effect_desc *eff)
char * kest_parser_strndup(const char *str, int n)
int kest_parser_lineize_content(kest_eff_parsing_state *ps)
void kest_parser_print_info_at_node(kest_eff_parsing_state *ps, kest_ast_node *node, const char *msg,...)
int init_parsing_state(kest_eff_parsing_state *ps)
int kest_parser_mempool_initialised
void kest_parser_warn_at_line(kest_eff_parsing_state *ps, int line, const char *msg,...)
void kest_parser_warn_at_node(kest_eff_parsing_state *ps, kest_ast_node *node, const char *msg,...)
#define KEST_PARSER_PRINT_BUFLEN
const char * reset_colour
kest_allocator * kest_parser_allocator
int kest_eff_parser_reset_mempool()
int kest_parse_tokens(kest_eff_parsing_state *ps)
int kest_parser_compute_formats(kest_eff_parsing_state *ps)
void kest_parser_warn_at(kest_eff_parsing_state *ps, kest_token_ll *token, const char *msg,...)
void kest_parser_print_info_at_line(kest_eff_parsing_state *ps, int line, const char *msg,...)
int kest_eff_parser_init_mempool()
void kest_parser_print_info(kest_eff_parsing_state *ps, const char *msg,...)
int kest_parser_format_offending_section(char *line, int index, int length, char *buf, int buf_len, char *colour)
void kest_parser_error_at_node(kest_eff_parsing_state *ps, kest_ast_node *node, const char *msg,...)
#define KEST_PARSER_PRINT_LOC_BUFLEN
void kest_parser_error(kest_eff_parsing_state *ps, const char *msg,...)
kest_bump_arena kest_eff_parser_mempool
void * kest_parser_alloc(size_t size)
void kest_parser_print_info_at(kest_eff_parsing_state *ps, kest_token_ll *token, const char *msg,...)
kest_effect_desc * kest_read_eff_desc_from_file(char *fname)
int kest_eff_parser_deinit_mempool()
void kest_parser_error_at_line(kest_eff_parsing_state *ps, int line, const char *msg,...)
void kest_parser_error_at(kest_eff_parsing_state *ps, kest_token_ll *token, const char *msg,...)
void kest_parser_warn(kest_eff_parsing_state *ps, const char *msg,...)
#define KEST_AST_NODE_SECTION
#define KEST_EFF_PARSER_MEM_POOL_SIZE_KB
#define KEST_AST_NODE_ROOT
int kest_parse_dictionary_section(kest_eff_parsing_state *ps, kest_ast_node *section)
int kest_resources_section_extract(kest_eff_parsing_state *ps, kest_dsp_resource_pll **list, kest_ast_node *sect)
int kest_parameters_section_extract(kest_eff_parsing_state *ps, kest_parameter_pll **list, kest_ast_node *sect)
int kest_dictionary_section_lookup_str(kest_ast_node *section, const char *name, const char **result)
int kest_parse_code_section(kest_eff_parsing_state *ps, kest_ast_node *section)
int kest_settings_section_extract(kest_eff_parsing_state *ps, kest_setting_pll **list, kest_ast_node *sect)
int kest_defs_section_extract(kest_eff_parsing_state *ps, kest_expr_scope *scope, struct kest_ast_node *sect)
int get_section_start_score(char *str, int current_score)
const char * kest_error_code_to_string(int error_code)
int kest_expr_scope_add_settings(kest_expr_scope *scope, kest_setting_pll *settings)
int kest_expr_scope_init(kest_expr_scope *scope)
int kest_expr_scope_add_params(kest_expr_scope *scope, kest_parameter_pll *params)
int kest_filter_compute_format(kest_filter *filter, kest_expr_scope *scope)
int kest_settings_assign_ids(kest_setting_pll *list)
int kest_parameters_assign_ids(kest_parameter_pll *list)
#define KEST_PRINTF_(...)
int kest_resources_assign_handles(kest_dsp_resource_pll *list)
#define KEST_DSP_RESOURCE_FILTER
int token_is_newline(char *str)
int kest_tokenize_content(kest_eff_parsing_state *ps)
kest_token_ll * kest_token_span_to_ll(kest_token_ll *start, kest_token_ll *end)
struct kest_ast_node * child
struct kest_ast_node * next
struct kest_dictionary * dict
kest_token_ll * current_token
kest_named_expression_pll * def_exprs
kest_dsp_resource_pll * resources
kest_parameter_pll * parameters
kest_setting_pll * settings
struct kest_asm_line_pll * asm_lines
kest_parameter_pll * parameters
kest_setting_pll * settings
kest_dsp_resource_pll * resources
kest_named_expression_pll * def_exprs
struct kest_token_ll * next