Fix lambdas, ready for codegen
This commit is contained in:
@@ -22,7 +22,11 @@ char* createCodegenError(SolsNode* node, char* what) {
|
||||
APPEND_ESTR(err, line_buf);
|
||||
APPEND_ESTR(err, "\n\n");
|
||||
|
||||
APPEND_ESTR(err, node->line.content);
|
||||
if (node->line.content == NULL) {
|
||||
APPEND_ESTR(err, "(null line)");
|
||||
} else {
|
||||
APPEND_ESTR(err, node->line.content);
|
||||
}
|
||||
APPEND_ESTR(err, "\n");
|
||||
|
||||
return err.str;
|
||||
@@ -200,6 +204,9 @@ ResultType(SolsType, charptr) getNodeType(SolsNode* node, SolsScope* scope) {
|
||||
}
|
||||
return Success(SolsType, charptr, var->typeinfo);
|
||||
}
|
||||
case SNT_LAMBDA: {
|
||||
return Success(SolsType, charptr, node->as.type);
|
||||
}
|
||||
}
|
||||
return Error(SolsType, charptr, "Not yet implemented");
|
||||
}
|
||||
|
||||
@@ -176,10 +176,15 @@ static inline ResultType(Nothing, charptr) parseSet(SolsParser* parser) {
|
||||
ResultType(SolsToken, Nothing) peek = parserPeek(parser, 0);
|
||||
if (peek.error) return Error(Nothing, charptr, "ruh roh");
|
||||
|
||||
size_t bracketCount = 0;
|
||||
for (;;) {
|
||||
ResultType(SolsToken, Nothing) peek = parserPeek(parser, 1);
|
||||
if (peek.error) break;
|
||||
if (getPrecedence(&peek.as.success) <= STP_SET) {
|
||||
|
||||
if (peek.as.success.type == STT_OPEN_CURLY) bracketCount++;
|
||||
else if (peek.as.success.type == STT_CLOSE_CURLY && bracketCount > 0) bracketCount--;
|
||||
|
||||
if (bracketCount == 0 && getPrecedence(&peek.as.success) <= STP_SET) {
|
||||
break;
|
||||
}
|
||||
parserConsume(parser);
|
||||
@@ -1220,10 +1225,10 @@ static inline ResultType(Nothing, charptr) parseLambda(SolsParser* parser) {
|
||||
parserConsume(parser);
|
||||
}
|
||||
|
||||
if (parserPeek(parser, 1).as.success.type != STT_OPEN_CURLY) {
|
||||
ResultType(SolsToken, Nothing) openCurly = parserConsume(parser);
|
||||
if (openCurly.error || openCurly.as.success.type != STT_OPEN_CURLY) {
|
||||
return Error(Nothing, charptr, "Expecting opening curly brace ({) for lambda body");
|
||||
}
|
||||
parserConsume(parser); // Consumes {
|
||||
|
||||
// Add node to parent
|
||||
addChildToSolsNode(parser->currentParent, node.as.success);
|
||||
@@ -1256,6 +1261,7 @@ ResultType(Nothing, charptr) parse(SolsParser* parser) {
|
||||
case STT_KW_PUTS: PARSER_HANDLE(Puts);
|
||||
case STT_KW_IF: PARSER_HANDLE(If);
|
||||
case STT_KW_WHILE: PARSER_HANDLE(While);
|
||||
case STT_KW_LAMBDA: PARSER_HANDLE(Lambda);
|
||||
case STT_OP_SET: PARSER_HANDLE(Set);
|
||||
case STT_OP_ADD: PARSER_HANDLE(Add);
|
||||
case STT_OP_SUB: PARSER_HANDLE(Sub);
|
||||
|
||||
Reference in New Issue
Block a user