From 221d15fbf04874128544add0b86faed2b3d3d645 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?b=CA=B0edoh=E2=82=82=20sw=C3=A9?= Date: Mon, 3 Jun 2024 02:39:27 +0500 Subject: [PATCH] Implement string parsing --- src/parser.c | 32 ++++++++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 4 deletions(-) diff --git a/src/parser.c b/src/parser.c index 6e51529..942f338 100644 --- a/src/parser.c +++ b/src/parser.c @@ -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;