diff options
author | David Phillips <david@sighup.nz> | 2018-08-06 01:40:02 +1200 |
---|---|---|
committer | David Phillips <david@sighup.nz> | 2018-08-06 01:40:02 +1200 |
commit | 5dbadfa0448e3324479ece98045c0a427856f382 (patch) | |
tree | 338998ddbfc0eed315845199f18d7bd4050d9a60 /lex.c | |
parent | 0bff14977a2e4196bf4cd06481b8d0a93a563816 (diff) | |
download | hence-5dbadfa0448e3324479ece98045c0a427856f382.tar.xz |
Add TOK_BEGIN
This lets us indicate that the lexer succeeded, even on an empty program.
Previous behaviour was to return NULL on failure and on lex success of
an empty progam. Enforcing the presence of a head for the linked token list
ensures that we can reliably detect error as a caller of the lexer.
Fixes test just added in previous commit too.
Diffstat (limited to 'lex.c')
-rw-r--r-- | lex.c | 5 |
1 files changed, 5 insertions, 0 deletions
@@ -232,12 +232,17 @@ lex_line(void) { struct token * lex_file(const char *filename_local, FILE *fd_local) { + struct token start; + filename = filename_local; fd = fd_local; line_number = 1; tok_cursor = tok_start = NULL; + start.type = TOK_BEGIN; + add_token(start); + while (NULL != fgets(buf, sizeof(buf), fd)) { column_number = 0; if (lex_line()) { |