#include "lexer.h" #include "SolsToken.h" #include "../include/error.h" #include "../include/estr.h" ResultType(SolsLexer, charptr) createLexer(char* input) { char* inputcopy = malloc(strlen(input) + 1); if (inputcopy == NULL) { return Error(SolsLexer, charptr, "Couldn't copy string into lexer (in createLexer() function)"); } strcpy(inputcopy, input); ResultType(SolsTokens, charptr) tokens = createSolsTokens(); if (tokens.error) { Estr e = CREATE_ESTR(tokens.as.error); APPEND_ESTR(e, " (in createLexer() function)"); return Error(SolsLexer, charptr, e.str); } SolsLexer lexer = { .input = inputcopy, .output = tokens.as.success, .current = 0, }; return Success(SolsLexer, charptr, lexer); } ResultType(voidptr, charptr) lex(SolsLexer* lexer) { if (lexer->input == NULL) { return Error(voidptr, charptr, "Lexer is not initialised"); } lexer->current = 0; return Success(voidptr, charptr, NULL); }