Implement string parsing

This commit is contained in:
bʰedoh₂ swé 2024-06-03 02:39:27 +05:00
parent 7906e6c4a8
commit 221d15fbf0

View File

@ -18,7 +18,8 @@ struct SyntaxElement* parse(FILE* file) {
bool incomment = false; bool incomment = false;
bool instring = false; bool instring = false;
bool intoken = false; bool intoken = false;
struct Extstring* token; struct Extstring* token = NULL;
struct Extstring* string = NULL;
while (1) { while (1) {
symbol = fgetc(file); symbol = fgetc(file);
if (feof(file)) if (feof(file))
@ -29,9 +30,26 @@ struct SyntaxElement* parse(FILE* file) {
continue; continue;
} }
if (instring) { if (instring) {
// TODO: String parsing if (symbol == '"') {
fprintf(stderr, "TODO: String parsing\n"); if (string == NULL) {
return NULL; string = malloc(sizeof(struct Extstring));
}
instring = false;
syntaxtree->type = STRING;
char* sstring = es_tostring(string)->string;
syntaxtree->content = sstring;
es_free(string);
string = NULL;
continue;
} else {
if (string == NULL) {
string = malloc(sizeof(struct Extstring));
string->symbol = symbol;
continue;
}
es_addsymbol(string, symbol);
continue;
}
} }
if (intoken) { if (intoken) {
if (isspace(symbol) || symbol == '(' || symbol == ')') { if (isspace(symbol) || symbol == '(' || symbol == ')') {
@ -78,6 +96,12 @@ struct SyntaxElement* parse(FILE* file) {
syntaxtree->next = NULL; syntaxtree->next = NULL;
} }
break; break;
case ';':
incomment = true;
continue;
case '"':
instring = true;
continue;
default: default:
token = malloc(sizeof(struct Extstring)); token = malloc(sizeof(struct Extstring));
token->symbol = symbol; token->symbol = symbol;