Search in sources :

Example 1 with VertexiumCypherSyntaxErrorException

use of org.vertexium.cypher.exceptions.VertexiumCypherSyntaxErrorException in project vertexium by visallo.

the class CypherAstParser method parse.

public CypherStatement parse(CypherCompilerContext ctx, String code) {
    CodePointCharStream input = CharStreams.fromString(code);
    CypherLexer lexer = new CypherLexer(input);
    CypherParser parser = new CypherParser(new CommonTokenStream(lexer));
    parser.setErrorHandler(new ParserErrorHandler(code));
    CypherParser.CypherContext tree = parser.cypher();
    if (!tree.getText().equals(code)) {
        throw new VertexiumCypherSyntaxErrorException("Parsing error, \"" + code.substring(tree.getText().length()) + "\"");
    }
    return new CypherCstToAstVisitor(ctx).visitCypher(tree);
}
Also used : CypherParser(org.vertexium.cypher.CypherParser) CypherLexer(org.vertexium.cypher.CypherLexer) VertexiumCypherSyntaxErrorException(org.vertexium.cypher.exceptions.VertexiumCypherSyntaxErrorException)

Example 2 with VertexiumCypherSyntaxErrorException

use of org.vertexium.cypher.exceptions.VertexiumCypherSyntaxErrorException in project vertexium by visallo.

the class CypherCstToAstVisitor method visitFunctionInvocation.

@Override
public CypherAstBase visitFunctionInvocation(CypherParser.FunctionInvocationContext ctx) {
    String functionName = visitFunctionName(ctx.functionName()).getValue();
    CypherFunction fn = compilerContext.getFunction(functionName);
    if (fn == null) {
        throw new VertexiumCypherSyntaxErrorException("UnknownFunction: Could not find function with name \"" + functionName + "\"");
    }
    boolean distinct = ctx.DISTINCT() != null;
    CypherListLiteral<CypherAstBase> argumentsList = visitExpressions(ctx.expression());
    CypherAstBase[] arguments = argumentsList.toArray(new CypherAstBase[argumentsList.size()]);
    fn.compile(compilerContext, arguments);
    return new CypherFunctionInvocation(functionName, distinct, arguments);
}
Also used : CypherFunction(org.vertexium.cypher.functions.CypherFunction) VertexiumCypherSyntaxErrorException(org.vertexium.cypher.exceptions.VertexiumCypherSyntaxErrorException)

Aggregations

VertexiumCypherSyntaxErrorException (org.vertexium.cypher.exceptions.VertexiumCypherSyntaxErrorException)2 CypherLexer (org.vertexium.cypher.CypherLexer)1 CypherParser (org.vertexium.cypher.CypherParser)1 CypherFunction (org.vertexium.cypher.functions.CypherFunction)1