Last bit of clean up before building the parser.
This commit is contained in:
+9
-29
@@ -7,40 +7,20 @@ Token* CreateToken(TokenType, char*);
|
||||
Token* GetNextToken(char *);
|
||||
int TokenIsNumeric(const char*, int *);
|
||||
|
||||
List* GenerateTokensFromFile(const char* file_path) {
|
||||
FILE *file;
|
||||
int line_count = 1;
|
||||
char* line = NULL;
|
||||
size_t len = 0;
|
||||
ssize_t bytes_read;
|
||||
List* GetTokensFromLine(char* line) {
|
||||
List* tokens = CreateList();
|
||||
|
||||
Token* token = GetNextToken(line);
|
||||
|
||||
file = fopen(file_path, "r");
|
||||
while (token) {
|
||||
|
||||
if (!file) {
|
||||
printf("Failed to open '%s' for reading.\n", file_path);
|
||||
return NULL;
|
||||
if (!token) break;
|
||||
|
||||
AddListItem(token, sizeof(Token), tokens);
|
||||
|
||||
token = GetNextToken(NULL);
|
||||
}
|
||||
|
||||
while((bytes_read = getline(&line, &len, file)) != -1) {
|
||||
Token* token = GetNextToken(line);
|
||||
|
||||
while (token) {
|
||||
|
||||
if (!token) break;
|
||||
|
||||
AddListItem(token, sizeof(Token), tokens);
|
||||
|
||||
token = GetNextToken(NULL);
|
||||
}
|
||||
|
||||
line_count++;
|
||||
}
|
||||
|
||||
fclose(file);
|
||||
|
||||
if (line) free(line);
|
||||
|
||||
return tokens;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user