class Query {

    public static Sparql11Parser getParser(String query) {
        Sparql11Lexer lexer = new Sparql11Lexer(new CaseInsensitiveInputStream(query));
        CommonTokenStream tokens = new CommonTokenStream(lexer);
        Sparql11Parser parser = new Sparql11Parser(tokens);
        parser.addErrorListener(new BaseErrorListener() {
            @Override
            public void syntaxError(Recognizer<?, ?> recognizer, Object offendingSymbol, int line,
                                    int charPositionInLine, String msg, RecognitionException ex) {
                throw new MalformedQueryException("Failed to parse at line " + line + " due to " + msg, ex);
            }
        });
        return parser;
    }

}