1
0

test-grammar-parser.cpp 16 KB

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