forked from solstice/solstice
Type parser
This commit is contained in:
@@ -55,7 +55,16 @@ ResultType(Nothing, charptr) addChildToSolsNode(SolsNode* parent, SolsNode child
|
||||
}
|
||||
parent->children.at = tmp;
|
||||
}
|
||||
parent->children.at[parent->children.count] = child;
|
||||
parent->children.at[parent->children.count] = deepCopySolsNode(child);
|
||||
parent->children.count++;
|
||||
return Success(Nothing, charptr, {});
|
||||
}
|
||||
|
||||
SolsNode deepCopySolsNode(SolsNode node) {
|
||||
SolsNode copy = node;
|
||||
copy.children.at = malloc(sizeof(SolsNode) * node.children.capacity);
|
||||
for (size_t i = 0; i < node.children.count; i++) {
|
||||
copy.children.at[i] = deepCopySolsNode(node.children.at[i]);
|
||||
}
|
||||
return copy;
|
||||
}
|
||||
|
||||
@@ -59,4 +59,7 @@ ResultType(SolsNode, charptr) createSolsNode(SolsNodeType type, ...);
|
||||
// Failure: char* detailing what went wrong (usually memory failure)
|
||||
ResultType(Nothing, charptr) addChildToSolsNode(SolsNode* parent, SolsNode child);
|
||||
|
||||
// Deep copies a SolsNode
|
||||
SolsNode deepCopySolsNode(SolsNode node);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -6,6 +6,21 @@
|
||||
#include <groundvm.h>
|
||||
|
||||
SolsTokenPrecedence getPrecedence(SolsToken *token) {
|
||||
static size_t braceCount = 0;
|
||||
switch (token->type) {
|
||||
case STT_OPEN_CURLY: {
|
||||
braceCount++;
|
||||
return STP_OTHER;
|
||||
}
|
||||
case STT_CLOSE_CURLY: {
|
||||
braceCount--;
|
||||
return STP_OTHER;
|
||||
}
|
||||
default: break;
|
||||
}
|
||||
if (braceCount > 0) {
|
||||
return STP_OTHER;
|
||||
}
|
||||
switch (token->type) {
|
||||
case STT_LINE_END: return STP_NEWLINE;
|
||||
case STT_KW_PUTS: return STP_PUTS;
|
||||
@@ -1399,9 +1414,7 @@ static inline ResultType(Nothing, charptr) parseDef(SolsParser* parser) {
|
||||
SolsNode codeBlock = parser->currentParent->children.at[parser->currentParent->children.count - 1];
|
||||
parser->currentParent->children.count--;
|
||||
|
||||
// We need to get the actual node from the parent to modify it
|
||||
SolsNode* defNode = &parser->currentParent->children.at[parser->currentParent->children.count - 1];
|
||||
addChildToSolsNode(defNode, codeBlock);
|
||||
addChildToSolsNode(&parser->currentParent->children.at[0], parser->currentParent->children.at[1]);
|
||||
|
||||
return Success(Nothing, charptr, {});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user