aboutsummaryrefslogtreecommitdiff
path: root/include/lex.h
diff options
context:
space:
mode:
authorHimbeer <himbeer@disroot.org>2024-09-19 21:59:35 +0200
committerHimbeer <himbeer@disroot.org>2024-09-19 22:09:49 +0200
commit68effb746fc33f90b6fe537893f18ac0aac4e7f0 (patch)
tree9906b31bd5866014cf9c74fbd7ee6c40faeb048a /include/lex.h
parenta278c311ee4a76c5855d4a8339c15c054a6eca19 (diff)
Store token locations and include them in parsing error messages
Diffstat (limited to 'include/lex.h')
-rw-r--r--include/lex.h11
1 files changed, 10 insertions, 1 deletions
diff --git a/include/lex.h b/include/lex.h
index ba1596d..51485a5 100644
--- a/include/lex.h
+++ b/include/lex.h
@@ -103,8 +103,14 @@ struct number {
} value;
};
+struct location {
+ const char *file;
+ int line, column;
+};
+
struct token {
enum lexical_token token;
+ struct location loc;
union {
struct number num;
const char *str;
@@ -117,11 +123,14 @@ struct lexer {
char *buf;
size_t bufsz, buflen;
struct token un;
+ struct location loc;
};
-void lex_init(struct lexer *lexer, FILE *f);
+void lex_init(struct lexer *lexer, FILE *f, const char *filename);
void lex_finish(struct lexer *lexer);
+struct location lex_loc(struct lexer *lexer);
+
enum lexical_token lex(struct lexer *lexer, struct token *out);
void unlex(struct lexer *lexer, const struct token *in);
bool match(struct lexer *lexer, enum lexical_token token);