stuff (nearly crashing)
This commit is contained in:
@@ -10,7 +10,7 @@
|
||||
#include "SolsLiteral.h"
|
||||
|
||||
typedef enum SolsTokenType {
|
||||
STT_IDENTIFIER, STT_LITERAL, STT_TYPE, STT_DOT, STT_OPEN_CURLY, STT_CLOSE_CURLY, STT_OPEN_PAREN, STT_CLOSE_PAREN, STT_OP_ADD, STT_OP_SUB, STT_OP_MUL, STT_OP_DIV, STT_OP_ADDTO, STT_OP_SUBTO, STT_OP_MULTO, STT_OP_DIVTO, STT_OP_INCREMENT, STT_OP_DECREMENT, STT_OP_SET, STT_OP_GREATER, STT_OP_LESSER, STT_OP_EQUAL, STT_OP_INEQUAL, STT_OP_EQGREATER, STT_OP_EQLESSER, STT_KW_DEF, STT_KW_STRUCT, STT_KW_PUTS, STT_KW_IF, STT_KW_WHILE, STT_KW_NEW, STT_KW_GROUND
|
||||
STT_IDENTIFIER, STT_LITERAL, STT_TYPE, STT_DOT, STT_OPEN_CURLY, STT_CLOSE_CURLY, STT_OPEN_PAREN, STT_CLOSE_PAREN, STT_OP_ADD, STT_OP_SUB, STT_OP_MUL, STT_OP_DIV, STT_OP_ADDTO, STT_OP_SUBTO, STT_OP_MULTO, STT_OP_DIVTO, STT_OP_INCREMENT, STT_OP_DECREMENT, STT_OP_SET, STT_OP_GREATER, STT_OP_LESSER, STT_OP_EQUAL, STT_OP_INEQUAL, STT_OP_EQGREATER, STT_OP_EQLESSER, STT_KW_DEF, STT_KW_STRUCT, STT_KW_PUTS, STT_KW_IF, STT_KW_WHILE, STT_KW_NEW, STT_KW_GROUND, STT_LINE_END
|
||||
} SolsTokenType;
|
||||
|
||||
typedef char* charptr;
|
||||
|
||||
@@ -33,6 +33,8 @@ struct _SolsTokenTypeMap SolsTokenTypeMap[] = {
|
||||
{"<", STT_OP_LESSER},
|
||||
{">=", STT_OP_EQGREATER},
|
||||
{"<=", STT_OP_EQLESSER},
|
||||
{"\n", STT_LINE_END},
|
||||
{";", STT_LINE_END},
|
||||
// Shh, this is our little secret
|
||||
// Your reward for actually reading the source code
|
||||
// Enable this by adding -DSUPER_SILLY_MODE to your
|
||||
@@ -472,6 +474,8 @@ ResultType(Nothing, charptr) lex(SolsLexer* lexer) {
|
||||
case ')':
|
||||
case ',':
|
||||
case ':':
|
||||
case ';':
|
||||
case '\n':
|
||||
{
|
||||
if (strcmp(buf.str, "") != 0) {
|
||||
ResultType(SolsToken, charptr) result = identifyToken(buf.str);
|
||||
@@ -714,7 +718,7 @@ ResultType(Nothing, charptr) lex(SolsLexer* lexer) {
|
||||
}
|
||||
|
||||
// This whitespace splits the program and does not get appended as it's own token.
|
||||
case '\n':
|
||||
case '\t':
|
||||
case ' ': {
|
||||
if (strcmp(buf.str, "") != 0) {
|
||||
ResultType(SolsToken, charptr) result = identifyToken(buf.str);
|
||||
|
||||
@@ -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, {});
|
||||
}
|
||||
|
||||
@@ -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, {});
|
||||
}
|
||||
|
||||
@@ -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);\
|
||||
|
||||
Reference in New Issue
Block a user