summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Phillips <david@sighup.nz>2018-08-06 01:30:09 +1200
committerDavid Phillips <david@sighup.nz>2018-08-06 01:30:09 +1200
commite4e292fce970257a7ee09f547cb905794af1a8d4 (patch)
treeb3060d84843b1bb56dab7c6013d226d5d37ae653
parent948160bed032bbfe174fb7b8e25a2b772e6c3369 (diff)
downloadhence-e4e292fce970257a7ee09f547cb905794af1a8d4.tar.xz
lex: add filename to error
Brings lexing error message format more into line with parser
-rw-r--r--hence.c2
-rw-r--r--lex.c6
-rw-r--r--lex.h2
3 files changed, 6 insertions, 4 deletions
diff --git a/hence.c b/hence.c
index b9f69bd..bc4b702 100644
--- a/hence.c
+++ b/hence.c
@@ -23,7 +23,7 @@ int main(int argc, char **argv) {
return 1;
}
- struct token *tok = lex_file(fd);
+ struct token *tok = lex_file(argv[1], fd);
int p = parse(argv[1], fd, tok);
// gate_set_input("a", LOGIC_LOW);
diff --git a/lex.c b/lex.c
index 6dc38d2..6777e42 100644
--- a/lex.c
+++ b/lex.c
@@ -6,7 +6,7 @@
#include "common.h"
#include "token.h"
-#define emit_error(...) fprintf(stderr, "Error (%zd,%zd): ", line_number, 1 + column_number);\
+#define emit_error(...) fprintf(stderr, "%s at (%zd,%zd): ", filename, line_number, 1 + column_number);\
fprintf(stderr, __VA_ARGS__)
#define BUFFER_SIZE 1024
@@ -50,6 +50,7 @@ static struct keyword token_descriptors[] = {
static char buf[BUFFER_SIZE];
static FILE* fd;
+static const char *filename = NULL;
static size_t line_number = 0;
static size_t column_number = 0;
static ssize_t leading_whitespace_len = 0;
@@ -230,7 +231,8 @@ lex_line(void) {
}
struct token *
-lex_file(FILE *fd_local) {
+lex_file(const char *filename_local, FILE *fd_local) {
+ filename = filename_local;
fd = fd_local;
line_number = 1;
diff --git a/lex.h b/lex.h
index 9a1be52..ee2795f 100644
--- a/lex.h
+++ b/lex.h
@@ -5,7 +5,7 @@
#include "token.h"
-struct token* lex_file(FILE*);
+struct token* lex_file(const char *, FILE*);
const char *get_token_description(enum TOKEN_TYPE);
#endif