Bug fixes

This commit is contained in:
2026-02-21 15:36:57 +11:00
parent f29b6fca31
commit 9383d5d84a

View File

@@ -7,7 +7,7 @@
#include <ctype.h> #include <ctype.h>
struct _SolsTokenTypeMap SolsTokenTypeMap[] = { struct _SolsTokenTypeMap SolsTokenTypeMap[] = {
{"puts", STT_KW_STRUCT}, {"puts", STT_KW_PUTS},
{"if", STT_KW_IF}, {"if", STT_KW_IF},
{"while", STT_KW_WHILE}, {"while", STT_KW_WHILE},
{"def", STT_KW_DEF}, {"def", STT_KW_DEF},
@@ -17,7 +17,7 @@ struct _SolsTokenTypeMap SolsTokenTypeMap[] = {
{"(", STT_OPEN_PAREN}, {"(", STT_OPEN_PAREN},
{")", STT_CLOSE_PAREN}, {")", STT_CLOSE_PAREN},
{"+", STT_OP_ADD}, {"+", STT_OP_ADD},
{"-", STT_OP_DIV}, {"-", STT_OP_SUB},
{"*", STT_OP_MUL}, {"*", STT_OP_MUL},
{"/", STT_OP_DIV}, {"/", STT_OP_DIV},
{"=", STT_OP_SET}, {"=", STT_OP_SET},
@@ -98,6 +98,9 @@ ResultType(SolsLexer, charptr) createLexer(char* input) {
ResultType(char, Nothing) lexerPeek(SolsLexer* lexer, size_t ahead) { ResultType(char, Nothing) lexerPeek(SolsLexer* lexer, size_t ahead) {
// Reduce by 1 so peeking at the next token with 1 works
ahead--;
// Bounds and null checking // Bounds and null checking
if (lexer->input == NULL) { if (lexer->input == NULL) {
return Error(char, Nothing, {}); return Error(char, Nothing, {});
@@ -497,7 +500,7 @@ ResultType(Nothing, charptr) lex(SolsLexer* lexer) {
buf = CREATE_ESTR(""); buf = CREATE_ESTR("");
} }
ResultType(char, Nothing) next = lexerPeek(lexer, 1); ResultType(char, Nothing) next = lexerPeek(lexer, 1);
if (next.error || next.as.success != chr.as.success || next.as.success != '=') { if (next.error || (next.as.success != chr.as.success && next.as.success != '=')) {
char tmp[] = {chr.as.success, '\0'}; char tmp[] = {chr.as.success, '\0'};
ResultType(SolsToken, charptr) result = identifyToken(tmp); ResultType(SolsToken, charptr) result = identifyToken(tmp);
if (result.error) { if (result.error) {