This repository has been archived on 2026-03-01. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
v2/src/lexer/lexer.c

35 lines
1.0 KiB
C
Raw Normal View History

2026-02-05 19:14:31 +11:00
#include "lexer.h"
2026-02-06 15:48:13 +11:00
#include "SolsToken.h"
2026-02-05 19:14:31 +11:00
#include "../include/error.h"
2026-02-06 15:48:13 +11:00
#include "../include/estr.h"
2026-02-05 19:14:31 +11:00
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);
2026-02-06 15:48:13 +11:00
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);
}
2026-02-05 19:14:31 +11:00
SolsLexer lexer = {
.input = inputcopy,
2026-02-06 15:48:13 +11:00
.output = tokens.as.success,
2026-02-05 19:14:31 +11:00
.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);
}