You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

lex.h 1.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. #ifndef L2_PARSE_LEX_H
  2. #define L2_PARSE_LEX_H
  3. #include "../io.h"
  4. enum l2_token_kind {
  5. L2_TOK_OPEN_PAREN,
  6. L2_TOK_CLOSE_PAREN,
  7. L2_TOK_OPEN_BRACE,
  8. L2_TOK_CLOSE_BRACE,
  9. L2_TOK_OPEN_BRACKET,
  10. L2_TOK_CLOSE_BRACKET,
  11. L2_TOK_QUOT,
  12. L2_TOK_COMMA,
  13. L2_TOK_PERIOD,
  14. L2_TOK_COLON,
  15. L2_TOK_COLON_EQ,
  16. L2_TOK_EOL,
  17. L2_TOK_EOF,
  18. L2_TOK_NUMBER,
  19. L2_TOK_STRING,
  20. L2_TOK_IDENT,
  21. L2_TOK_ERROR,
  22. };
  23. const char *l2_token_kind_name(enum l2_token_kind kind);
  24. struct l2_token {
  25. enum l2_token_kind kind;
  26. int line;
  27. int ch;
  28. union {
  29. char *str;
  30. double num;
  31. } v;
  32. };
  33. void l2_token_free(struct l2_token *tok);
  34. char *l2_token_extract_str(struct l2_token *tok);
  35. void l2_token_print(struct l2_token *tok, struct l2_io_writer *w);
  36. struct l2_lexer {
  37. struct l2_token toks[4];
  38. int tokidx;
  39. int line;
  40. int ch;
  41. int parens;
  42. int do_log_tokens;
  43. struct l2_bufio_reader reader;
  44. };
  45. void l2_lexer_init(struct l2_lexer *lexer, struct l2_io_reader *r);
  46. struct l2_token *l2_lexer_peek(struct l2_lexer *lexer, int count);
  47. void l2_lexer_consume(struct l2_lexer *lexer);
  48. void l2_lexer_skip_opt(struct l2_lexer *lexer, enum l2_token_kind kind);
  49. #endif