Skip to content

Commit 6771ccd

Browse files
committed
Add SOSL Highlight And Spell Correction Clause Support
Update the SOSL grammar to recognize WITH HIGHLIGHT and WITH SPELL_CORRECTION, including optional boolean assignment for spell correction.
1 parent fab9a9e commit 6771ccd

14 files changed

Lines changed: 4508 additions & 4011 deletions

formatter/soql_test.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,28 @@ RETURNING Account(
343343
Name)
344344
WITH SYSTEM_MODE]`,
345345
},
346+
{
347+
`[FIND 'Acme' IN ALL FIELDS RETURNING Account(Name) WITH HIGHLIGHT]`,
348+
`[FIND 'Acme'
349+
IN ALL FIELDS
350+
RETURNING Account(
351+
Name)
352+
WITH HIGHLIGHT]`,
353+
},
354+
{
355+
`[FIND 'Acme' RETURNING Account(Name) WITH SPELL_CORRECTION]`,
356+
`[FIND 'Acme'
357+
RETURNING Account(
358+
Name)
359+
WITH SPELL_CORRECTION]`,
360+
},
361+
{
362+
`[FIND 'Acme' RETURNING Account(Name) WITH SPELL_CORRECTION = false]`,
363+
`[FIND 'Acme'
364+
RETURNING Account(
365+
Name)
366+
WITH SPELL_CORRECTION = false]`,
367+
},
346368
}
347369

348370
for _, tt := range tests {

formatter/visitors.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1665,6 +1665,12 @@ func (v *FormatVisitor) VisitSoslClauses(ctx *parser.SoslClausesContext) interfa
16651665
if i := ctx.WithSnippet(); i != nil {
16661666
clauses.WriteString(fmt.Sprintf("\n%s", v.visitRule(i)))
16671667
}
1668+
if i := ctx.WithHighlight(); i != nil {
1669+
clauses.WriteString(fmt.Sprintf("\n%s", v.visitRule(i)))
1670+
}
1671+
if i := ctx.WithSpellCorrection(); i != nil {
1672+
clauses.WriteString(fmt.Sprintf("\n%s", v.visitRule(i)))
1673+
}
16681674
if i := ctx.WithNetworkIn(); i != nil {
16691675
clauses.WriteString(fmt.Sprintf("\n%s", v.visitRule(i)))
16701676
}
@@ -1723,6 +1729,17 @@ func (v *FormatVisitor) VisitWithModeClause(ctx *parser.WithModeClauseContext) i
17231729
return "WITH SYSTEM_MODE"
17241730
}
17251731

1732+
func (v *FormatVisitor) VisitWithHighlight(_ *parser.WithHighlightContext) interface{} {
1733+
return "WITH HIGHLIGHT"
1734+
}
1735+
1736+
func (v *FormatVisitor) VisitWithSpellCorrection(ctx *parser.WithSpellCorrectionContext) interface{} {
1737+
if b := ctx.BooleanLiteral(); b != nil {
1738+
return fmt.Sprintf("WITH SPELL_CORRECTION = %s", strings.ToLower(b.GetText()))
1739+
}
1740+
return "WITH SPELL_CORRECTION"
1741+
}
1742+
17261743
func (v *FormatVisitor) VisitFieldSpecClauses(ctx *parser.FieldSpecClausesContext) interface{} {
17271744
var clauses strings.Builder
17281745
clauses.WriteString(fmt.Sprintf("(\n%s", indent(v.visitRule(ctx.FieldList()).(string))))

grammar/ApexLexer.g4

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,8 @@ METADATA : M E T A D A T A;
249249
PRICEBOOKID : P R I C E B O O K I D;
250250
NETWORK : N E T W O R K;
251251
SNIPPET : S N I P P E T;
252+
HIGHLIGHT : H I G H L I G H T;
253+
SPELL_CORRECTION : S P E L L '_' C O R R E C T I O N;
252254
TARGET_LENGTH : T A R G E T '_' L E N G T H;
253255
DIVISION : D I V I S I O N;
254256
RETURNING : R E T U R N I N G;

grammar/ApexParser.g4

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -842,6 +842,8 @@ soslClauses
842842
withDivisionAssign?
843843
withDataCategory?
844844
withSnippet?
845+
withHighlight?
846+
withSpellCorrection?
845847
withNetworkIn?
846848
withNetworkAssign?
847849
withPricebookIdAssign?
@@ -871,6 +873,14 @@ withSnippet
871873
: WITH SNIPPET (LPAREN TARGET_LENGTH ASSIGN IntegerLiteral RPAREN)?
872874
;
873875

876+
withHighlight
877+
: WITH HIGHLIGHT
878+
;
879+
880+
withSpellCorrection
881+
: WITH SPELL_CORRECTION (ASSIGN BooleanLiteral)?
882+
;
883+
874884
withNetworkIn
875885
: WITH NETWORK IN LPAREN networkList RPAREN
876886
;
@@ -1093,6 +1103,8 @@ id
10931103
| PRICEBOOKID
10941104
| NETWORK
10951105
| SNIPPET
1106+
| HIGHLIGHT
1107+
| SPELL_CORRECTION
10961108
| TARGET_LENGTH
10971109
| DIVISION
10981110
| RETURNING
@@ -1305,6 +1317,8 @@ anyId
13051317
| PRICEBOOKID
13061318
| NETWORK
13071319
| SNIPPET
1320+
| HIGHLIGHT
1321+
| SPELL_CORRECTION
13081322
| TARGET_LENGTH
13091323
| DIVISION
13101324
| RETURNING

parser/ApexLexer.interp

Lines changed: 7 additions & 1 deletion
Large diffs are not rendered by default.

parser/ApexLexer.tokens

Lines changed: 115 additions & 113 deletions
Original file line numberDiff line numberDiff line change
@@ -186,116 +186,118 @@ METADATA=185
186186
PRICEBOOKID=186
187187
NETWORK=187
188188
SNIPPET=188
189-
TARGET_LENGTH=189
190-
DIVISION=190
191-
RETURNING=191
192-
LISTVIEW=192
193-
FindLiteral=193
194-
FindLiteralAlt=194
195-
IntegerLiteral=195
196-
LongLiteral=196
197-
NumberLiteral=197
198-
BooleanLiteral=198
199-
StringLiteral=199
200-
NullLiteral=200
201-
LPAREN=201
202-
RPAREN=202
203-
LBRACE=203
204-
RBRACE=204
205-
LBRACK=205
206-
RBRACK=206
207-
SEMI=207
208-
COMMA=208
209-
DOT=209
210-
ASSIGN=210
211-
GT=211
212-
LT=212
213-
BANG=213
214-
TILDE=214
215-
QUESTIONDOT=215
216-
QUESTION=216
217-
COLON=217
218-
EQUAL=218
219-
TRIPLEEQUAL=219
220-
NOTEQUAL=220
221-
LESSANDGREATER=221
222-
TRIPLENOTEQUAL=222
223-
AND=223
224-
OR=224
225-
COAL=225
226-
INC=226
227-
DEC=227
228-
ADD=228
229-
SUB=229
230-
MUL=230
231-
DIV=231
232-
BITAND=232
233-
BITOR=233
234-
CARET=234
235-
MOD=235
236-
MAPTO=236
237-
ADD_ASSIGN=237
238-
SUB_ASSIGN=238
239-
MUL_ASSIGN=239
240-
DIV_ASSIGN=240
241-
AND_ASSIGN=241
242-
OR_ASSIGN=242
243-
XOR_ASSIGN=243
244-
MOD_ASSIGN=244
245-
LSHIFT_ASSIGN=245
246-
RSHIFT_ASSIGN=246
247-
URSHIFT_ASSIGN=247
248-
ATSIGN=248
249-
Identifier=249
250-
DOC_COMMENT=250
251-
COMMENT=251
252-
LINE_COMMENT=252
253-
WS=253
254-
'('=201
255-
')'=202
256-
'{'=203
257-
'}'=204
258-
'['=205
259-
']'=206
260-
';'=207
261-
','=208
262-
'.'=209
263-
'='=210
264-
'>'=211
265-
'<'=212
266-
'!'=213
267-
'~'=214
268-
'?.'=215
269-
'?'=216
270-
':'=217
271-
'=='=218
272-
'==='=219
273-
'!='=220
274-
'<>'=221
275-
'!=='=222
276-
'&&'=223
277-
'||'=224
278-
'??'=225
279-
'++'=226
280-
'--'=227
281-
'+'=228
282-
'-'=229
283-
'*'=230
284-
'/'=231
285-
'&'=232
286-
'|'=233
287-
'^'=234
288-
'%'=235
289-
'=>'=236
290-
'+='=237
291-
'-='=238
292-
'*='=239
293-
'/='=240
294-
'&='=241
295-
'|='=242
296-
'^='=243
297-
'%='=244
298-
'<<='=245
299-
'>>='=246
300-
'>>>='=247
301-
'@'=248
189+
HIGHLIGHT=189
190+
SPELL_CORRECTION=190
191+
TARGET_LENGTH=191
192+
DIVISION=192
193+
RETURNING=193
194+
LISTVIEW=194
195+
FindLiteral=195
196+
FindLiteralAlt=196
197+
IntegerLiteral=197
198+
LongLiteral=198
199+
NumberLiteral=199
200+
BooleanLiteral=200
201+
StringLiteral=201
202+
NullLiteral=202
203+
LPAREN=203
204+
RPAREN=204
205+
LBRACE=205
206+
RBRACE=206
207+
LBRACK=207
208+
RBRACK=208
209+
SEMI=209
210+
COMMA=210
211+
DOT=211
212+
ASSIGN=212
213+
GT=213
214+
LT=214
215+
BANG=215
216+
TILDE=216
217+
QUESTIONDOT=217
218+
QUESTION=218
219+
COLON=219
220+
EQUAL=220
221+
TRIPLEEQUAL=221
222+
NOTEQUAL=222
223+
LESSANDGREATER=223
224+
TRIPLENOTEQUAL=224
225+
AND=225
226+
OR=226
227+
COAL=227
228+
INC=228
229+
DEC=229
230+
ADD=230
231+
SUB=231
232+
MUL=232
233+
DIV=233
234+
BITAND=234
235+
BITOR=235
236+
CARET=236
237+
MOD=237
238+
MAPTO=238
239+
ADD_ASSIGN=239
240+
SUB_ASSIGN=240
241+
MUL_ASSIGN=241
242+
DIV_ASSIGN=242
243+
AND_ASSIGN=243
244+
OR_ASSIGN=244
245+
XOR_ASSIGN=245
246+
MOD_ASSIGN=246
247+
LSHIFT_ASSIGN=247
248+
RSHIFT_ASSIGN=248
249+
URSHIFT_ASSIGN=249
250+
ATSIGN=250
251+
Identifier=251
252+
DOC_COMMENT=252
253+
COMMENT=253
254+
LINE_COMMENT=254
255+
WS=255
256+
'('=203
257+
')'=204
258+
'{'=205
259+
'}'=206
260+
'['=207
261+
']'=208
262+
';'=209
263+
','=210
264+
'.'=211
265+
'='=212
266+
'>'=213
267+
'<'=214
268+
'!'=215
269+
'~'=216
270+
'?.'=217
271+
'?'=218
272+
':'=219
273+
'=='=220
274+
'==='=221
275+
'!='=222
276+
'<>'=223
277+
'!=='=224
278+
'&&'=225
279+
'||'=226
280+
'??'=227
281+
'++'=228
282+
'--'=229
283+
'+'=230
284+
'-'=231
285+
'*'=232
286+
'/'=233
287+
'&'=234
288+
'|'=235
289+
'^'=236
290+
'%'=237
291+
'=>'=238
292+
'+='=239
293+
'-='=240
294+
'*='=241
295+
'/='=242
296+
'&='=243
297+
'|='=244
298+
'^='=245
299+
'%='=246
300+
'<<='=247
301+
'>>='=248
302+
'>>>='=249
303+
'@'=250

parser/ApexParser.interp

Lines changed: 7 additions & 1 deletion
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)