Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# apex-parser - Changelog

## Unreleased

- Fix the `dataCategoryName` grammar rule so parenthesized SOQL data category lists close with `RPAREN`; previously, valid multi-category `WITH DATA CATEGORY` filters failed to parse.

## 5.1.0 - 2026-07-03

- Allow functions in `GROUP BY` clause of SOQL queries
Expand Down
2 changes: 1 addition & 1 deletion antlr/BaseApexParser.g4
Original file line number Diff line number Diff line change
Expand Up @@ -762,7 +762,7 @@ dataCategorySelection

dataCategoryName
: soqlId
| LPAREN soqlId (COMMA soqlId)* LPAREN;
| LPAREN soqlId (COMMA soqlId)* RPAREN;

filteringSelector
: AT | ABOVE | BELOW | ABOVE_OR_BELOW;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,36 @@ void testSOQL() {
assertEquals(0, parserAndCounter.getValue().getNumErrors());
}

@Test
void testSOQLWhereWithSingleDataCategoryFilter() {
Map.Entry<ApexParser, SyntaxErrorCounter> parserAndCounter = createParser(
"SELECT Title FROM KnowledgeArticleVersion WHERE PublishStatus='online' WITH DATA CATEGORY Geography__c ABOVE usa__c"
);
ApexParser.QueryContext context = parserAndCounter.getKey().query();
assertNotNull(context);
assertEquals(0, parserAndCounter.getValue().getNumErrors());
}

@Test
void testSOQLWhereWithDataCategoryListFilter() {
Map.Entry<ApexParser, SyntaxErrorCounter> parserAndCounter = createParser(
"SELECT Title FROM Question WHERE LastReplyDate > 2005-10-08T01:02:03Z WITH DATA CATEGORY Geography__c AT (usa__c, uk__c)"
);
ApexParser.QueryContext context = parserAndCounter.getKey().query();
assertNotNull(context);
assertEquals(0, parserAndCounter.getValue().getNumErrors());
}

@Test
void testSOQLWhereWithMultipleDataCategoryFilters() {
Map.Entry<ApexParser, SyntaxErrorCounter> parserAndCounter = createParser(
"SELECT UrlName FROM KnowledgeArticleVersion WHERE PublishStatus='draft' WITH DATA CATEGORY Geography__c AT usa__c AND Product__c ABOVE_OR_BELOW mobile_phones__c"
);
ApexParser.QueryContext context = parserAndCounter.getKey().query();
assertNotNull(context);
assertEquals(0, parserAndCounter.getValue().getNumErrors());
}

@Test
void testCurrencyLiteral() {
Map.Entry<ApexParser, SyntaxErrorCounter> parserAndCounter = createParser(
Expand Down
30 changes: 30 additions & 0 deletions npm/test/SOQLParserTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,36 @@ test("SOQL Query", () => {
expect(errorCounter.getNumErrors()).toEqual(0);
});

test("SOQL Where with single data category filter", () => {
const [parser, errorCounter] = createParser(
"SELECT Title FROM KnowledgeArticleVersion WHERE PublishStatus='online' WITH DATA CATEGORY Geography__c ABOVE usa__c"
);
const context = parser.query();

expect(context).toBeInstanceOf(QueryContext);
expect(errorCounter.getNumErrors()).toEqual(0);
});

test("SOQL Where with data category list filter", () => {
const [parser, errorCounter] = createParser(
"SELECT Title FROM Question WHERE LastReplyDate > 2005-10-08T01:02:03Z WITH DATA CATEGORY Geography__c AT (usa__c, uk__c)"
);
const context = parser.query();

expect(context).toBeInstanceOf(QueryContext);
expect(errorCounter.getNumErrors()).toEqual(0);
});

test("SOQL Where with multiple data category filters", () => {
const [parser, errorCounter] = createParser(
"SELECT UrlName FROM KnowledgeArticleVersion WHERE PublishStatus='draft' WITH DATA CATEGORY Geography__c AT usa__c AND Product__c ABOVE_OR_BELOW mobile_phones__c"
);
const context = parser.query();

expect(context).toBeInstanceOf(QueryContext);
expect(errorCounter.getNumErrors()).toEqual(0);
});

test("SOQL Query Using Field function", () => {
const [parser, errorCounter] = createParser(
"Select Fields(All) from Account"
Expand Down