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