class JexlASTHelper {

    public static ASTJexlScript parseJexlQuery(String query) throws ParseException {
        // Instantiate a parser and visitor
        Parser parser = new Parser(new StringReader(";"));
        
        // lowercase all 'and', 'or', and 'not' portions of the query.
        String caseFixQuery = AND_PATTERN.matcher(query).replaceAll(" and ");
        caseFixQuery = OR_PATTERN.matcher(caseFixQuery).replaceAll(" or ");
        caseFixQuery = NOT_PATTERN.matcher(caseFixQuery).replaceAll(" not ");
        
        if (caseFixQuery.contains(DOUBLE_BACKSLASH)) {
            try {
                return parseQueryWithBackslashes(query, parser);
            } catch (Exception e) {
                throw new ParseException("Unable to perform backslash substitution while parsing the query: " + e.getMessage());
            }
        } else {
            // Parse the original query
            try {
                return parser.parse(new StringReader(caseFixQuery), null);
            } catch (TokenMgrError e) {
                throw new ParseException(e.getMessage());
            }
        }
    }

    private  JexlASTHelper();

}