Skip to content

Commit

Permalink
Merge pull request #43 from apex-dev-tools/42-sosl-find-clause-with-u…
Browse files Browse the repository at this point in the history
…ser_mode-or-system_mode

Support USER/SYSTEM mode on SOSL
  • Loading branch information
pwrightcertinia authored May 14, 2024
2 parents 2f9160c + d72c7fd commit 35b8feb
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 20 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# apex-parser - Changelog

## 4.0.0 - 2023-03-28
## 4.1.0 - 2024-05-12

- Allow WITH USER_MODE or SYSTEM_MODE on SOSL queries

## 4.0.0 - 2024-03-28

- Correct trigger body parsing to allow member declarations
- Add support for TYPEOF in SOQL subqueries
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,12 @@ Maven
<dependency>
<groupId>io.github.apex-dev-tools</groupId>
<artifactId>apex-parser</artifactId>
<version>4.0.0</version>
<version>4.1.0</version>
</dependency>

NPM

"@apexdevtools/apex-parser": "^4.0.0"
"@apexdevtools/apex-parser": "^4.1.0"

## Building

Expand Down
20 changes: 13 additions & 7 deletions antlr/ApexParser.g4
Original file line number Diff line number Diff line change
Expand Up @@ -826,17 +826,23 @@ soslLiteralAlt
soslClauses
: (IN searchGroup)?
(RETURNING fieldSpecList)?
(WITH DIVISION ASSIGN StringLiteral)?
(WITH DATA CATEGORY filteringExpression)?
(WITH SNIPPET (LPAREN TARGET_LENGTH ASSIGN IntegerLiteral RPAREN)? )?
(WITH NETWORK IN LPAREN networkList RPAREN)?
(WITH NETWORK ASSIGN StringLiteral)?
(WITH PRICEBOOKID ASSIGN StringLiteral)?
(WITH METADATA ASSIGN StringLiteral)?
soslWithClause*
limitClause?
(UPDATE updateList)?
;

soslWithClause
: WITH DIVISION ASSIGN StringLiteral
| WITH DATA CATEGORY filteringExpression
| WITH SNIPPET (LPAREN TARGET_LENGTH ASSIGN IntegerLiteral RPAREN)?
| WITH NETWORK IN LPAREN networkList RPAREN
| WITH NETWORK ASSIGN StringLiteral
| WITH PRICEBOOKID ASSIGN StringLiteral
| WITH METADATA ASSIGN StringLiteral
| WITH USER_MODE
| WITH SYSTEM_MODE
;

searchGroup
: (ALL|EMAIL|NAME|PHONE|SIDEBAR) FIELDS
;
Expand Down
15 changes: 8 additions & 7 deletions jvm/pom.xml
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>io.github.apex-dev-tools</groupId>
<artifactId>apex-parser</artifactId>
<version>4.0.0</version>
<version>4.1.0</version>
<packaging>jar</packaging>

<name>apex-parser</name>
Expand Down Expand Up @@ -59,9 +60,9 @@

<dependencies>
<dependency>
<groupId>org.antlr</groupId>
<artifactId>antlr4-runtime</artifactId>
<version>4.9.1</version>
<groupId>org.antlr</groupId>
<artifactId>antlr4-runtime</artifactId>
<version>4.9.1</version>
</dependency>

<dependency>
Expand Down Expand Up @@ -221,4 +222,4 @@

</plugins>
</build>
</project>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,20 @@ void testQuotesFailOnAltFormat() {
assertNotNull(context);
assertEquals(1, parserAndCounter.getValue().getNumErrors());
}

@Test
void testWithUserModeQuery() {
Map.Entry<ApexParser, SyntaxErrorCounter> parserAndCounter = createParser("[Find 'something' RETURNING Account WITH USER_MODE WITH METADATA='Labels']");
ApexParser.SoslLiteralContext context = parserAndCounter.getKey().soslLiteral();
assertNotNull(context);
assertEquals(0, parserAndCounter.getValue().getNumErrors());
}

@Test
void testWithSystemModeQuery() {
Map.Entry<ApexParser, SyntaxErrorCounter> parserAndCounter = createParser("[Find 'something' RETURNING Account WITH METADATA='Labels' WITH SYSTEM_MODE]");
ApexParser.SoslLiteralContext context = parserAndCounter.getKey().soslLiteral();
assertNotNull(context);
assertEquals(0, parserAndCounter.getValue().getNumErrors());
}
}
4 changes: 2 additions & 2 deletions npm/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion npm/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@apexdevtools/apex-parser",
"version": "4.0.0",
"version": "4.1.0",
"author": "Apex Dev Tools Team <[email protected]> (https://github.com/apex-dev-tools)",
"bugs": "https://github.com/apex-dev-tools/apex-parser/issues",
"description": "Javascript parser for Salesforce Apex Language",
Expand Down
18 changes: 18 additions & 0 deletions npm/src/__tests__/SOSLParserTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,21 @@ test('testQuotesFailOnAltFormat', () => {
expect(context).toBeInstanceOf(SoslLiteralAltContext)
expect(errorCounter.getNumErrors()).toEqual(1)
})

test('testWithUserModeQuery', () => {
const [parser, errorCounter] = createParser("[Find 'something' RETURNING Account WITH USER_MODE WITH METADATA='Labels']")

const context = parser.soslLiteralAlt()

expect(context).toBeInstanceOf(SoslLiteralAltContext)
expect(errorCounter.getNumErrors()).toEqual(1)
})

test('testWithSystemModeQuery', () => {
const [parser, errorCounter] = createParser("[Find 'something' RETURNING Account WITH METADATA='Labels' WITH SYSTEM_MODE]")

const context = parser.soslLiteralAlt()

expect(context).toBeInstanceOf(SoslLiteralAltContext)
expect(errorCounter.getNumErrors()).toEqual(1)
})

0 comments on commit 35b8feb

Please sign in to comment.