Add all the other inequalities

This commit is contained in:
2026-02-28 10:25:26 +11:00
parent 8756dd08c8
commit fbddd9a199
3 changed files with 526 additions and 1 deletions

View File

@@ -535,6 +535,321 @@ static inline ResultType(Nothing, charptr) parseEqual(SolsParser* parser) {
return Success(Nothing, charptr, {});
}
static inline ResultType(Nothing, charptr) parseInequal(SolsParser* parser) {
if (parser->currentParent->children.count < 1) {
return Error(Nothing, charptr, "Expecting something before '!='");
}
// Collect tokens for node
ResultType(SolsTokens, charptr) tokens = createSolsTokens();
if (tokens.error) {
return Error(Nothing, charptr, tokens.as.error);
}
// Get the 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");
for (;;) {
ResultType(SolsToken, Nothing) peek = parserPeek(parser, 1);
if (peek.error) break;
if (getPrecedence(&peek.as.success) <= STP_COMPARE) {
break;
}
parserConsume(parser);
addTokenToSolsTokens(&tokens.as.success, peek.as.success);
}
// Create node
ResultType(SolsNode, charptr) node = createSolsNode(SNT_OP_INEQUAL);
if (node.error) return Error(Nothing, charptr, node.as.error);
node.as.success.line = peek.as.success.line;
// Parse selected tokens
ResultType(SolsParser, charptr) putsParser = createSolsParser(&tokens.as.success);
if (putsParser.error) return Error(Nothing, charptr, putsParser.as.error);
putsParser.as.success.currentParent = &putsParser.as.success.output;
ResultType(Nothing, charptr) parsed = parse(&putsParser.as.success);
// Add any error messages from parsing
if (parsed.error) {
addToParserErrors(parser, parsed.as.error);
return Success(Nothing, charptr, {});
}
if (putsParser.as.success.output.children.count < 1) {
return Error(Nothing, charptr, "Expecting token after '!='");
}
// 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 equal node where the idNode was
parser->currentParent->children.count--;
addChildToSolsNode(parser->currentParent, node.as.success);
return Success(Nothing, charptr, {});
}
static inline ResultType(Nothing, charptr) parseGreater(SolsParser* parser) {
if (parser->currentParent->children.count < 1) {
return Error(Nothing, charptr, "Expecting something before '>'");
}
// Collect tokens for node
ResultType(SolsTokens, charptr) tokens = createSolsTokens();
if (tokens.error) {
return Error(Nothing, charptr, tokens.as.error);
}
// Get the 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");
for (;;) {
ResultType(SolsToken, Nothing) peek = parserPeek(parser, 1);
if (peek.error) break;
if (getPrecedence(&peek.as.success) <= STP_COMPARE) {
break;
}
parserConsume(parser);
addTokenToSolsTokens(&tokens.as.success, peek.as.success);
}
// Create node
ResultType(SolsNode, charptr) node = createSolsNode(SNT_OP_GREATER);
if (node.error) return Error(Nothing, charptr, node.as.error);
node.as.success.line = peek.as.success.line;
// Parse selected tokens
ResultType(SolsParser, charptr) putsParser = createSolsParser(&tokens.as.success);
if (putsParser.error) return Error(Nothing, charptr, putsParser.as.error);
putsParser.as.success.currentParent = &putsParser.as.success.output;
ResultType(Nothing, charptr) parsed = parse(&putsParser.as.success);
// Add any error messages from parsing
if (parsed.error) {
addToParserErrors(parser, parsed.as.error);
return Success(Nothing, charptr, {});
}
if (putsParser.as.success.output.children.count < 1) {
return Error(Nothing, charptr, "Expecting token after '>'");
}
// 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 equal node where the idNode was
parser->currentParent->children.count--;
addChildToSolsNode(parser->currentParent, node.as.success);
return Success(Nothing, charptr, {});
}
static inline ResultType(Nothing, charptr) parseLesser(SolsParser* parser) {
if (parser->currentParent->children.count < 1) {
return Error(Nothing, charptr, "Expecting something before '<'");
}
// Collect tokens for node
ResultType(SolsTokens, charptr) tokens = createSolsTokens();
if (tokens.error) {
return Error(Nothing, charptr, tokens.as.error);
}
// Get the 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");
for (;;) {
ResultType(SolsToken, Nothing) peek = parserPeek(parser, 1);
if (peek.error) break;
if (getPrecedence(&peek.as.success) <= STP_COMPARE) {
break;
}
parserConsume(parser);
addTokenToSolsTokens(&tokens.as.success, peek.as.success);
}
// Create node
ResultType(SolsNode, charptr) node = createSolsNode(SNT_OP_LESSER);
if (node.error) return Error(Nothing, charptr, node.as.error);
node.as.success.line = peek.as.success.line;
// Parse selected tokens
ResultType(SolsParser, charptr) putsParser = createSolsParser(&tokens.as.success);
if (putsParser.error) return Error(Nothing, charptr, putsParser.as.error);
putsParser.as.success.currentParent = &putsParser.as.success.output;
ResultType(Nothing, charptr) parsed = parse(&putsParser.as.success);
// Add any error messages from parsing
if (parsed.error) {
addToParserErrors(parser, parsed.as.error);
return Success(Nothing, charptr, {});
}
if (putsParser.as.success.output.children.count < 1) {
return Error(Nothing, charptr, "Expecting token after '<'");
}
// 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 equal node where the idNode was
parser->currentParent->children.count--;
addChildToSolsNode(parser->currentParent, node.as.success);
return Success(Nothing, charptr, {});
}
static inline ResultType(Nothing, charptr) parseEqGreater(SolsParser* parser) {
if (parser->currentParent->children.count < 1) {
return Error(Nothing, charptr, "Expecting something before '>='");
}
// Collect tokens for node
ResultType(SolsTokens, charptr) tokens = createSolsTokens();
if (tokens.error) {
return Error(Nothing, charptr, tokens.as.error);
}
// Get the 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");
for (;;) {
ResultType(SolsToken, Nothing) peek = parserPeek(parser, 1);
if (peek.error) break;
if (getPrecedence(&peek.as.success) <= STP_COMPARE) {
break;
}
parserConsume(parser);
addTokenToSolsTokens(&tokens.as.success, peek.as.success);
}
// Create node
ResultType(SolsNode, charptr) node = createSolsNode(SNT_OP_EQGREATER);
if (node.error) return Error(Nothing, charptr, node.as.error);
node.as.success.line = peek.as.success.line;
// Parse selected tokens
ResultType(SolsParser, charptr) putsParser = createSolsParser(&tokens.as.success);
if (putsParser.error) return Error(Nothing, charptr, putsParser.as.error);
putsParser.as.success.currentParent = &putsParser.as.success.output;
ResultType(Nothing, charptr) parsed = parse(&putsParser.as.success);
// Add any error messages from parsing
if (parsed.error) {
addToParserErrors(parser, parsed.as.error);
return Success(Nothing, charptr, {});
}
if (putsParser.as.success.output.children.count < 1) {
return Error(Nothing, charptr, "Expecting token after '>='");
}
// 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 equal node where the idNode was
parser->currentParent->children.count--;
addChildToSolsNode(parser->currentParent, node.as.success);
return Success(Nothing, charptr, {});
}
static inline ResultType(Nothing, charptr) parseEqLesser(SolsParser* parser) {
if (parser->currentParent->children.count < 1) {
return Error(Nothing, charptr, "Expecting something before '<='");
}
// Collect tokens for node
ResultType(SolsTokens, charptr) tokens = createSolsTokens();
if (tokens.error) {
return Error(Nothing, charptr, tokens.as.error);
}
// Get the 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");
for (;;) {
ResultType(SolsToken, Nothing) peek = parserPeek(parser, 1);
if (peek.error) break;
if (getPrecedence(&peek.as.success) <= STP_COMPARE) {
break;
}
parserConsume(parser);
addTokenToSolsTokens(&tokens.as.success, peek.as.success);
}
// Create node
ResultType(SolsNode, charptr) node = createSolsNode(SNT_OP_EQLESSER);
if (node.error) return Error(Nothing, charptr, node.as.error);
node.as.success.line = peek.as.success.line;
// Parse selected tokens
ResultType(SolsParser, charptr) putsParser = createSolsParser(&tokens.as.success);
if (putsParser.error) return Error(Nothing, charptr, putsParser.as.error);
putsParser.as.success.currentParent = &putsParser.as.success.output;
ResultType(Nothing, charptr) parsed = parse(&putsParser.as.success);
// Add any error messages from parsing
if (parsed.error) {
addToParserErrors(parser, parsed.as.error);
return Success(Nothing, charptr, {});
}
if (putsParser.as.success.output.children.count < 1) {
return Error(Nothing, charptr, "Expecting token after '<='");
}
// 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 equal node where the idNode was
parser->currentParent->children.count--;
addChildToSolsNode(parser->currentParent, node.as.success);
return Success(Nothing, charptr, {});
}
static inline ResultType(Nothing, charptr) parseLiteral(SolsParser* parser) {
ResultType(SolsToken, Nothing) peek = parserPeek(parser, 0);
if (peek.error) {
@@ -643,6 +958,11 @@ ResultType(Nothing, charptr) parse(SolsParser* parser) {
case STT_OP_MUL: PARSER_HANDLE(Mul);
case STT_OP_DIV: PARSER_HANDLE(Div);
case STT_OP_EQUAL: PARSER_HANDLE(Equal);
case STT_OP_INEQUAL: PARSER_HANDLE(Inequal);
case STT_OP_GREATER: PARSER_HANDLE(Greater);
case STT_OP_LESSER: PARSER_HANDLE(Lesser);
case STT_OP_EQGREATER: PARSER_HANDLE(EqGreater);
case STT_OP_EQLESSER: PARSER_HANDLE(EqLesser);
}
}
if (parser->errors.count > 0) {