update lexer to just return the number and then do the other logic somewhere else
This commit is contained in:
@@ -1,15 +1,24 @@
|
||||
#include "parser.h"
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "../lexer/token.h"
|
||||
#include "../list/list.h"
|
||||
#include "string/string.h"
|
||||
|
||||
TaggedValue parse_token(LinkedList * tokens, size_t *index) {
|
||||
TaggedValue * parse_token(LinkedList * tokens, size_t *index) {
|
||||
Token * token = get_element_at(tokens, *index);
|
||||
switch (token->type) {
|
||||
case TOKEN_STRING:
|
||||
(*index)++;
|
||||
return parse_string(*token);
|
||||
case TOKEN_NEW_LINE:
|
||||
(*index)++;
|
||||
return NULL;
|
||||
default:
|
||||
perror("unreachable");
|
||||
exit(0);
|
||||
fprintf(stderr, "Panic: %s\n", "unreachable"); \
|
||||
exit(EXIT_FAILURE); \
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,7 +26,19 @@ void parser(LinkedList * parsed, LinkedList * tokens, bool inline_flag) {
|
||||
size_t index = 0;
|
||||
size_t length = list_length(tokens);
|
||||
while (index < length) {
|
||||
TaggedValue parsed_code = parse_token(tokens, &index);
|
||||
append(parsed,&parsed_code);
|
||||
TaggedValue * parsed_code = parse_token(tokens, &index);
|
||||
if (parsed_code)
|
||||
append(parsed,parsed_code);
|
||||
}
|
||||
}
|
||||
|
||||
void free_tagged_value(void *ptr) {
|
||||
TaggedValue *tagged = ptr;
|
||||
switch (tagged->type) {
|
||||
case AST_STRING:
|
||||
free(tagged->data);
|
||||
break;
|
||||
// Add cases if needed
|
||||
}
|
||||
free(tagged); // Always free the TaggedValue itself
|
||||
}
|
||||
Reference in New Issue
Block a user