NCDConfigParser_parse.y 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854
  1. /**
  2. * @file NCDConfigParser.y
  3. * @author Ambroz Bizjak <ambrop7@gmail.com>
  4. *
  5. * @section LICENSE
  6. *
  7. * Redistribution and use in source and binary forms, with or without
  8. * modification, are permitted provided that the following conditions are met:
  9. * 1. Redistributions of source code must retain the above copyright
  10. * notice, this list of conditions and the following disclaimer.
  11. * 2. Redistributions in binary form must reproduce the above copyright
  12. * notice, this list of conditions and the following disclaimer in the
  13. * documentation and/or other materials provided with the distribution.
  14. * 3. Neither the name of the author nor the
  15. * names of its contributors may be used to endorse or promote products
  16. * derived from this software without specific prior written permission.
  17. *
  18. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  19. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  20. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  21. * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
  22. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  23. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  24. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  25. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  26. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  27. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  28. */
  29. %include {
  30. #include <string.h>
  31. #include <stddef.h>
  32. #include <misc/debug.h>
  33. #include <misc/concat_strings.h>
  34. #include <ncd/NCDAst.h>
  35. struct parser_out {
  36. int out_of_memory;
  37. int syntax_error;
  38. int have_ast;
  39. NCDProgram ast;
  40. };
  41. struct token {
  42. char *str;
  43. size_t len;
  44. };
  45. struct program {
  46. int have;
  47. NCDProgram v;
  48. };
  49. struct block {
  50. int have;
  51. NCDBlock v;
  52. };
  53. struct statement {
  54. int have;
  55. NCDStatement v;
  56. };
  57. struct ifblock {
  58. int have;
  59. NCDIfBlock v;
  60. };
  61. struct value {
  62. int have;
  63. NCDValue v;
  64. };
  65. static void free_token (struct token o) { free(o.str); }
  66. static void free_program (struct program o) { if (o.have) NCDProgram_Free(&o.v); }
  67. static void free_block (struct block o) { if (o.have) NCDBlock_Free(&o.v); }
  68. static void free_statement (struct statement o) { if (o.have) NCDStatement_Free(&o.v); }
  69. static void free_ifblock (struct ifblock o) { if (o.have) NCDIfBlock_Free(&o.v); }
  70. static void free_value (struct value o) { if (o.have) NCDValue_Free(&o.v); }
  71. }
  72. %extra_argument { struct parser_out *parser_out }
  73. %token_type { struct token }
  74. %token_destructor { free_token($$); }
  75. %type processes { struct program }
  76. %type statement { struct statement }
  77. %type elif_maybe { struct ifblock }
  78. %type elif { struct ifblock }
  79. %type else_maybe { struct block }
  80. %type statements { struct block }
  81. %type dotted_name { char * }
  82. %type statement_args_maybe { struct value }
  83. %type list_contents { struct value }
  84. %type list { struct value }
  85. %type map_contents { struct value }
  86. %type map { struct value }
  87. %type invoc { struct value }
  88. %type value { struct value }
  89. %type name_maybe { char * }
  90. %type process_or_template { int }
  91. %type name_list { struct value }
  92. // mention parser_out in some destructor to avoid an unused-variable warning
  93. %destructor processes { (void)parser_out; free_program($$); }
  94. %destructor statement { free_statement($$); }
  95. %destructor elif_maybe { free_ifblock($$); }
  96. %destructor elif { free_ifblock($$); }
  97. %destructor else_maybe { free_block($$); }
  98. %destructor statements { free_block($$); }
  99. %destructor dotted_name { free($$); }
  100. %destructor statement_args_maybe { free_value($$); }
  101. %destructor list_contents { free_value($$); }
  102. %destructor list { free_value($$); }
  103. %destructor map_contents { free_value($$); }
  104. %destructor map { free_value($$); }
  105. %destructor invoc { free_value($$); }
  106. %destructor value { free_value($$); }
  107. %destructor name_maybe { free($$); }
  108. %destructor name_list { free_value($$); }
  109. %stack_size 0
  110. %syntax_error {
  111. parser_out->syntax_error = 1;
  112. }
  113. // workaroud Lemon bug: if the stack overflows, the token that caused the overflow will be leaked
  114. %stack_overflow {
  115. if (yypMinor) {
  116. free_token(yypMinor->yy0);
  117. }
  118. }
  119. input ::= processes(A). {
  120. ASSERT(!parser_out->have_ast)
  121. if (A.have) {
  122. parser_out->have_ast = 1;
  123. parser_out->ast = A.v;
  124. }
  125. }
  126. processes(R) ::= . {
  127. NCDProgram prog;
  128. NCDProgram_Init(&prog);
  129. R.have = 1;
  130. R.v = prog;
  131. }
  132. processes(R) ::= INCLUDE STRING(A) processes(N). {
  133. ASSERT(A.str)
  134. if (!N.have) {
  135. goto failA0;
  136. }
  137. NCDProgramElem elem;
  138. if (!NCDProgramElem_InitInclude(&elem, A.str, A.len)) {
  139. goto failA0;
  140. }
  141. if (!NCDProgram_PrependElem(&N.v, elem)) {
  142. goto failA1;
  143. }
  144. R.have = 1;
  145. R.v = N.v;
  146. N.have = 0;
  147. goto doneA;
  148. failA1:
  149. NCDProgramElem_Free(&elem);
  150. failA0:
  151. R.have = 0;
  152. parser_out->out_of_memory = 1;
  153. doneA:
  154. free_token(A);
  155. free_program(N);
  156. }
  157. processes(R) ::= INCLUDE_GUARD STRING(A) processes(N). {
  158. ASSERT(A.str)
  159. if (!N.have) {
  160. goto failZ0;
  161. }
  162. NCDProgramElem elem;
  163. if (!NCDProgramElem_InitIncludeGuard(&elem, A.str, A.len)) {
  164. goto failZ0;
  165. }
  166. if (!NCDProgram_PrependElem(&N.v, elem)) {
  167. goto failZ1;
  168. }
  169. R.have = 1;
  170. R.v = N.v;
  171. N.have = 0;
  172. goto doneZ;
  173. failZ1:
  174. NCDProgramElem_Free(&elem);
  175. failZ0:
  176. R.have = 0;
  177. parser_out->out_of_memory = 1;
  178. doneZ:
  179. free_token(A);
  180. free_program(N);
  181. }
  182. processes(R) ::= process_or_template(T) NAME(A) CURLY_OPEN statements(B) CURLY_CLOSE processes(N). {
  183. ASSERT(A.str)
  184. if (!B.have || !N.have) {
  185. goto failB0;
  186. }
  187. NCDProcess proc;
  188. if (!NCDProcess_Init(&proc, T, A.str, B.v)) {
  189. goto failB0;
  190. }
  191. B.have = 0;
  192. NCDProgramElem elem;
  193. NCDProgramElem_InitProcess(&elem, proc);
  194. if (!NCDProgram_PrependElem(&N.v, elem)) {
  195. goto failB1;
  196. }
  197. R.have = 1;
  198. R.v = N.v;
  199. N.have = 0;
  200. goto doneB;
  201. failB1:
  202. NCDProgramElem_Free(&elem);
  203. failB0:
  204. R.have = 0;
  205. parser_out->out_of_memory = 1;
  206. doneB:
  207. free_token(A);
  208. free_block(B);
  209. free_program(N);
  210. }
  211. statement(R) ::= dotted_name(A) ROUND_OPEN statement_args_maybe(B) ROUND_CLOSE name_maybe(C) SEMICOLON. {
  212. if (!A || !B.have) {
  213. goto failC0;
  214. }
  215. if (!NCDStatement_InitReg(&R.v, C, NULL, A, B.v)) {
  216. goto failC0;
  217. }
  218. B.have = 0;
  219. R.have = 1;
  220. goto doneC;
  221. failC0:
  222. R.have = 0;
  223. parser_out->out_of_memory = 1;
  224. doneC:
  225. free(A);
  226. free_value(B);
  227. free(C);
  228. }
  229. statement(R) ::= dotted_name(M) ARROW dotted_name(A) ROUND_OPEN statement_args_maybe(B) ROUND_CLOSE name_maybe(C) SEMICOLON. {
  230. if (!M || !A || !B.have) {
  231. goto failD0;
  232. }
  233. if (!NCDStatement_InitReg(&R.v, C, M, A, B.v)) {
  234. goto failD0;
  235. }
  236. B.have = 0;
  237. R.have = 1;
  238. goto doneD;
  239. failD0:
  240. R.have = 0;
  241. parser_out->out_of_memory = 1;
  242. doneD:
  243. free(M);
  244. free(A);
  245. free_value(B);
  246. free(C);
  247. }
  248. statement(R) ::= IF ROUND_OPEN value(A) ROUND_CLOSE CURLY_OPEN statements(B) CURLY_CLOSE elif_maybe(I) else_maybe(E) name_maybe(C) SEMICOLON. {
  249. if (!A.have || !B.have || !I.have) {
  250. goto failE0;
  251. }
  252. NCDIf ifc;
  253. NCDIf_Init(&ifc, A.v, B.v);
  254. A.have = 0;
  255. B.have = 0;
  256. if (!NCDIfBlock_PrependIf(&I.v, ifc)) {
  257. NCDIf_Free(&ifc);
  258. goto failE0;
  259. }
  260. if (!NCDStatement_InitIf(&R.v, C, I.v)) {
  261. goto failE0;
  262. }
  263. I.have = 0;
  264. if (E.have) {
  265. NCDStatement_IfAddElse(&R.v, E.v);
  266. E.have = 0;
  267. }
  268. R.have = 1;
  269. goto doneE;
  270. failE0:
  271. R.have = 0;
  272. parser_out->out_of_memory = 1;
  273. doneE:
  274. free_value(A);
  275. free_block(B);
  276. free_ifblock(I);
  277. free_block(E);
  278. free(C);
  279. }
  280. statement(R) ::= FOREACH ROUND_OPEN value(A) AS NAME(B) ROUND_CLOSE CURLY_OPEN statements(S) CURLY_CLOSE name_maybe(N) SEMICOLON. {
  281. if (!A.have || !B.str || !S.have) {
  282. goto failEA0;
  283. }
  284. if (!NCDStatement_InitForeach(&R.v, N, A.v, B.str, NULL, S.v)) {
  285. goto failEA0;
  286. }
  287. A.have = 0;
  288. S.have = 0;
  289. R.have = 1;
  290. goto doneEA0;
  291. failEA0:
  292. R.have = 0;
  293. parser_out->out_of_memory = 1;
  294. doneEA0:
  295. free_value(A);
  296. free_token(B);
  297. free_block(S);
  298. free(N);
  299. }
  300. statement(R) ::= FOREACH ROUND_OPEN value(A) AS NAME(B) COLON NAME(C) ROUND_CLOSE CURLY_OPEN statements(S) CURLY_CLOSE name_maybe(N) SEMICOLON. {
  301. if (!A.have || !B.str || !C.str || !S.have) {
  302. goto failEB0;
  303. }
  304. if (!NCDStatement_InitForeach(&R.v, N, A.v, B.str, C.str, S.v)) {
  305. goto failEB0;
  306. }
  307. A.have = 0;
  308. S.have = 0;
  309. R.have = 1;
  310. goto doneEB0;
  311. failEB0:
  312. R.have = 0;
  313. parser_out->out_of_memory = 1;
  314. doneEB0:
  315. free_value(A);
  316. free_token(B);
  317. free_token(C);
  318. free_block(S);
  319. free(N);
  320. }
  321. elif_maybe(R) ::= . {
  322. NCDIfBlock_Init(&R.v);
  323. R.have = 1;
  324. }
  325. elif_maybe(R) ::= elif(A). {
  326. R = A;
  327. }
  328. elif(R) ::= ELIF ROUND_OPEN value(A) ROUND_CLOSE CURLY_OPEN statements(B) CURLY_CLOSE. {
  329. if (!A.have || !B.have) {
  330. goto failF0;
  331. }
  332. NCDIfBlock_Init(&R.v);
  333. NCDIf ifc;
  334. NCDIf_Init(&ifc, A.v, B.v);
  335. A.have = 0;
  336. B.have = 0;
  337. if (!NCDIfBlock_PrependIf(&R.v, ifc)) {
  338. goto failF1;
  339. }
  340. R.have = 1;
  341. goto doneF0;
  342. failF1:
  343. NCDIf_Free(&ifc);
  344. NCDIfBlock_Free(&R.v);
  345. failF0:
  346. R.have = 0;
  347. parser_out->out_of_memory = 1;
  348. doneF0:
  349. free_value(A);
  350. free_block(B);
  351. }
  352. elif(R) ::= ELIF ROUND_OPEN value(A) ROUND_CLOSE CURLY_OPEN statements(B) CURLY_CLOSE elif(N). {
  353. if (!A.have || !B.have || !N.have) {
  354. goto failG0;
  355. }
  356. NCDIf ifc;
  357. NCDIf_Init(&ifc, A.v, B.v);
  358. A.have = 0;
  359. B.have = 0;
  360. if (!NCDIfBlock_PrependIf(&N.v, ifc)) {
  361. goto failG1;
  362. }
  363. R.have = 1;
  364. R.v = N.v;
  365. N.have = 0;
  366. goto doneG0;
  367. failG1:
  368. NCDIf_Free(&ifc);
  369. failG0:
  370. R.have = 0;
  371. parser_out->out_of_memory = 1;
  372. doneG0:
  373. free_value(A);
  374. free_block(B);
  375. free_ifblock(N);
  376. }
  377. else_maybe(R) ::= . {
  378. R.have = 0;
  379. }
  380. else_maybe(R) ::= ELSE CURLY_OPEN statements(B) CURLY_CLOSE. {
  381. R = B;
  382. }
  383. statement(R) ::= BLOCK CURLY_OPEN statements(S) CURLY_CLOSE name_maybe(N) SEMICOLON. {
  384. if (!S.have) {
  385. goto failGA0;
  386. }
  387. if (!NCDStatement_InitBlock(&R.v, N, S.v)) {
  388. goto failGA0;
  389. }
  390. S.have = 0;
  391. R.have = 1;
  392. goto doneGA0;
  393. failGA0:
  394. R.have = 0;
  395. parser_out->out_of_memory = 1;
  396. doneGA0:
  397. free_block(S);
  398. free(N);
  399. }
  400. statements(R) ::= statement(A). {
  401. if (!A.have) {
  402. goto failH0;
  403. }
  404. NCDBlock_Init(&R.v);
  405. if (!NCDBlock_PrependStatement(&R.v, A.v)) {
  406. goto failH1;
  407. }
  408. A.have = 0;
  409. R.have = 1;
  410. goto doneH;
  411. failH1:
  412. NCDBlock_Free(&R.v);
  413. failH0:
  414. R.have = 0;
  415. parser_out->out_of_memory = 1;
  416. doneH:
  417. free_statement(A);
  418. }
  419. statements(R) ::= statement(A) statements(N). {
  420. if (!A.have || !N.have) {
  421. goto failI0;
  422. }
  423. if (!NCDBlock_PrependStatement(&N.v, A.v)) {
  424. goto failI1;
  425. }
  426. A.have = 0;
  427. R.have = 1;
  428. R.v = N.v;
  429. N.have = 0;
  430. goto doneI;
  431. failI1:
  432. NCDBlock_Free(&R.v);
  433. failI0:
  434. R.have = 0;
  435. parser_out->out_of_memory = 1;
  436. doneI:
  437. free_statement(A);
  438. free_block(N);
  439. }
  440. dotted_name(R) ::= NAME(A). {
  441. ASSERT(A.str)
  442. R = A.str;
  443. }
  444. dotted_name(R) ::= NAME(A) DOT dotted_name(N). {
  445. ASSERT(A.str)
  446. if (!N) {
  447. goto failJ0;
  448. }
  449. if (!(R = concat_strings(3, A.str, ".", N))) {
  450. goto failJ0;
  451. }
  452. goto doneJ;
  453. failJ0:
  454. R = NULL;
  455. parser_out->out_of_memory = 1;
  456. doneJ:
  457. free_token(A);
  458. free(N);
  459. }
  460. name_list(R) ::= NAME(A). {
  461. if (!A.str) {
  462. goto failK0;
  463. }
  464. NCDValue_InitList(&R.v);
  465. NCDValue this_string;
  466. if (!NCDValue_InitString(&this_string, A.str)) {
  467. goto failK1;
  468. }
  469. if (!NCDValue_ListPrepend(&R.v, this_string)) {
  470. goto failK2;
  471. }
  472. R.have = 1;
  473. goto doneK;
  474. failK2:
  475. NCDValue_Free(&this_string);
  476. failK1:
  477. NCDValue_Free(&R.v);
  478. failK0:
  479. R.have = 0;
  480. parser_out->out_of_memory = 1;
  481. doneK:
  482. free_token(A);
  483. }
  484. name_list(R) ::= NAME(A) DOT name_list(N). {
  485. if (!A.str || !N.have) {
  486. goto failKA0;
  487. }
  488. NCDValue this_string;
  489. if (!NCDValue_InitString(&this_string, A.str)) {
  490. goto failKA0;
  491. }
  492. if (!NCDValue_ListPrepend(&N.v, this_string)) {
  493. goto failKA1;
  494. }
  495. R.have = 1;
  496. R.v = N.v;
  497. N.have = 0;
  498. goto doneKA;
  499. failKA1:
  500. NCDValue_Free(&this_string);
  501. failKA0:
  502. R.have = 0;
  503. parser_out->out_of_memory = 1;
  504. doneKA:
  505. free_token(A);
  506. free_value(N);
  507. }
  508. statement_args_maybe(R) ::= . {
  509. R.have = 1;
  510. NCDValue_InitList(&R.v);
  511. }
  512. statement_args_maybe(R) ::= list_contents(A). {
  513. R = A;
  514. }
  515. list_contents(R) ::= value(A). {
  516. if (!A.have) {
  517. goto failL0;
  518. }
  519. NCDValue_InitList(&R.v);
  520. if (!NCDValue_ListPrepend(&R.v, A.v)) {
  521. goto failL1;
  522. }
  523. A.have = 0;
  524. R.have = 1;
  525. goto doneL;
  526. failL1:
  527. NCDValue_Free(&R.v);
  528. failL0:
  529. R.have = 0;
  530. parser_out->out_of_memory = 1;
  531. doneL:
  532. free_value(A);
  533. }
  534. list_contents(R) ::= value(A) COMMA list_contents(N). {
  535. if (!A.have || !N.have) {
  536. goto failM0;
  537. }
  538. if (!NCDValue_ListPrepend(&N.v, A.v)) {
  539. goto failM0;
  540. }
  541. A.have = 0;
  542. R.have = 1;
  543. R.v = N.v;
  544. N.have = 0;
  545. goto doneM;
  546. failM0:
  547. R.have = 0;
  548. parser_out->out_of_memory = 1;
  549. doneM:
  550. free_value(A);
  551. free_value(N);
  552. }
  553. list(R) ::= CURLY_OPEN CURLY_CLOSE. {
  554. R.have = 1;
  555. NCDValue_InitList(&R.v);
  556. }
  557. list(R) ::= CURLY_OPEN list_contents(A) CURLY_CLOSE. {
  558. R = A;
  559. }
  560. map_contents(R) ::= value(A) COLON value(B). {
  561. if (!A.have || !B.have) {
  562. goto failS0;
  563. }
  564. NCDValue_InitMap(&R.v);
  565. if (!NCDValue_MapPrepend(&R.v, A.v, B.v)) {
  566. goto failS1;
  567. }
  568. A.have = 0;
  569. B.have = 0;
  570. R.have = 1;
  571. goto doneS;
  572. failS1:
  573. NCDValue_Free(&R.v);
  574. failS0:
  575. R.have = 0;
  576. parser_out->out_of_memory = 1;
  577. doneS:
  578. free_value(A);
  579. free_value(B);
  580. }
  581. map_contents(R) ::= value(A) COLON value(B) COMMA map_contents(N). {
  582. if (!A.have || !B.have || !N.have) {
  583. goto failT0;
  584. }
  585. if (!NCDValue_MapPrepend(&N.v, A.v, B.v)) {
  586. goto failT0;
  587. }
  588. A.have = 0;
  589. B.have = 0;
  590. R.have = 1;
  591. R.v = N.v;
  592. N.have = 0;
  593. goto doneT;
  594. failT0:
  595. R.have = 0;
  596. parser_out->out_of_memory = 1;
  597. doneT:
  598. free_value(A);
  599. free_value(B);
  600. free_value(N);
  601. }
  602. map(R) ::= BRACKET_OPEN BRACKET_CLOSE. {
  603. R.have = 1;
  604. NCDValue_InitMap(&R.v);
  605. }
  606. map(R) ::= BRACKET_OPEN map_contents(A) BRACKET_CLOSE. {
  607. R = A;
  608. }
  609. invoc(R) ::= value(F) ROUND_OPEN list_contents(A) ROUND_CLOSE. {
  610. if (!F.have || !A.have) {
  611. goto failQ0;
  612. }
  613. if (!NCDValue_InitInvoc(&R.v, F.v, A.v)) {
  614. goto failQ0;
  615. }
  616. F.have = 0;
  617. A.have = 0;
  618. R.have = 1;
  619. goto doneQ;
  620. failQ0:
  621. R.have = 0;
  622. parser_out->out_of_memory = 1;
  623. doneQ:
  624. free_value(F);
  625. free_value(A);
  626. }
  627. value(R) ::= STRING(A). {
  628. ASSERT(A.str)
  629. if (!NCDValue_InitStringBin(&R.v, (uint8_t *)A.str, A.len)) {
  630. goto failU0;
  631. }
  632. R.have = 1;
  633. goto doneU;
  634. failU0:
  635. R.have = 0;
  636. parser_out->out_of_memory = 1;
  637. doneU:
  638. free_token(A);
  639. }
  640. value(R) ::= AT_SIGN dotted_name(A). {
  641. if (!A) {
  642. goto failUA0;
  643. }
  644. if (!NCDValue_InitString(&R.v, A)) {
  645. goto failUA0;
  646. }
  647. R.have = 1;
  648. goto doneUA0;
  649. failUA0:
  650. R.have = 0;
  651. parser_out->out_of_memory = 1;
  652. doneUA0:
  653. free(A);
  654. }
  655. value(R) ::= CARET name_list(A). {
  656. R = A;
  657. }
  658. value(R) ::= dotted_name(A). {
  659. if (!A) {
  660. goto failV0;
  661. }
  662. if (!NCDValue_InitVar(&R.v, A)) {
  663. goto failV0;
  664. }
  665. R.have = 1;
  666. goto doneV;
  667. failV0:
  668. R.have = 0;
  669. parser_out->out_of_memory = 1;
  670. doneV:
  671. free(A);
  672. }
  673. value(R) ::= list(A). {
  674. R = A;
  675. }
  676. value(R) ::= map(A). {
  677. R = A;
  678. }
  679. value(R) ::= ROUND_OPEN value(A) ROUND_CLOSE. {
  680. R = A;
  681. }
  682. value(R) ::= invoc(A). {
  683. R = A;
  684. }
  685. name_maybe(R) ::= . {
  686. R = NULL;
  687. }
  688. name_maybe(R) ::= NAME(A). {
  689. ASSERT(A.str)
  690. R = A.str;
  691. }
  692. process_or_template(R) ::= PROCESS. {
  693. R = 0;
  694. }
  695. process_or_template(R) ::= TEMPLATE. {
  696. R = 1;
  697. }