diff --git a/src/parser/parser.c b/src/parser/parser.c index f277675..174ed54 100644 --- a/src/parser/parser.c +++ b/src/parser/parser.c @@ -149,7 +149,10 @@ static inline ResultType(Nothing, charptr) parseIdentifier(SolsParser* parser) { } static inline ResultType(Nothing, charptr) parseSet(SolsParser* parser) { - if (parser->output.children.at[parser->output.children.count - 1].type != SNT_IDENTIFIER) { + if (parser->currentParent->children.count < 1) { + return Error(Nothing, charptr, "Expecting identifier before '='"); + } + if (parser->currentParent->children.at[parser->output.children.count - 1].type != SNT_IDENTIFIER) { return Error(Nothing, charptr, "Expecting identifier before '='"); } @@ -159,6 +162,9 @@ static inline ResultType(Nothing, charptr) parseSet(SolsParser* parser) { return Error(Nothing, charptr, tokens.as.error); } + // Get the identifier (previous node) + SolsNode idNode = parser->currentParent->children.at[parser->currentParent->children.count - 1]; + ResultType(SolsToken, Nothing) peek = parserPeek(parser, 0); if (peek.error) return Error(Nothing, charptr, "ruh roh"); @@ -193,11 +199,16 @@ static inline ResultType(Nothing, charptr) parseSet(SolsParser* parser) { return Error(Nothing, charptr, "Expecting token after '='"); } - // Copy nodes into the sols node + // Copy idnode into set node + addChildToSolsNode(&node.as.success, idNode); + + // Copy nodes into the set node for (size_t i = 0; i < putsParser.as.success.output.children.count; i++) { addChildToSolsNode(&node.as.success, putsParser.as.success.output.children.at[i]); } + // Put the set node where the idNode was + parser->currentParent->children.count--; addChildToSolsNode(parser->currentParent, node.as.success); return Success(Nothing, charptr, {}); diff --git a/test.sols b/test.sols index 6e7e69f..51d482f 100644 --- a/test.sols +++ b/test.sols @@ -1,5 +1,5 @@ // heheheha comment -= x 5 +x = 5 puts x