From 824571167017b4e201973ea845566c2838d5c050 Mon Sep 17 00:00:00 2001 From: Kevin Jones Date: Sun, 12 May 2024 16:53:17 +0100 Subject: [PATCH 1/2] Support USER/SYSTEM mode on SOSL --- CHANGELOG.md | 6 +++++- antlr/ApexParser.g4 | 20 ++++++++++++------- .../apexparser/SOSLParserTest.java | 16 +++++++++++++++ npm/src/__tests__/SOSLParserTest.ts | 18 +++++++++++++++++ 4 files changed, 52 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 24556ee..f0e847f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/antlr/ApexParser.g4 b/antlr/ApexParser.g4 index d4e6702..11dc476 100644 --- a/antlr/ApexParser.g4 +++ b/antlr/ApexParser.g4 @@ -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 ; diff --git a/jvm/src/test/java/io/github/apexdevtools/apexparser/SOSLParserTest.java b/jvm/src/test/java/io/github/apexdevtools/apexparser/SOSLParserTest.java index 7d47146..cc218a1 100644 --- a/jvm/src/test/java/io/github/apexdevtools/apexparser/SOSLParserTest.java +++ b/jvm/src/test/java/io/github/apexdevtools/apexparser/SOSLParserTest.java @@ -60,4 +60,20 @@ void testQuotesFailOnAltFormat() { assertNotNull(context); assertEquals(1, parserAndCounter.getValue().getNumErrors()); } + + @Test + void testWithUserModeQuery() { + Map.Entry 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 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()); + } } diff --git a/npm/src/__tests__/SOSLParserTest.ts b/npm/src/__tests__/SOSLParserTest.ts index 7746a8e..59f1721 100644 --- a/npm/src/__tests__/SOSLParserTest.ts +++ b/npm/src/__tests__/SOSLParserTest.ts @@ -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) +}) From d72c7fd33f85b1d1b905af72b0beb8ae722cf071 Mon Sep 17 00:00:00 2001 From: Kevin Jones Date: Sun, 12 May 2024 19:46:32 +0100 Subject: [PATCH 2/2] Bump to 4.1.0 --- README.md | 4 ++-- jvm/pom.xml | 15 ++++++++------- npm/package-lock.json | 4 ++-- npm/package.json | 2 +- 4 files changed, 13 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index e221cce..57e9802 100644 --- a/README.md +++ b/README.md @@ -48,12 +48,12 @@ Maven io.github.apex-dev-tools apex-parser - 4.0.0 + 4.1.0 NPM - "@apexdevtools/apex-parser": "^4.0.0" + "@apexdevtools/apex-parser": "^4.1.0" ## Building diff --git a/jvm/pom.xml b/jvm/pom.xml index 8dc50a9..065a492 100644 --- a/jvm/pom.xml +++ b/jvm/pom.xml @@ -1,10 +1,11 @@ - + 4.0.0 io.github.apex-dev-tools apex-parser - 4.0.0 + 4.1.0 jar apex-parser @@ -59,9 +60,9 @@ - org.antlr - antlr4-runtime - 4.9.1 + org.antlr + antlr4-runtime + 4.9.1 @@ -221,4 +222,4 @@ - + \ No newline at end of file diff --git a/npm/package-lock.json b/npm/package-lock.json index 6a08cd6..16e298a 100644 --- a/npm/package-lock.json +++ b/npm/package-lock.json @@ -1,12 +1,12 @@ { "name": "@apexdevtools/apex-parser", - "version": "4.0.0", + "version": "4.1.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@apexdevtools/apex-parser", - "version": "4.0.0", + "version": "4.1.0", "license": "BSD-3-Clause", "dependencies": { "antlr4ts": "0.5.0-alpha.4", diff --git a/npm/package.json b/npm/package.json index bdd9cea..39ddb88 100644 --- a/npm/package.json +++ b/npm/package.json @@ -1,6 +1,6 @@ { "name": "@apexdevtools/apex-parser", - "version": "4.0.0", + "version": "4.1.0", "author": "Apex Dev Tools Team (https://github.com/apex-dev-tools)", "bugs": "https://github.com/apex-dev-tools/apex-parser/issues", "description": "Javascript parser for Salesforce Apex Language",