Skip to content

Commit

Permalink
Return null instead of an empty string when no error was found
Browse files Browse the repository at this point in the history
  • Loading branch information
Elscrux authored and schweikart committed Jan 22, 2024
1 parent 8c6a76e commit f5833ba
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
12 changes: 8 additions & 4 deletions src/converter/dimacs/LogicalExpressionValidator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,17 @@ export class LogicalExpressionValidator {
/**
* Validates a logical expression
* @param logicalExpression {string} logical expression
* @returns {string[]} an array of errors. If empty, the logical expression is valid.
* @returns {string[]} an array of errors, or null if there are none.
*/
public validateLogicalExpression(logicalExpression: string): string[] {
public validateLogicalExpression(logicalExpression: string): string[] | null {
let tokens = this.lex.tokenize(logicalExpression);
if (tokens.length == 0) return [];

//Verify formula integrity
return this.verifyTokens(tokens);
}

private verifyTokens(tokens: Token[]): string[] {
private verifyTokens(tokens: Token[]): string[] | null {
let errors: string[] = [];
let wasOperator = false;
let wasVariable = false;
Expand Down Expand Up @@ -107,6 +107,10 @@ export class LogicalExpressionValidator {
wasNegate = token.name == TokenName.negate;
}

return errors;
if (errors.length > 0) {
return errors;
} else {
return null;
}
}
}
2 changes: 1 addition & 1 deletion src/pages/solve/SAT.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ const SAT: NextPage = () => {
value.toString()
);

if (errors.length > 0) {
if (errors) {
setErrorString(errors.toString());
} else {
setErrorString("");
Expand Down

0 comments on commit f5833ba

Please sign in to comment.