Skip to content

Commit d76252c

Browse files
committed
Moved the responsibility for opening files from the parser to stream.c
1 parent 566cdfd commit d76252c

File tree

5 files changed

+7
-7
lines changed

5 files changed

+7
-7
lines changed

inc/lexer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ typedef struct lexerCtx {
7474
int length;
7575
} lexerCtx;
7676

77-
lexerCtx* lexerInit (FILE* file);
77+
lexerCtx* lexerInit (const char* filename);
7878
void lexerEnd (lexerCtx* ctx);
7979

8080
void lexerNext (lexerCtx* ctx);

inc/stream.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ typedef struct streamCtx {
1313
int lineChar;
1414
} streamCtx;
1515

16-
streamCtx* streamInit (FILE* file);
16+
streamCtx* streamInit (const char* filename);
1717
void streamEnd (streamCtx* ctx);
1818

1919
/**

src/lexer.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ static bool lexerTryEatNext (lexerCtx* ctx, char c);
1616

1717
static keywordTag lookKeyword (const char* str);
1818

19-
lexerCtx* lexerInit (FILE* file) {
19+
lexerCtx* lexerInit (const char* filename) {
2020
lexerCtx* ctx = malloc(sizeof(lexerCtx));
21-
ctx->stream = streamInit(file);
21+
ctx->stream = streamInit(filename);
2222
ctx->line = 1;
2323
ctx->lineChar = 1;
2424

src/parser.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ static ast* parserDoWhile (parserCtx* ctx);
2525
static ast* parserFor (parserCtx* ctx);
2626

2727
static void parserInit (parserCtx* ctx, sym* scope, char* filename, char* fullname, compilerCtx* comp) {
28-
ctx->lexer = lexerInit(fopen(fullname, "r"));
28+
ctx->lexer = lexerInit(fullname);
2929
ctx->location = (tokenLocation) {0, 0, 0};
3030

3131
ctx->filename = filename;

src/stream.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
#include "stdlib.h"
77
#include "stdio.h"
88

9-
streamCtx* streamInit (FILE* file) {
9+
streamCtx* streamInit (const char* filename) {
1010
streamCtx* ctx = malloc(sizeof(streamCtx));
11-
ctx->file = file;
11+
ctx->file = fopen(filename, "r");
1212

1313
ctx->current = 0;
1414
ctx->line = 1;

0 commit comments

Comments
 (0)