stuff (nearly crashing)

This commit is contained in:
2026-02-23 18:04:56 +11:00
parent efa605206a
commit 44aace638a
5 changed files with 42 additions and 11 deletions

View File

@@ -1,6 +1,7 @@
#include "SolsNode.h"
#include <stdarg.h>
#include <stdio.h>
#include "../include/error.h"
#include "../lexer/SolsLiteral.h"
@@ -54,7 +55,8 @@ ResultType(Nothing, charptr) addChildToSolsNode(SolsNode* parent, SolsNode child
}
parent->children.at = tmp;
}
parent->children.at[parent->children.capacity] = child;
parent->children.capacity++;
printf("capacity: %zu, count: %zu\n", parent->children.capacity, parent->children.count);
parent->children.at[parent->children.count] = child;
parent->children.count++;
return Success(Nothing, charptr, {});
}

View File

@@ -9,6 +9,7 @@ ResultType(SolsParser, charptr) createSolsParser(SolsTokens* input) {
if (node.error) {
Estr str = CREATE_ESTR(node.as.error);
APPEND_ESTR(str, " (in createSolsParser() function)");
return Error(SolsParser, charptr, str.str);
}
SolsParser parser = {
.input = input,
@@ -60,6 +61,7 @@ void createParserError(SolsParser* parser, char* what) {
parser->errors.at[parser->errors.count - 1] = "Failed to allocate more memory for createParserError function";
return;
}
parser->errors.at = tmp;
}
Estr err = CREATE_ESTR(ESC_BOLD ESC_RED_FG "error: " ESC_RESET ESC_BOLD);
@@ -96,13 +98,30 @@ void createParserError(SolsParser* parser, char* what) {
static inline ResultType(Nothing, charptr) parseIdentifier(SolsParser* parser) {
ResultType(SolsToken, Nothing) peek = parserPeek(parser, 0);
return Error(Nothing, charptr, "Not an error, just curious what errors look like");
if (peek.error) {
return Error(Nothing, charptr, "ruh roh");
}
ResultType(SolsNode, charptr) node = createSolsNode(SNT_IDENTIFIER, peek.as.success.as.idName);
if (node.error) {
Estr err = CREATE_ESTR(node.as.error);
APPEND_ESTR(err, " (in parseLiteral() function)");
return Error(Nothing, charptr, err.str);
}
// addChildToSolsNode(parser->currentParent, node.as.success);
return Success(Nothing, charptr, {});
}
static inline ResultType(Nothing, charptr) parseLiteral(SolsParser* parser) {
return Error(Nothing, charptr, "Not an error, just curious what errors look like");
ResultType(SolsToken, Nothing) peek = parserPeek(parser, 0);
if (peek.error) {
return Error(Nothing, charptr, "ruh roh");
}
ResultType(SolsNode, charptr) node = createSolsNode(SNT_LITERAL, peek.as.success.as.literal);
if (node.error) {
Estr err = CREATE_ESTR(node.as.error);
APPEND_ESTR(err, " (in parseLiteral() function)");
return Error(Nothing, charptr, err.str);
}
// addChildToSolsNode(parser->currentParent, node.as.success);
return Success(Nothing, charptr, {});
}
@@ -144,7 +163,7 @@ ResultType(SolsToken, Nothing) parserLookAt(SolsParser* parser, size_t where) {
return Success(SolsToken, Nothing, parser->input->at[where]);
}
ResultType(SolsToken, Nothing) parserPeek(SolsParser* parser, size_t ahead) {
ResultType(SolsToken, Nothing) parserPeek(SolsParser* parser, int64_t ahead) {
if (parser->input == NULL) {
return Error(SolsToken, Nothing, {});
}

View File

@@ -38,6 +38,13 @@ ResultType(SolsParser, charptr) createSolsParser(SolsTokens* input);
// Failure: char* detailing what went wrong (usually user error)
ResultType(Nothing, charptr) parse(SolsParser* parser);
Result(SolsNode, Nothing);
// Parses one singular node and returns it.
// Returns:
// Success: The parsed SolsNode
// Failure: Nothing (out of bounds, or an error)
Result(SolsToken, Nothing);
// Peeks at a token at a specific index in the lexer, 0 being the first token.
@@ -50,7 +57,7 @@ ResultType(SolsToken, Nothing) parserLookAt(SolsParser* parser, size_t where);
// Returns:
// Success: The requested token
// Failure: Nothing (token is out of bounds)
ResultType(SolsToken, Nothing) parserPeek(SolsParser* parser, size_t ahead);
ResultType(SolsToken, Nothing) parserPeek(SolsParser* parser, int64_t ahead);
// Consumes the next token in the parser.
// Returns:
@@ -61,7 +68,6 @@ ResultType(SolsToken, Nothing) parserConsume(SolsParser* parser);
// Macro for cleaner handling of each token type in the parser.
// Calls functions and returns errors for you! Such amazing
#define PARSER_HANDLE(tokentype) {\
printf("Currently parsing " #tokentype "\n");\
ResultType(Nothing, charptr) __result = parse##tokentype(parser);\
if (__result.error) {\
createParserError(parser, __result.as.error);\