bool shader_parse(struct shader_parser *sp, const char *shader, const char *file) { if (!cf_parser_parse(&sp->cfp, shader, file)) return false; while (sp->cfp.cur_token && sp->cfp.cur_token->type != CFTOKEN_NONE) { if (cf_token_is(&sp->cfp, ";") || is_whitespace(*sp->cfp.cur_token->str.array)) { sp->cfp.cur_token++; } else if (cf_token_is(&sp->cfp, "struct")) { sp_parse_struct(sp); } else if (cf_token_is(&sp->cfp, "sampler_state")) { sp_parse_sampler_state(sp); } else if (cf_token_is(&sp->cfp, "{")) { cf_adderror(&sp->cfp, "Unexpected code segment", LEX_ERROR, NULL, NULL, NULL); cf_pass_pair(&sp->cfp, '{', '}'); } else { /* parameters and functions */ sp_parse_other(sp); } } return !error_data_has_errors(&sp->cfp.error_list); }
bool ep_parse(struct effect_parser *ep, gs_effect_t *effect, const char *effect_string, const char *file) { bool success; const char *graphics_preprocessor = gs_preprocessor_name(); if (graphics_preprocessor) { struct cf_def def; cf_def_init(&def); def.name.str.array = graphics_preprocessor; def.name.str.len = strlen(graphics_preprocessor); strref_copy(&def.name.unmerged_str, &def.name.str); cf_preprocessor_add_def(&ep->cfp.pp, &def); } ep->effect = effect; if (!cf_parser_parse(&ep->cfp, effect_string, file)) return false; while (ep->cfp.cur_token && ep->cfp.cur_token->type != CFTOKEN_NONE) { if (cf_token_is(&ep->cfp, ";") || is_whitespace(*ep->cfp.cur_token->str.array)) { /* do nothing */ ep->cfp.cur_token++; } else if (cf_token_is(&ep->cfp, "struct")) { ep_parse_struct(ep); } else if (cf_token_is(&ep->cfp, "technique")) { ep_parse_technique(ep); } else if (cf_token_is(&ep->cfp, "sampler_state")) { ep_parse_sampler_state(ep); } else if (cf_token_is(&ep->cfp, "{")) { /* add error and pass braces */ cf_adderror(&ep->cfp, "Unexpected code segment", LEX_ERROR, NULL, NULL, NULL); cf_pass_pair(&ep->cfp, '{', '}'); } else { /* parameters and functions */ ep_parse_other(ep); } } success = !error_data_has_errors(&ep->cfp.error_list); if (success) success = ep_compile(ep); return success; }
static void sp_parse_function(struct shader_parser *sp, char *type, char *name) { struct shader_func func; shader_func_init(&func, type, name); if (!sp_parse_func_params(sp, &func)) goto error; if (!cf_next_valid_token(&sp->cfp)) goto error; /* if function is mapped to something, for example COLOR */ if (cf_token_is(&sp->cfp, ":")) { char *mapping = NULL; int errorcode = cf_next_name(&sp->cfp, &mapping, "mapping", "{"); if (errorcode != PARSE_SUCCESS) goto error; func.mapping = mapping; if (!cf_next_valid_token(&sp->cfp)) goto error; } if (!cf_token_is(&sp->cfp, "{")) { cf_adderror_expecting(&sp->cfp, "{"); goto error; } func.start = sp->cfp.cur_token; if (!cf_pass_pair(&sp->cfp, '{', '}')) goto error; /* it is established that the current token is '}' if we reach this */ cf_next_token(&sp->cfp); func.end = sp->cfp.cur_token; da_push_back(sp->funcs, &func); return; error: shader_func_free(&func); }