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;