seq.peg 1001 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. # seq language lexer+parser
  2. # see t.seq test
  3. %prefix "seq"
  4. %source{
  5. #include <stdio.h>
  6. int nlines= 1;
  7. #if 1
  8. static const char *dbg_str[] = { "Evaluating rule", "Matched rule", "Abandoning rule" };
  9. #define PCC_DEBUG(event, rule, level, pos, buffer, length) \
  10. fprintf(stdout, "%*s%s %s @%d [%.*s]\n", level * 2, "", dbg_str[event], rule, pos, length, buffer)
  11. /* NOTE: To guarantee the output order, stderr, which can lead a race condition with stdout, is not used. */
  12. fflush(stdout);
  13. #endif
  14. }
  15. list <- '[' _ some_digits* _ ']' _
  16. some_digits <- id list2 / pair
  17. list2 <- '[' _ some_digits* _ ']' _
  18. pair <- (id digit)
  19. digit <- ([0-9]+ _)
  20. id <- < [a-zA-Z_]+[a-zA-Z_0-9]* > _ { printf("ID=%s\n",$0); }
  21. _ <- (space / comment)*
  22. space <- (' ' / '\t' / endofline)
  23. comment <- '#' (!endofline .)*
  24. endofline <- ( '\r\n' / '\n' / '\r' / '\n\r' ) { nlines++; }
  25. %%
  26. int main() {
  27. seq_context_t *ctx = seq_create(NULL);
  28. while (seq_parse(ctx, NULL)){;}
  29. seq_destroy(ctx);
  30. return 0;
  31. }