ctpv/lexer.h

41 lines
794 B
C
Raw Normal View History

2022-06-06 21:18:18 +02:00
#ifndef LEXER_H
#define LEXER_H
#include <stdio.h>
#include <stdlib.h>
2022-06-08 05:33:52 +02:00
#define PARSEERROR(c, format, ...) \
print_errorf("config:%u:%u " format, (c).line, \
(c).col __VA_OPT__(, ) __VA_ARGS__)
2022-06-06 21:18:18 +02:00
typedef struct Lexer Lexer;
typedef struct {
2022-06-08 05:33:52 +02:00
int line, col;
2022-06-08 01:27:30 +02:00
enum TokenType {
2022-06-06 21:18:18 +02:00
TOK_NULL,
TOK_EOF,
TOK_ERR,
TOK_END,
TOK_BLK_OPEN,
TOK_BLK_CLS,
2022-06-08 01:27:30 +02:00
TOK_SLASH,
TOK_STAR,
TOK_DOT,
2022-06-06 21:18:18 +02:00
TOK_INT,
TOK_STR,
} type;
union {
int i;
size_t sp;
} val;
} Token;
Lexer *lexer_init(FILE *f);
void lexer_free(Lexer *ctx);
Token lexer_get_token(Lexer *ctx);
char *lexer_get_string(Lexer *ctx, Token tok);
2022-06-08 01:27:30 +02:00
char *lexer_token_type_str(enum TokenType type);
2022-06-06 21:18:18 +02:00
#endif