0

Does Salesforce publish their SOQL and SOSL grammar? Do we have any link to download?

I need to use ANTLR for creating parser on the SOQL and SOSL grammar. Please can any one help on this.

1
  • 2
    I've downvoted this question because it shows no research effort. – Derek F Nov 5 '17 at 16:31
2

Salesforce used to publish the grammar in BNF (Backus-Naur Form), but have been using a less formal representation for a number of releases now.

It's hiding in the documentation, specifically SOQL SELECT Syntax

SELECT fieldList [subquery][...]
[TYPEOF typeOfField whenExpression[...] elseExpression END][...]
FROM objectType[,...]
[USING SCOPE filterScope]
[WHERE conditionExpression]
[WITH [DATA CATEGORY] filteringExpression]
[GROUP BY {fieldGroupByList|ROLLUP (fieldSubtotalGroupByList)|CUBE (fieldSubtotalGroupByList)}
[HAVING havingConditionExpression] ]
[ORDER BY fieldOrderByList {ASC|DESC} [NULLS {FIRST|LAST}] ]
[LIMIT numberOfRowsToReturn]
[OFFSET numberOfRowsToSkip]
[FOR {VIEW | REFERENCE}[,...] ]
[ UPDATE {TRACKING|VIEWSTAT}[,...] ]

and SOSL Syntax.

FIND {SearchQuery}
[ IN SearchGroup ]
[ RETURNING FieldSpec [[ toLabel(fields)] [convertCurrency(Amount)] [FORMAT()]] ]
[ WITH DivisionFilter ]
[ WITH DATA CATEGORY DataCategorySpec ]
[ WITH SNIPPET[(target_length=n)] ]
[ WITH NETWORK NetworkIdSpec ]
[ WITH PricebookId ]
[ WITH METADATA ]
[ LIMIT n ]

[ UPDATE [TRACKING], [VIEWSTAT] ]

They use notation described in Typographical Conventions Used in this Document.

It'd take some effort, but I'm sure you could convert those documentation pages into a BNF grammar.

Googling for your question turns up a few (albeit outdated) resources as well: http://blog.jeffdouglas.com/2009/09/23/syntax-rules-for-soql/

and https://resources.docs.salesforce.com/sfdc/pdf/apex_api.pdf?major=146 (with the BNF grammar for SOQL on page 66)

0
2

Mulesoft has published their antlr3 & antlr4 grammars. I was able to generate and run classes using the antlr4 grammar & so far, it seems to be complete.

1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.