ABenassi87 / salesforce-soql-parser

Salesforce Soql Antlr Parser for Java

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Salesforce SOQL Parser

This is a java parser for SOQL (Salesforce Query Language) implemented with ANTLR 3. This parser was built following to the SOQL syntax definition provided by Salesforce.

There is a another implementation of the parser based on ANTLR 4 not yet released. The SOQL ANTLR 4 grammar can be seen here.

Usage

You can use the parser generated by ANTLR straight away, but the simplest way to parse and process queries is by using the SOQLParserHelper. With the SOQLParserHelper you can create a simpler object representation of the SOQL query.

public String printSelectClause(String soqlText)
{
    //Use the SOQLParserHelper to create a SOQLQuery object containing the SOQL query data
    SOQLQuery queryData = SOQLParserHelper.createSOQLData(soqlText);
        
    //Get the object representation of part of the SOQL query 
    SelectClause selectClause = queryData.getSelectClause();
        
    //Use the toSOQLText method of any part of the query to convert it back to text
    return selectClause.toSOQLText();
}

You can also use the SOQLParserHelper to obtain the ANTRL AST of a SOQL query.

SOQLCommonTree queryDataAST = SOQLParserHelper.createSOQLParserTree(soqlText);

To simplify query processing the SOQLQuery class accepts visitors. The easiest way to implement visitors for SOQLQuery is extending the SOQLDataBaseVisitor class.

Maven Configuration

Maven dependency

<dependency>
    <groupId>org.mule.tools</groupId>
    <artifactId>salesforce-soql-parser</artifactId>
    <version>2.0</version>
</dependency>

Maven repositories

<repositories>
    <repository>
        <id>mulesoft-releases</id>
        <name>MuleSoft Releases Repository</name>
        <url>http://repository.mulesoft.org/releases/</url>
        <layout>default</layout>
    </repository>
    <repository>
        <id>mulesoft-snapshots</id>
        <name>MuleSoft Snapshots Repository</name>
        <url>http://repository.mulesoft.org/snapshots/</url>
        <layout>default</layout>
    </repository>
</repositories>

License

Common Public Attribution License Version 1.0 (CPAL)

About

Salesforce Soql Antlr Parser for Java

License:Other


Languages

Language:Java 87.6%Language:GAP 12.4%