test-grammar-parser.cpp 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515
  1. #ifdef NDEBUG
  2. #undef NDEBUG
  3. #endif
  4. #include "llama.h"
  5. #include "grammar-parser.h"
  6. #include <cassert>
  7. static const char * type_str(llama_gretype type) {
  8. switch (type) {
  9. case LLAMA_GRETYPE_CHAR: return "LLAMA_GRETYPE_CHAR";
  10. case LLAMA_GRETYPE_CHAR_NOT: return "LLAMA_GRETYPE_CHAR_NOT";
  11. case LLAMA_GRETYPE_CHAR_ALT: return "LLAMA_GRETYPE_CHAR_ALT";
  12. case LLAMA_GRETYPE_CHAR_RNG_UPPER: return "LLAMA_GRETYPE_CHAR_RNG_UPPER";
  13. case LLAMA_GRETYPE_RULE_REF: return "LLAMA_GRETYPE_RULE_REF";
  14. case LLAMA_GRETYPE_ALT: return "LLAMA_GRETYPE_ALT";
  15. case LLAMA_GRETYPE_END: return "LLAMA_GRETYPE_END";
  16. default: return "?";
  17. }
  18. }
  19. static void verify_parsing(const char *grammar_bytes, const std::vector<std::pair<std::string, uint32_t>> expected, const std::vector<llama_grammar_element> &expected_rules) {
  20. uint32_t index = 0;
  21. grammar_parser::parse_state parsed_grammar = grammar_parser::parse(grammar_bytes);
  22. std::map<uint32_t, std::string> symbol_names;
  23. for (auto it = parsed_grammar.symbol_ids.begin(); it != parsed_grammar.symbol_ids.end(); ++it) {
  24. symbol_names[it->second] = it->first;
  25. }
  26. auto print_all = [&]() {
  27. fprintf(stderr, " verify_parsing(R\"\"\"(%s)\"\"\", {\n", grammar_bytes);
  28. for (auto it = parsed_grammar.symbol_ids.begin(); it != parsed_grammar.symbol_ids.end(); ++it) {
  29. fprintf(stderr, " {\"%s\", %u},\n", it->first.c_str(), it->second);
  30. }
  31. fprintf(stderr, " }, {\n");
  32. for (size_t i_rule = 0; i_rule < parsed_grammar.rules.size(); i_rule++) {
  33. fprintf(stderr, " // %s (index %zu)\n", symbol_names[i_rule].c_str(), i_rule);
  34. auto & rule = parsed_grammar.rules[i_rule];
  35. for (uint32_t i = 0; i < rule.size(); i++) {
  36. std::string rule_str;
  37. fprintf(stderr, " {%s, ", type_str(rule[i].type));
  38. if (rule[i].type == LLAMA_GRETYPE_CHAR || rule[i].type == LLAMA_GRETYPE_CHAR_ALT ||
  39. rule[i].type == LLAMA_GRETYPE_CHAR_NOT || rule[i].type == LLAMA_GRETYPE_CHAR_RNG_UPPER) {
  40. char c = rule[i].value;
  41. if (c == '\n') {
  42. fprintf(stderr, "'\\n'");
  43. } else if (c == '\t') {
  44. fprintf(stderr, "'\\t'");
  45. } else if (c == '\r') {
  46. fprintf(stderr, "'\\r'");
  47. } else if (c == '\0') {
  48. fprintf(stderr, "'\\0'");
  49. } else {
  50. fprintf(stderr, "'%c'", c);
  51. }
  52. } else if (rule[i].type == LLAMA_GRETYPE_RULE_REF) {
  53. fprintf(stderr, "/* %s */ %u", symbol_names[rule[i].value].c_str(), rule[i].value);
  54. } else {
  55. fprintf(stderr, "%u", rule[i].value);
  56. }
  57. fprintf(stderr, "},\n");
  58. }
  59. }
  60. fprintf(stderr, " });\n");
  61. };
  62. if (getenv("TEST_GRAMMAR_PARSER_PRINT_ALL")) {
  63. print_all();
  64. fprintf(stderr, "\n");
  65. return;
  66. }
  67. fprintf(stderr, "Testing grammar:%s\n", grammar_bytes);
  68. if (parsed_grammar.symbol_ids.size() != expected.size()) {
  69. fprintf(stderr, "Code to update expectation (set TEST_GRAMMAR_PARSER_PRINT_ALL=1 to print all):\n");
  70. print_all();
  71. assert(parsed_grammar.symbol_ids.size() == expected.size());
  72. }
  73. for (auto it = parsed_grammar.symbol_ids.begin(); it != parsed_grammar.symbol_ids.end(); ++it)
  74. {
  75. std::string key = it->first;
  76. uint32_t value = it->second;
  77. std::pair<std::string, uint32_t> expected_pair = expected[index];
  78. // pretty print error message before asserting
  79. if (expected_pair.first != key || expected_pair.second != value)
  80. {
  81. fprintf(stderr, "index: %u\n", index);
  82. fprintf(stderr, "expected_pair: %s, %u\n", expected_pair.first.c_str(), expected_pair.second);
  83. fprintf(stderr, "actual_pair: %s, %u\n", key.c_str(), value);
  84. fprintf(stderr, "expected_pair != actual_pair\n");
  85. fprintf(stderr, "Code to update expectation (set TEST_GRAMMAR_PARSER_PRINT_ALL=1 to print all):\n");
  86. print_all();
  87. }
  88. assert(expected_pair.first == key && expected_pair.second == value);
  89. index++;
  90. }
  91. index = 0;
  92. for (auto rule : parsed_grammar.rules)
  93. {
  94. // compare rule to expected rule
  95. for (uint32_t i = 0; i < rule.size(); i++)
  96. {
  97. llama_grammar_element element = rule[i];
  98. llama_grammar_element expected_element = expected_rules[index];
  99. // pretty print error message before asserting
  100. if (expected_element.type != element.type || expected_element.value != element.value)
  101. {
  102. fprintf(stderr, "index: %u\n", index);
  103. fprintf(stderr, "expected_element: %s, %u\n", type_str(expected_element.type), expected_element.value);
  104. fprintf(stderr, "actual_element: %s, %u\n", type_str(element.type), element.value);
  105. fprintf(stderr, "expected_element != actual_element\n");
  106. fprintf(stderr, "all elements:\n");
  107. fprintf(stderr, "Code to update expectation (set TEST_GRAMMAR_PARSER_PRINT_ALL=1 to print all):\n");
  108. print_all();
  109. }
  110. assert(expected_element.type == element.type && expected_element.value == element.value);
  111. index++;
  112. }
  113. }
  114. }
  115. static void verify_failure(const char *grammar_bytes) {
  116. fprintf(stderr, "Testing expected failure:%s\n", grammar_bytes);
  117. auto result = grammar_parser::parse(grammar_bytes);
  118. assert(result.rules.empty() && "should have failed");
  119. }
  120. int main()
  121. {
  122. verify_failure(R"""(
  123. root ::= "a"{,}"
  124. )""");
  125. verify_failure(R"""(
  126. root ::= "a"{,10}"
  127. )""");
  128. verify_parsing(R"""(
  129. root ::= "a"
  130. )""", {
  131. {"root", 0},
  132. }, {
  133. // root (index 0)
  134. {LLAMA_GRETYPE_CHAR, 'a'},
  135. {LLAMA_GRETYPE_END, 0},
  136. });
  137. verify_parsing(R"""(
  138. root ::= "a" | [bdx-z] | [^1-3]
  139. )""", {
  140. {"root", 0},
  141. }, {
  142. // root (index 0)
  143. {LLAMA_GRETYPE_CHAR, 'a'},
  144. {LLAMA_GRETYPE_ALT, 0},
  145. {LLAMA_GRETYPE_CHAR, 'b'},
  146. {LLAMA_GRETYPE_CHAR_ALT, 'd'},
  147. {LLAMA_GRETYPE_CHAR_ALT, 'x'},
  148. {LLAMA_GRETYPE_CHAR_RNG_UPPER, 'z'},
  149. {LLAMA_GRETYPE_ALT, 0},
  150. {LLAMA_GRETYPE_CHAR_NOT, '1'},
  151. {LLAMA_GRETYPE_CHAR_RNG_UPPER, '3'},
  152. {LLAMA_GRETYPE_END, 0},
  153. });
  154. verify_parsing(R"""(
  155. root ::= a+
  156. a ::= "a"
  157. )""", {
  158. {"a", 1},
  159. {"root", 0},
  160. {"root_2", 2},
  161. }, {
  162. // root (index 0)
  163. {LLAMA_GRETYPE_RULE_REF, /* a */ 1},
  164. {LLAMA_GRETYPE_RULE_REF, /* root_2 */ 2},
  165. {LLAMA_GRETYPE_END, 0},
  166. // a (index 1)
  167. {LLAMA_GRETYPE_CHAR, 'a'},
  168. {LLAMA_GRETYPE_END, 0},
  169. // root_2 (index 2)
  170. {LLAMA_GRETYPE_RULE_REF, /* a */ 1},
  171. {LLAMA_GRETYPE_RULE_REF, /* root_2 */ 2},
  172. {LLAMA_GRETYPE_ALT, 0},
  173. {LLAMA_GRETYPE_END, 0},
  174. });
  175. verify_parsing(R"""(
  176. root ::= "a"+
  177. )""", {
  178. {"root", 0},
  179. {"root_1", 1},
  180. }, {
  181. // root (index 0)
  182. {LLAMA_GRETYPE_CHAR, 'a'},
  183. {LLAMA_GRETYPE_RULE_REF, /* root_1 */ 1},
  184. {LLAMA_GRETYPE_END, 0},
  185. // root_1 (index 1)
  186. {LLAMA_GRETYPE_CHAR, 'a'},
  187. {LLAMA_GRETYPE_RULE_REF, /* root_1 */ 1},
  188. {LLAMA_GRETYPE_ALT, 0},
  189. {LLAMA_GRETYPE_END, 0},
  190. });
  191. verify_parsing(R"""(
  192. root ::= a?
  193. a ::= "a"
  194. )""", {
  195. {"a", 1},
  196. {"root", 0},
  197. {"root_2", 2},
  198. }, {
  199. // root (index 0)
  200. {LLAMA_GRETYPE_RULE_REF, /* root_2 */ 2},
  201. {LLAMA_GRETYPE_END, 0},
  202. // a (index 1)
  203. {LLAMA_GRETYPE_CHAR, 'a'},
  204. {LLAMA_GRETYPE_END, 0},
  205. // root_2 (index 2)
  206. {LLAMA_GRETYPE_RULE_REF, /* a */ 1},
  207. {LLAMA_GRETYPE_ALT, 0},
  208. {LLAMA_GRETYPE_END, 0},
  209. });
  210. verify_parsing(R"""(
  211. root ::= "a"?
  212. )""", {
  213. {"root", 0},
  214. {"root_1", 1},
  215. }, {
  216. // root (index 0)
  217. {LLAMA_GRETYPE_RULE_REF, /* root_1 */ 1},
  218. {LLAMA_GRETYPE_END, 0},
  219. // root_1 (index 1)
  220. {LLAMA_GRETYPE_CHAR, 'a'},
  221. {LLAMA_GRETYPE_ALT, 0},
  222. {LLAMA_GRETYPE_END, 0},
  223. });
  224. verify_parsing(R"""(
  225. root ::= a*
  226. a ::= "a"
  227. )""", {
  228. {"a", 1},
  229. {"root", 0},
  230. {"root_2", 2},
  231. }, {
  232. // root (index 0)
  233. {LLAMA_GRETYPE_RULE_REF, /* root_2 */ 2},
  234. {LLAMA_GRETYPE_END, 0},
  235. // a (index 1)
  236. {LLAMA_GRETYPE_CHAR, 'a'},
  237. {LLAMA_GRETYPE_END, 0},
  238. // root_2 (index 2)
  239. {LLAMA_GRETYPE_RULE_REF, /* a */ 1},
  240. {LLAMA_GRETYPE_RULE_REF, /* root_2 */ 2},
  241. {LLAMA_GRETYPE_ALT, 0},
  242. {LLAMA_GRETYPE_END, 0},
  243. });
  244. verify_parsing(R"""(
  245. root ::= "a"*
  246. )""", {
  247. {"root", 0},
  248. {"root_1", 1},
  249. }, {
  250. // root (index 0)
  251. {LLAMA_GRETYPE_RULE_REF, /* root_1 */ 1},
  252. {LLAMA_GRETYPE_END, 0},
  253. // root_1 (index 1)
  254. {LLAMA_GRETYPE_CHAR, 'a'},
  255. {LLAMA_GRETYPE_RULE_REF, /* root_1 */ 1},
  256. {LLAMA_GRETYPE_ALT, 0},
  257. {LLAMA_GRETYPE_END, 0},
  258. });
  259. verify_parsing(R"""(
  260. root ::= "a"{2}
  261. )""", {
  262. {"root", 0},
  263. }, {
  264. // root (index 0)
  265. {LLAMA_GRETYPE_CHAR, 'a'},
  266. {LLAMA_GRETYPE_CHAR, 'a'},
  267. {LLAMA_GRETYPE_END, 0},
  268. });
  269. verify_parsing(R"""(
  270. root ::= "a"{2,}
  271. )""", {
  272. {"root", 0},
  273. {"root_1", 1},
  274. }, {
  275. // root (index 0)
  276. {LLAMA_GRETYPE_CHAR, 'a'},
  277. {LLAMA_GRETYPE_CHAR, 'a'},
  278. {LLAMA_GRETYPE_RULE_REF, /* root_1 */ 1},
  279. {LLAMA_GRETYPE_END, 0},
  280. // root_1 (index 1)
  281. {LLAMA_GRETYPE_CHAR, 'a'},
  282. {LLAMA_GRETYPE_RULE_REF, /* root_1 */ 1},
  283. {LLAMA_GRETYPE_ALT, 0},
  284. {LLAMA_GRETYPE_END, 0},
  285. });
  286. verify_parsing(R"""(
  287. root ::= "a"{ 4}
  288. )""", {
  289. {"root", 0},
  290. }, {
  291. // root (index 0)
  292. {LLAMA_GRETYPE_CHAR, 'a'},
  293. {LLAMA_GRETYPE_CHAR, 'a'},
  294. {LLAMA_GRETYPE_CHAR, 'a'},
  295. {LLAMA_GRETYPE_CHAR, 'a'},
  296. {LLAMA_GRETYPE_END, 0},
  297. });
  298. verify_parsing(R"""(
  299. root ::= "a"{2,4}
  300. )""", {
  301. {"root", 0},
  302. {"root_1", 1},
  303. {"root_2", 2},
  304. }, {
  305. // root (index 0)
  306. {LLAMA_GRETYPE_CHAR, 'a'},
  307. {LLAMA_GRETYPE_CHAR, 'a'},
  308. {LLAMA_GRETYPE_RULE_REF, /* root_2 */ 2},
  309. {LLAMA_GRETYPE_END, 0},
  310. // root_1 (index 1)
  311. {LLAMA_GRETYPE_CHAR, 'a'},
  312. {LLAMA_GRETYPE_ALT, 0},
  313. {LLAMA_GRETYPE_END, 0},
  314. // root_2 (index 2)
  315. {LLAMA_GRETYPE_CHAR, 'a'},
  316. {LLAMA_GRETYPE_RULE_REF, /* root_1 */ 1},
  317. {LLAMA_GRETYPE_ALT, 0},
  318. {LLAMA_GRETYPE_END, 0},
  319. });
  320. verify_parsing(R"""(
  321. root ::= (expr "=" term "\n")+
  322. expr ::= term ([-+*/] term)*
  323. term ::= [0-9]+
  324. )""", {
  325. {"expr", 2},
  326. {"expr_5", 5},
  327. {"expr_6", 6},
  328. {"root", 0},
  329. {"root_1", 1},
  330. {"root_4", 4},
  331. {"term", 3},
  332. {"term_7", 7},
  333. }, {
  334. // root (index 0)
  335. {LLAMA_GRETYPE_RULE_REF, /* root_1 */ 1},
  336. {LLAMA_GRETYPE_RULE_REF, /* root_4 */ 4},
  337. {LLAMA_GRETYPE_END, 0},
  338. // root_1 (index 1)
  339. {LLAMA_GRETYPE_RULE_REF, /* expr */ 2},
  340. {LLAMA_GRETYPE_CHAR, '='},
  341. {LLAMA_GRETYPE_RULE_REF, /* term */ 3},
  342. {LLAMA_GRETYPE_CHAR, '\n'},
  343. {LLAMA_GRETYPE_END, 0},
  344. // expr (index 2)
  345. {LLAMA_GRETYPE_RULE_REF, /* term */ 3},
  346. {LLAMA_GRETYPE_RULE_REF, /* expr_6 */ 6},
  347. {LLAMA_GRETYPE_END, 0},
  348. // term (index 3)
  349. {LLAMA_GRETYPE_CHAR, '0'},
  350. {LLAMA_GRETYPE_CHAR_RNG_UPPER, '9'},
  351. {LLAMA_GRETYPE_RULE_REF, /* term_7 */ 7},
  352. {LLAMA_GRETYPE_END, 0},
  353. // root_4 (index 4)
  354. {LLAMA_GRETYPE_RULE_REF, /* root_1 */ 1},
  355. {LLAMA_GRETYPE_RULE_REF, /* root_4 */ 4},
  356. {LLAMA_GRETYPE_ALT, 0},
  357. {LLAMA_GRETYPE_END, 0},
  358. // expr_5 (index 5)
  359. {LLAMA_GRETYPE_CHAR, '-'},
  360. {LLAMA_GRETYPE_CHAR_ALT, '+'},
  361. {LLAMA_GRETYPE_CHAR_ALT, '*'},
  362. {LLAMA_GRETYPE_CHAR_ALT, '/'},
  363. {LLAMA_GRETYPE_RULE_REF, /* term */ 3},
  364. {LLAMA_GRETYPE_END, 0},
  365. // expr_6 (index 6)
  366. {LLAMA_GRETYPE_RULE_REF, /* expr_5 */ 5},
  367. {LLAMA_GRETYPE_RULE_REF, /* expr_6 */ 6},
  368. {LLAMA_GRETYPE_ALT, 0},
  369. {LLAMA_GRETYPE_END, 0},
  370. // term_7 (index 7)
  371. {LLAMA_GRETYPE_CHAR, '0'},
  372. {LLAMA_GRETYPE_CHAR_RNG_UPPER, '9'},
  373. {LLAMA_GRETYPE_RULE_REF, /* term_7 */ 7},
  374. {LLAMA_GRETYPE_ALT, 0},
  375. {LLAMA_GRETYPE_END, 0},
  376. });
  377. verify_parsing(R"""(
  378. root ::= (expr "=" ws term "\n")+
  379. expr ::= term ([-+*/] term)*
  380. term ::= ident | num | "(" ws expr ")" ws
  381. ident ::= [a-z] [a-z0-9_]* ws
  382. num ::= [0-9]+ ws
  383. ws ::= [ \t\n]*
  384. )""", {
  385. {"expr", 2},
  386. {"expr_6", 6},
  387. {"expr_7", 7},
  388. {"ident", 8},
  389. {"ident_10", 10},
  390. {"num", 9},
  391. {"num_11", 11},
  392. {"root", 0},
  393. {"root_1", 1},
  394. {"root_5", 5},
  395. {"term", 4},
  396. {"ws", 3},
  397. {"ws_12", 12},
  398. }, {
  399. // root (index 0)
  400. {LLAMA_GRETYPE_RULE_REF, /* root_1 */ 1},
  401. {LLAMA_GRETYPE_RULE_REF, /* root_5 */ 5},
  402. {LLAMA_GRETYPE_END, 0},
  403. // root_1 (index 1)
  404. {LLAMA_GRETYPE_RULE_REF, /* expr */ 2},
  405. {LLAMA_GRETYPE_CHAR, '='},
  406. {LLAMA_GRETYPE_RULE_REF, /* ws */ 3},
  407. {LLAMA_GRETYPE_RULE_REF, /* term */ 4},
  408. {LLAMA_GRETYPE_CHAR, '\n'},
  409. {LLAMA_GRETYPE_END, 0},
  410. // expr (index 2)
  411. {LLAMA_GRETYPE_RULE_REF, /* term */ 4},
  412. {LLAMA_GRETYPE_RULE_REF, /* expr_7 */ 7},
  413. {LLAMA_GRETYPE_END, 0},
  414. // ws (index 3)
  415. {LLAMA_GRETYPE_RULE_REF, /* ws_12 */ 12},
  416. {LLAMA_GRETYPE_END, 0},
  417. // term (index 4)
  418. {LLAMA_GRETYPE_RULE_REF, /* ident */ 8},
  419. {LLAMA_GRETYPE_ALT, 0},
  420. {LLAMA_GRETYPE_RULE_REF, /* num */ 9},
  421. {LLAMA_GRETYPE_ALT, 0},
  422. {LLAMA_GRETYPE_CHAR, '('},
  423. {LLAMA_GRETYPE_RULE_REF, /* ws */ 3},
  424. {LLAMA_GRETYPE_RULE_REF, /* expr */ 2},
  425. {LLAMA_GRETYPE_CHAR, ')'},
  426. {LLAMA_GRETYPE_RULE_REF, /* ws */ 3},
  427. {LLAMA_GRETYPE_END, 0},
  428. // root_5 (index 5)
  429. {LLAMA_GRETYPE_RULE_REF, /* root_1 */ 1},
  430. {LLAMA_GRETYPE_RULE_REF, /* root_5 */ 5},
  431. {LLAMA_GRETYPE_ALT, 0},
  432. {LLAMA_GRETYPE_END, 0},
  433. // expr_6 (index 6)
  434. {LLAMA_GRETYPE_CHAR, '-'},
  435. {LLAMA_GRETYPE_CHAR_ALT, '+'},
  436. {LLAMA_GRETYPE_CHAR_ALT, '*'},
  437. {LLAMA_GRETYPE_CHAR_ALT, '/'},
  438. {LLAMA_GRETYPE_RULE_REF, /* term */ 4},
  439. {LLAMA_GRETYPE_END, 0},
  440. // expr_7 (index 7)
  441. {LLAMA_GRETYPE_RULE_REF, /* expr_6 */ 6},
  442. {LLAMA_GRETYPE_RULE_REF, /* expr_7 */ 7},
  443. {LLAMA_GRETYPE_ALT, 0},
  444. {LLAMA_GRETYPE_END, 0},
  445. // ident (index 8)
  446. {LLAMA_GRETYPE_CHAR, 'a'},
  447. {LLAMA_GRETYPE_CHAR_RNG_UPPER, 'z'},
  448. {LLAMA_GRETYPE_RULE_REF, /* ident_10 */ 10},
  449. {LLAMA_GRETYPE_RULE_REF, /* ws */ 3},
  450. {LLAMA_GRETYPE_END, 0},
  451. // num (index 9)
  452. {LLAMA_GRETYPE_CHAR, '0'},
  453. {LLAMA_GRETYPE_CHAR_RNG_UPPER, '9'},
  454. {LLAMA_GRETYPE_RULE_REF, /* num_11 */ 11},
  455. {LLAMA_GRETYPE_RULE_REF, /* ws */ 3},
  456. {LLAMA_GRETYPE_END, 0},
  457. // ident_10 (index 10)
  458. {LLAMA_GRETYPE_CHAR, 'a'},
  459. {LLAMA_GRETYPE_CHAR_RNG_UPPER, 'z'},
  460. {LLAMA_GRETYPE_CHAR_ALT, '0'},
  461. {LLAMA_GRETYPE_CHAR_RNG_UPPER, '9'},
  462. {LLAMA_GRETYPE_CHAR_ALT, '_'},
  463. {LLAMA_GRETYPE_RULE_REF, /* ident_10 */ 10},
  464. {LLAMA_GRETYPE_ALT, 0},
  465. {LLAMA_GRETYPE_END, 0},
  466. // num_11 (index 11)
  467. {LLAMA_GRETYPE_CHAR, '0'},
  468. {LLAMA_GRETYPE_CHAR_RNG_UPPER, '9'},
  469. {LLAMA_GRETYPE_RULE_REF, /* num_11 */ 11},
  470. {LLAMA_GRETYPE_ALT, 0},
  471. {LLAMA_GRETYPE_END, 0},
  472. // ws_12 (index 12)
  473. {LLAMA_GRETYPE_CHAR, ' '},
  474. {LLAMA_GRETYPE_CHAR_ALT, '\t'},
  475. {LLAMA_GRETYPE_CHAR_ALT, '\n'},
  476. {LLAMA_GRETYPE_RULE_REF, /* ws_12 */ 12},
  477. {LLAMA_GRETYPE_ALT, 0},
  478. {LLAMA_GRETYPE_END, 0},
  479. });
  480. return 0;
  481. }