| 51 | } |
| 52 | |
| 53 | static void |
| 54 | token_error(token_t *token) { |
| 55 | if (!token->parser->verbose) { |
| 56 | return; |
| 57 | } |
| 58 | switch (token->token_type) { |
| 59 | case TOKEN_TYPE_NONE: |
| 60 | not_reached(); |
| 61 | case TOKEN_TYPE_ERROR: |
| 62 | malloc_printf("%zu:%zu: Unexpected character in token: ", |
| 63 | token->line, token->col); |
| 64 | break; |
| 65 | default: |
| 66 | malloc_printf("%zu:%zu: Unexpected token: ", token->line, |
| 67 | token->col); |
| 68 | break; |
| 69 | } |
| 70 | UNUSED ssize_t err = malloc_write_fd(STDERR_FILENO, |
| 71 | &token->parser->buf[token->pos], token->len); |
| 72 | malloc_printf("\n"); |
| 73 | } |
| 74 | |
| 75 | static void |
| 76 | parser_init(parser_t *parser, bool verbose) { |
no test coverage detected