diff --git a/packages/core/src/stores/webdaql/WebdaQLParser.g4 b/packages/core/src/stores/webdaql/WebdaQLParser.g4 index 9def96985..d7d08ef9e 100644 --- a/packages/core/src/stores/webdaql/WebdaQLParser.g4 +++ b/packages/core/src/stores/webdaql/WebdaQLParser.g4 @@ -17,6 +17,9 @@ expression identifier LIKE stringLiteral #likeExpression | identifier IN setExpression #inExpression | identifier CONTAINS stringLiteral #containsExpression + // IS NULL / IS NOT NULL + | identifier IS NULL #isNullExpression + | identifier IS NOT NULL #isNotNullExpression // Comparison operations | identifier (EQUAL | NOT_EQUAL | GREATER_OR_EQUAL | LESS_OR_EQUAL | LESS | GREATER) values #binaryComparisonExpression // Logic operations diff --git a/packages/core/src/stores/webdaql/query.ts b/packages/core/src/stores/webdaql/query.ts index 655a0420b..9f9873b8e 100644 --- a/packages/core/src/stores/webdaql/query.ts +++ b/packages/core/src/stores/webdaql/query.ts @@ -233,6 +233,22 @@ export namespace WebdaQL { return new ComparisonExpression("CONTAINS", left.text, value); } + /** + * IS NULL expression + */ + visitIsNullExpression(ctx: any) { + const left = ctx.getChild(0); + return new ComparisonExpression("IS NULL", left.text, null); + } + + /** + * IS NOT NULL expression + */ + visitIsNotNullExpression(ctx: any) { + const left = ctx.getChild(0); + return new ComparisonExpression("IS NOT NULL", left.text, null); + } + /** * Get the OrExpression, regrouping all the parameters * @@ -319,7 +335,7 @@ export namespace WebdaQL { abstract toString(depth?: number): string; } - export type ComparisonOperator = "=" | "<=" | ">=" | "<" | ">" | "!=" | "LIKE" | "IN" | "CONTAINS"; + export type ComparisonOperator = "=" | "<=" | ">=" | "<" | ">" | "!=" | "LIKE" | "IN" | "CONTAINS" | "IS NULL" | "IS NOT NULL"; /** * Comparison expression */ @@ -430,6 +446,10 @@ export namespace WebdaQL { return left.includes(this.value); } return false; + case "IS NOT NULL": + return left !== null && left !== undefined; + case "IS NULL": + return left === null || left === undefined; } }