shader-parser.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677
  1. /******************************************************************************
  2. Copyright (C) 2013 by Hugh Bailey <[email protected]>
  3. This program is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation, either version 3 of the License, or
  6. (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program. If not, see <http://www.gnu.org/licenses/>.
  13. ******************************************************************************/
  14. #include "shader-parser.h"
  15. enum shader_param_type get_shader_param_type(const char *type)
  16. {
  17. if (strcmp(type, "float") == 0)
  18. return SHADER_PARAM_FLOAT;
  19. else if (strcmp(type, "float2") == 0)
  20. return SHADER_PARAM_VEC2;
  21. else if (strcmp(type, "float3") == 0)
  22. return SHADER_PARAM_VEC3;
  23. else if (strcmp(type, "float4") == 0)
  24. return SHADER_PARAM_VEC4;
  25. else if (astrcmp_n(type, "texture", 7) == 0)
  26. return SHADER_PARAM_TEXTURE;
  27. else if (strcmp(type, "float3x3") == 0)
  28. return SHADER_PARAM_MATRIX3X3;
  29. else if (strcmp(type, "float4x4") == 0)
  30. return SHADER_PARAM_MATRIX4X4;
  31. else if (strcmp(type, "bool") == 0)
  32. return SHADER_PARAM_BOOL;
  33. else if (strcmp(type, "int") == 0)
  34. return SHADER_PARAM_INT;
  35. else if (strcmp(type, "string") == 0)
  36. return SHADER_PARAM_STRING;
  37. return SHADER_PARAM_UNKNOWN;
  38. }
  39. enum gs_sample_filter get_sample_filter(const char *filter)
  40. {
  41. if (astrcmpi(filter, "Anisotropy") == 0)
  42. return GS_FILTER_ANISOTROPIC;
  43. else if (astrcmpi(filter, "Point") == 0 ||
  44. strcmp(filter, "MIN_MAG_MIP_POINT") == 0)
  45. return GS_FILTER_POINT;
  46. else if (astrcmpi(filter, "Linear") == 0 ||
  47. strcmp(filter, "MIN_MAG_MIP_LINEAR") == 0)
  48. return GS_FILTER_LINEAR;
  49. else if (strcmp(filter, "MIN_MAG_POINT_MIP_LINEAR") == 0)
  50. return GS_FILTER_MIN_MAG_POINT_MIP_LINEAR;
  51. else if (strcmp(filter, "MIN_POINT_MAG_LINEAR_MIP_POINT") == 0)
  52. return GS_FILTER_MIN_POINT_MAG_LINEAR_MIP_POINT;
  53. else if (strcmp(filter, "MIN_POINT_MAG_MIP_LINEAR") == 0)
  54. return GS_FILTER_MIN_POINT_MAG_MIP_LINEAR;
  55. else if (strcmp(filter, "MIN_LINEAR_MAG_MIP_POINT") == 0)
  56. return GS_FILTER_MIN_LINEAR_MAG_MIP_POINT;
  57. else if (strcmp(filter, "MIN_LINEAR_MAG_POINT_MIP_LINEAR") == 0)
  58. return GS_FILTER_MIN_LINEAR_MAG_POINT_MIP_LINEAR;
  59. else if (strcmp(filter, "MIN_MAG_LINEAR_MIP_POINT") == 0)
  60. return GS_FILTER_MIN_MAG_LINEAR_MIP_POINT;
  61. return GS_FILTER_LINEAR;
  62. }
  63. extern enum gs_address_mode get_address_mode(const char *mode)
  64. {
  65. if (astrcmpi(mode, "Wrap") == 0 || astrcmpi(mode, "Repeat") == 0)
  66. return GS_ADDRESS_WRAP;
  67. else if (astrcmpi(mode, "Clamp") == 0 || astrcmpi(mode, "None") == 0)
  68. return GS_ADDRESS_CLAMP;
  69. else if (astrcmpi(mode, "Mirror") == 0)
  70. return GS_ADDRESS_MIRROR;
  71. else if (astrcmpi(mode, "Border") == 0)
  72. return GS_ADDRESS_BORDER;
  73. else if (astrcmpi(mode, "MirrorOnce") == 0)
  74. return GS_ADDRESS_MIRRORONCE;
  75. return GS_ADDRESS_CLAMP;
  76. }
  77. void shader_sampler_convert(struct shader_sampler *ss,
  78. struct gs_sampler_info *info)
  79. {
  80. size_t i;
  81. memset(info, 0, sizeof(struct gs_sampler_info));
  82. for (i = 0; i < ss->states.num; i++) {
  83. const char *state = ss->states.array[i];
  84. const char *value = ss->values.array[i];
  85. if (astrcmpi(state, "Filter") == 0)
  86. info->filter = get_sample_filter(value);
  87. else if (astrcmpi(state, "AddressU") == 0)
  88. info->address_u = get_address_mode(value);
  89. else if (astrcmpi(state, "AddressV") == 0)
  90. info->address_v = get_address_mode(value);
  91. else if (astrcmpi(state, "AddressW") == 0)
  92. info->address_w = get_address_mode(value);
  93. else if (astrcmpi(state, "MaxAnisotropy") == 0)
  94. info->max_anisotropy = strtol(value, NULL, 10);
  95. /*else if (astrcmpi(state, "BorderColor") == 0)
  96. // TODO */
  97. }
  98. }
  99. /* ------------------------------------------------------------------------- */
  100. static int sp_parse_sampler_state_item(struct shader_parser *sp,
  101. struct shader_sampler *ss)
  102. {
  103. int ret;
  104. char *state = NULL, *value = NULL;
  105. ret = next_name(&sp->cfp, &state, "state name", ";");
  106. if (ret != PARSE_SUCCESS) goto fail;
  107. ret = next_token_should_be(&sp->cfp, "=", ";", NULL);
  108. if (ret != PARSE_SUCCESS) goto fail;
  109. ret = next_name(&sp->cfp, &value, "value name", ";");
  110. if (ret != PARSE_SUCCESS) goto fail;
  111. ret = next_token_should_be(&sp->cfp, ";", ";", NULL);
  112. if (ret != PARSE_SUCCESS) goto fail;
  113. da_push_back(ss->states, &state);
  114. da_push_back(ss->values, &value);
  115. return ret;
  116. fail:
  117. bfree(state);
  118. bfree(value);
  119. return ret;
  120. }
  121. static void sp_parse_sampler_state(struct shader_parser *sp)
  122. {
  123. struct shader_sampler ss;
  124. struct cf_token peek;
  125. shader_sampler_init(&ss);
  126. if (next_name(&sp->cfp, &ss.name, "name", ";") != PARSE_SUCCESS)
  127. goto error;
  128. if (next_token_should_be(&sp->cfp, "{", ";", NULL) != PARSE_SUCCESS)
  129. goto error;
  130. if (!peek_valid_token(&sp->cfp, &peek))
  131. goto error;
  132. while (strref_cmp(&peek.str, "}") != 0) {
  133. int ret = sp_parse_sampler_state_item(sp, &ss);
  134. if (ret == PARSE_EOF)
  135. goto error;
  136. if (!peek_valid_token(&sp->cfp, &peek))
  137. goto error;
  138. }
  139. if (next_token_should_be(&sp->cfp, "}", ";", NULL) != PARSE_SUCCESS)
  140. goto error;
  141. if (next_token_should_be(&sp->cfp, ";", NULL, NULL) != PARSE_SUCCESS)
  142. goto error;
  143. da_push_back(sp->samplers, &ss);
  144. return;
  145. error:
  146. shader_sampler_free(&ss);
  147. }
  148. static inline int sp_parse_struct_var(struct shader_parser *sp,
  149. struct shader_var *var)
  150. {
  151. int errcode;
  152. /* -------------------------------------- */
  153. /* variable type */
  154. if (!next_valid_token(&sp->cfp)) return PARSE_EOF;
  155. if (token_is(&sp->cfp, ";")) return PARSE_CONTINUE;
  156. if (token_is(&sp->cfp, "}")) return PARSE_BREAK;
  157. errcode = token_is_type(&sp->cfp, CFTOKEN_NAME, "type name", ";");
  158. if (errcode != PARSE_SUCCESS)
  159. return errcode;
  160. copy_token(&sp->cfp, &var->type);
  161. /* -------------------------------------- */
  162. /* variable name */
  163. if (!next_valid_token(&sp->cfp)) return PARSE_EOF;
  164. if (token_is(&sp->cfp, ";")) return PARSE_UNEXPECTED_CONTINUE;
  165. if (token_is(&sp->cfp, "}")) return PARSE_UNEXPECTED_BREAK;
  166. errcode = token_is_type(&sp->cfp, CFTOKEN_NAME, "variable name", ";");
  167. if (errcode != PARSE_SUCCESS)
  168. return errcode;
  169. copy_token(&sp->cfp, &var->name);
  170. /* -------------------------------------- */
  171. /* variable mapping if any (POSITION, TEXCOORD, etc) */
  172. if (!next_valid_token(&sp->cfp)) return PARSE_EOF;
  173. if (token_is(&sp->cfp, ":")) {
  174. if (!next_valid_token(&sp->cfp)) return PARSE_EOF;
  175. if (token_is(&sp->cfp, ";")) return PARSE_UNEXPECTED_CONTINUE;
  176. if (token_is(&sp->cfp, "}")) return PARSE_UNEXPECTED_BREAK;
  177. errcode = token_is_type(&sp->cfp, CFTOKEN_NAME,
  178. "mapping name", ";");
  179. if (errcode != PARSE_SUCCESS)
  180. return errcode;
  181. copy_token(&sp->cfp, &var->mapping);
  182. if (!next_valid_token(&sp->cfp)) return PARSE_EOF;
  183. }
  184. /* -------------------------------------- */
  185. if (!token_is(&sp->cfp, ";")) {
  186. if (!go_to_valid_token(&sp->cfp, ";", "}"))
  187. return PARSE_EOF;
  188. return PARSE_CONTINUE;
  189. }
  190. return PARSE_SUCCESS;
  191. }
  192. static void sp_parse_struct(struct shader_parser *sp)
  193. {
  194. struct shader_struct ss;
  195. shader_struct_init(&ss);
  196. if (next_name(&sp->cfp, &ss.name, "name", ";") != PARSE_SUCCESS)
  197. goto error;
  198. if (next_token_should_be(&sp->cfp, "{", ";", NULL) != PARSE_SUCCESS)
  199. goto error;
  200. /* get structure variables */
  201. while (true) {
  202. bool do_break = false;
  203. struct shader_var var;
  204. shader_var_init(&var);
  205. switch (sp_parse_struct_var(sp, &var)) {
  206. case PARSE_UNEXPECTED_CONTINUE:
  207. cf_adderror_syntax_error(&sp->cfp);
  208. case PARSE_CONTINUE:
  209. shader_var_free(&var);
  210. continue;
  211. case PARSE_UNEXPECTED_BREAK:
  212. cf_adderror_syntax_error(&sp->cfp);
  213. case PARSE_BREAK:
  214. shader_var_free(&var);
  215. do_break = true;
  216. break;
  217. case PARSE_EOF:
  218. shader_var_free(&var);
  219. goto error;
  220. }
  221. if (do_break)
  222. break;
  223. da_push_back(ss.vars, &var);
  224. }
  225. if (next_token_should_be(&sp->cfp, ";", NULL, NULL) != PARSE_SUCCESS)
  226. goto error;
  227. da_push_back(sp->structs, &ss);
  228. return;
  229. error:
  230. shader_struct_free(&ss);
  231. }
  232. static inline int sp_check_for_keyword(struct shader_parser *sp,
  233. const char *keyword, bool *val)
  234. {
  235. bool new_val;
  236. new_val = token_is(&sp->cfp, keyword);
  237. if (new_val) {
  238. if (!next_valid_token(&sp->cfp))
  239. return PARSE_EOF;
  240. if (new_val && *val)
  241. cf_adderror(&sp->cfp, "'$1' keyword already specified",
  242. LEVEL_WARNING, keyword, NULL, NULL);
  243. *val = new_val;
  244. return PARSE_CONTINUE;
  245. }
  246. return PARSE_SUCCESS;
  247. }
  248. static inline int sp_parse_func_param(struct shader_parser *sp,
  249. struct shader_func *func, struct shader_var *var)
  250. {
  251. int errcode;
  252. bool is_uniform;
  253. if (!next_valid_token(&sp->cfp))
  254. return PARSE_EOF;
  255. errcode = sp_check_for_keyword(sp, "uniform", &is_uniform);
  256. if (errcode == PARSE_EOF)
  257. return PARSE_EOF;
  258. var->var_type = is_uniform ? SHADER_VAR_UNIFORM : SHADER_VAR_NONE;
  259. errcode = get_name(&sp->cfp, &var->type, "type", ")");
  260. if (errcode != PARSE_SUCCESS)
  261. return errcode;
  262. errcode = next_name(&sp->cfp, &var->name, "name", ")");
  263. if (errcode != PARSE_SUCCESS)
  264. return errcode;
  265. if (!next_valid_token(&sp->cfp))
  266. return PARSE_EOF;
  267. if (token_is(&sp->cfp, ":")) {
  268. errcode = next_name(&sp->cfp, &var->mapping,
  269. "mapping specifier", ")");
  270. if (errcode != PARSE_SUCCESS)
  271. return errcode;
  272. if (!next_valid_token(&sp->cfp))
  273. return PARSE_EOF;
  274. }
  275. return PARSE_SUCCESS;
  276. }
  277. static bool sp_parse_func_params(struct shader_parser *sp,
  278. struct shader_func *func)
  279. {
  280. struct cf_token peek;
  281. int errcode;
  282. cf_token_clear(&peek);
  283. if (!peek_valid_token(&sp->cfp, &peek))
  284. return false;
  285. if (*peek.str.array == ')') {
  286. next_token(&sp->cfp);
  287. goto exit;
  288. }
  289. do {
  290. struct shader_var var;
  291. shader_var_init(&var);
  292. if (!token_is(&sp->cfp, "(") && !token_is(&sp->cfp, ","))
  293. cf_adderror_syntax_error(&sp->cfp);
  294. errcode = sp_parse_func_param(sp, func, &var);
  295. if (errcode != PARSE_SUCCESS) {
  296. shader_var_free(&var);
  297. if (errcode == PARSE_CONTINUE)
  298. goto exit;
  299. else if (errcode == PARSE_EOF)
  300. return false;
  301. }
  302. da_push_back(func->params, &var);
  303. } while (!token_is(&sp->cfp, ")"));
  304. exit:
  305. return true;
  306. }
  307. static void sp_parse_function(struct shader_parser *sp,
  308. char *type, char *name)
  309. {
  310. struct shader_func func;
  311. shader_func_init(&func, type, name);
  312. if (!sp_parse_func_params(sp, &func))
  313. goto error;
  314. if (!next_valid_token(&sp->cfp))
  315. goto error;
  316. /* if function is mapped to something, for example COLOR */
  317. if (token_is(&sp->cfp, ":")) {
  318. if (!next_valid_token(&sp->cfp))
  319. goto error;
  320. if (!next_valid_token(&sp->cfp))
  321. goto error;
  322. }
  323. if (!token_is(&sp->cfp, "{")) {
  324. cf_adderror_expecting(&sp->cfp, "{");
  325. goto error;
  326. }
  327. func.start = sp->cfp.cur_token;
  328. if (!pass_pair(&sp->cfp, '{', '}'))
  329. goto error;
  330. /* it is established that the current token is '}' if we reach this */
  331. next_token(&sp->cfp);
  332. func.end = sp->cfp.cur_token;
  333. da_push_back(sp->funcs, &func);
  334. return;
  335. error:
  336. shader_func_free(&func);
  337. }
  338. /* parses "array[count]" */
  339. static bool sp_parse_param_array(struct shader_parser *sp,
  340. struct shader_var *param)
  341. {
  342. if (!next_valid_token(&sp->cfp))
  343. return false;
  344. if (sp->cfp.cur_token->type != CFTOKEN_NUM ||
  345. !valid_int_str(sp->cfp.cur_token->str.array,
  346. sp->cfp.cur_token->str.len))
  347. return false;
  348. param->array_count = strtol(sp->cfp.cur_token->str.array, NULL, 10);
  349. if (next_token_should_be(&sp->cfp, "]", ";", NULL) == PARSE_EOF)
  350. return false;
  351. if (!next_valid_token(&sp->cfp))
  352. return false;
  353. return true;
  354. }
  355. static inline int sp_parse_param_assign_intfloat(struct shader_parser *sp,
  356. struct shader_var *param, bool is_float)
  357. {
  358. int errcode;
  359. if (!next_valid_token(&sp->cfp))
  360. return PARSE_EOF;
  361. errcode = token_is_type(&sp->cfp, CFTOKEN_NUM, "numeric value", ";");
  362. if (errcode != PARSE_SUCCESS)
  363. return errcode;
  364. if (is_float) {
  365. float f = (float)strtod(sp->cfp.cur_token->str.array, NULL);
  366. da_push_back_array(param->default_val, &f, sizeof(float));
  367. } else {
  368. long l = strtol(sp->cfp.cur_token->str.array, NULL, 10);
  369. da_push_back_array(param->default_val, &l, sizeof(long));
  370. }
  371. return PARSE_SUCCESS;
  372. }
  373. /*
  374. * parses assignment for float1, float2, float3, float4, and any combination
  375. * for float3x3, float4x4, etc
  376. */
  377. static inline int sp_parse_param_assign_float_array(struct shader_parser *sp,
  378. struct shader_var *param)
  379. {
  380. const char *float_type = param->type+5;
  381. int float_count = 0, errcode, i;
  382. /* -------------------------------------------- */
  383. if (float_type[0] < '1' || float_type[0] > '4')
  384. cf_adderror(&sp->cfp, "Invalid row count", LEVEL_ERROR,
  385. NULL, NULL, NULL);
  386. float_count = float_type[0]-'0';
  387. if (float_type[1] == 'x') {
  388. if (float_type[2] < '1' || float_type[2] > '4')
  389. cf_adderror(&sp->cfp, "Invalid column count",
  390. LEVEL_ERROR, NULL, NULL, NULL);
  391. float_count *= float_type[2]-'0';
  392. }
  393. /* -------------------------------------------- */
  394. errcode = next_token_should_be(&sp->cfp, "{", ";", NULL);
  395. if (errcode != PARSE_SUCCESS) return errcode;
  396. for (i = 0; i < float_count; i++) {
  397. char *next = ((i+1) < float_count) ? "," : "}";
  398. errcode = sp_parse_param_assign_intfloat(sp, param, true);
  399. if (errcode != PARSE_SUCCESS) return errcode;
  400. errcode = next_token_should_be(&sp->cfp, next, ";", NULL);
  401. if (errcode != PARSE_SUCCESS) return errcode;
  402. }
  403. return PARSE_SUCCESS;
  404. }
  405. static int sp_parse_param_assignment_val(struct shader_parser *sp,
  406. struct shader_var *param)
  407. {
  408. if (strcmp(param->type, "int") == 0)
  409. return sp_parse_param_assign_intfloat(sp, param, false);
  410. else if (strcmp(param->type, "float") == 0)
  411. return sp_parse_param_assign_intfloat(sp, param, true);
  412. else if (astrcmp_n(param->type, "float", 5) == 0)
  413. return sp_parse_param_assign_float_array(sp, param);
  414. cf_adderror(&sp->cfp, "Invalid type '$1' used for assignment",
  415. LEVEL_ERROR, param->type, NULL, NULL);
  416. return PARSE_CONTINUE;
  417. }
  418. static inline bool sp_parse_param_assignment(struct shader_parser *sp,
  419. struct shader_var *param)
  420. {
  421. if (sp_parse_param_assignment_val(sp, param) != PARSE_SUCCESS)
  422. return false;
  423. if (!next_valid_token(&sp->cfp))
  424. return false;
  425. return true;
  426. }
  427. static void sp_parse_param(struct shader_parser *sp,
  428. char *type, char *name, bool is_const, bool is_uniform)
  429. {
  430. struct shader_var param;
  431. shader_var_init_param(&param, type, name, is_uniform, is_const);
  432. if (token_is(&sp->cfp, ";"))
  433. goto complete;
  434. if (token_is(&sp->cfp, "[") && !sp_parse_param_array(sp, &param))
  435. goto error;
  436. if (token_is(&sp->cfp, "=") && !sp_parse_param_assignment(sp, &param))
  437. goto error;
  438. if (!token_is(&sp->cfp, ";"))
  439. goto error;
  440. complete:
  441. da_push_back(sp->params, &param);
  442. return;
  443. error:
  444. shader_var_free(&param);
  445. }
  446. static bool sp_get_var_specifiers(struct shader_parser *sp,
  447. bool *is_const, bool *is_uniform)
  448. {
  449. while(true) {
  450. int errcode;
  451. errcode = sp_check_for_keyword(sp, "const", is_const);
  452. if (errcode == PARSE_EOF)
  453. return false;
  454. else if (errcode == PARSE_CONTINUE)
  455. continue;
  456. errcode = sp_check_for_keyword(sp, "uniform", is_uniform);
  457. if (errcode == PARSE_EOF)
  458. return false;
  459. else if (errcode == PARSE_CONTINUE)
  460. continue;
  461. break;
  462. }
  463. return true;
  464. }
  465. static inline void report_invalid_func_keyword(struct shader_parser *sp,
  466. const char *name, bool val)
  467. {
  468. if (val)
  469. cf_adderror(&sp->cfp, "'$1' keyword cannot be used with a "
  470. "function", LEVEL_ERROR,
  471. name, NULL, NULL);
  472. }
  473. static void sp_parse_other(struct shader_parser *sp)
  474. {
  475. bool is_const = false, is_uniform = false;
  476. char *type = NULL, *name = NULL;
  477. if (!sp_get_var_specifiers(sp, &is_const, &is_uniform))
  478. goto error;
  479. if (get_name(&sp->cfp, &type, "type", ";") != PARSE_SUCCESS)
  480. goto error;
  481. if (next_name(&sp->cfp, &name, "name", ";") != PARSE_SUCCESS)
  482. goto error;
  483. if (!next_valid_token(&sp->cfp))
  484. goto error;
  485. if (token_is(&sp->cfp, "(")) {
  486. report_invalid_func_keyword(sp, "const", is_const);
  487. report_invalid_func_keyword(sp, "uniform", is_uniform);
  488. sp_parse_function(sp, type, name);
  489. return;
  490. } else {
  491. sp_parse_param(sp, type, name, is_const, is_uniform);
  492. return;
  493. }
  494. error:
  495. bfree(type);
  496. bfree(name);
  497. }
  498. bool shader_parse(struct shader_parser *sp, const char *shader,
  499. const char *file)
  500. {
  501. if (!cf_parser_parse(&sp->cfp, shader, file))
  502. return false;
  503. while (sp->cfp.cur_token && sp->cfp.cur_token->type != CFTOKEN_NONE) {
  504. if (token_is(&sp->cfp, ";") ||
  505. is_whitespace(*sp->cfp.cur_token->str.array)) {
  506. sp->cfp.cur_token++;
  507. } else if (token_is(&sp->cfp, "struct")) {
  508. sp_parse_struct(sp);
  509. } else if (token_is(&sp->cfp, "sampler_state")) {
  510. sp_parse_sampler_state(sp);
  511. } else if (token_is(&sp->cfp, "{")) {
  512. cf_adderror(&sp->cfp, "Unexpected code segment",
  513. LEVEL_ERROR, NULL, NULL, NULL);
  514. pass_pair(&sp->cfp, '{', '}');
  515. } else {
  516. /* parameters and functions */
  517. sp_parse_other(sp);
  518. }
  519. }
  520. return !error_data_has_errors(&sp->cfp.error_list);
  521. }