test.c 998 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #include <string.h>
  4. #include "lexer.h"
  5. static void got_token(lexer_token_t* t) {
  6. if(t->is_whitespace) {
  7. /*printf("s: x%ld [", t->text_len);
  8. for(int i = 0; i < t->text_len; i++) {
  9. printf("%d ", t->text[i]);
  10. }
  11. printf("]\n");
  12. */
  13. }
  14. else {
  15. printf("[%.*s]", (int)t->text_len, t->text);
  16. // printf("[%ld,%ld] t:%.*s, ", t->start_line, t->start_col, (int)t->text_len, t->text);
  17. }
  18. if(t->eol) printf("\n");
  19. }
  20. int main(int argc, char* argv[]) {
  21. lexer_opts_t opts;
  22. opts.symbols = (char*[]){
  23. "(", ")", "[", "]", "{", "}",
  24. ".", "...", ",", ";",
  25. "=", "==", "->",
  26. "-", "+", "/", "%", "*",
  27. "-=", "+=", "/=", "%=", "*=",
  28. ">=", ">", "<=", "<",
  29. "<<", "<<=", ">>", ">>=",
  30. "&&", "||",
  31. "~", "!", "!=", "^", "|", "&",
  32. "~=", "!=", "^=", "|=", "&=",
  33. "++", "--",
  34. "?", ":",
  35. "#", "##",
  36. "<%", "%>", "<:", ":>", "%:", "%:%:",
  37. NULL
  38. };
  39. opts.got_token = got_token;
  40. lex_file("./lexer.c", &opts);
  41. return 0;
  42. }