* @param gql the GQL query - the parameters to the GQL are referenced by :1, :2, ...
*/
public PreparedGql prepare( String gql ) {
try {
GqlExtLexer lexer = new GqlExtLexer( new ANTLRStringStream( gql ));
GqlExtParser parser = new GqlExtParser( new CommonTokenStream( lexer ));
GqlExtParser.gqlext_return parserResult = parser.gqlext();
if (parser.getNumberOfSyntaxErrors() != 0) {
for (String err : parser.getErrors()) {
log.error("prepare(): " + err + " - in GQL: " + gql);
}
throw new RuntimeException( parser.getErrors().get(0));
}
CommonTree tree = (CommonTree) parserResult.getTree();
if (log.isDebugEnabled()) {
log.debug("prepare(): gql=" + gql + ", tree=" + tree.toStringTree());
}
PreparedGql.QueryType qt = PreparedGql.QueryType.valueOf( parser.getQueryType().name());
return new PreparedGql( ds, gql, qt, tree, parser.getTokenStream());
}
catch (RecognitionException e) {
log.error("prepare(): " + formatError( gql, e ), e);
throw new RuntimeException( "Cannot parse GQL: " + e.getMessage() + " in GQL: " + gql, e );