Search in sources :

Example 1 with QueryStringContext

use of com.inova8.pathql.pathPattern.PathPatternParser.QueryStringContext in project com.inova8.intelligentgraph by peterjohnlawrence.

the class PathParser method pathPatternParser.

/**
 * Path pattern parser.
 *
 * @param pathPattern the path pattern
 * @param pathPatternVisitor the path pattern visitor
 * @return the path element
 * @throws RecognitionException the recognition exception
 * @throws PathPatternException the path pattern exception
 */
private static PathElement pathPatternParser(String pathPattern, PathPatternVisitor pathPatternVisitor) throws RecognitionException, PathPatternException {
    PathErrorListener errorListener = new PathErrorListener(pathPattern);
    CharStream input = CharStreams.fromString(pathPattern);
    PathPatternLexer lexer = new PathPatternLexer(input);
    lexer.removeErrorListeners();
    lexer.addErrorListener(errorListener);
    CommonTokenStream tokens = new CommonTokenStream(lexer);
    PathPatternParser parser = new PathPatternParser(tokens);
    parser.removeErrorListeners();
    parser.addErrorListener(errorListener);
    QueryStringContext queryStringTree = parser.queryString();
    PathElement pathElement = pathPatternVisitor.visit(queryStringTree);
    if (errorListener.toString() != null) {
        if (parser.getNumberOfSyntaxErrors() == 0) {
            // Lexer only error
            throw new PathPatternException(errorListener.toString(), ErrorCode.LEXER);
        } else {
            // Parser error
            throw new PathPatternException(errorListener.toString(), ErrorCode.PARSER);
        }
    }
    pathElement.setPathPattern(pathPattern);
    pathElement.indexVisitor(null, 0, null);
    pathElement.setIterations(Iterations.create(pathElement));
    // pathElement.setPathBindings(PathBindings.create(pathElement));
    return pathElement;
}
Also used : CommonTokenStream(org.antlr.v4.runtime.CommonTokenStream) QueryStringContext(com.inova8.pathql.pathPattern.PathPatternParser.QueryStringContext) PathElement(com.inova8.pathql.element.PathElement) PathPatternParser(com.inova8.pathql.pathPattern.PathPatternParser) PathPatternException(com.inova8.pathql.processor.PathPatternException) PathPatternLexer(com.inova8.pathql.pathPattern.PathPatternLexer) PathErrorListener(com.inova8.pathql.processor.PathErrorListener) CharStream(org.antlr.v4.runtime.CharStream)

Example 2 with QueryStringContext

use of com.inova8.pathql.pathPattern.PathPatternParser.QueryStringContext in project com.inova8.intelligentgraph by peterjohnlawrence.

the class QueryStringParserTests method prepareElement.

/**
 * Prepare element.
 *
 * @param input the input
 * @return the path element
 * @throws RecognitionException the recognition exception
 */
private PathElement prepareElement(CharStream input) throws RecognitionException {
    PathPatternLexer lexer = new PathPatternLexer(input);
    CommonTokenStream tokens = new CommonTokenStream(lexer);
    PathPatternParser parser = new PathPatternParser(tokens);
    // PathPatternContext pathPatternTree = parser.pathPattern();
    QueryStringContext queryStringTree = parser.queryString();
    PathPatternVisitor pathPatternVisitor = new PathPatternVisitor(repositoryContext);
    PathElement element = pathPatternVisitor.visit(queryStringTree);
    return element;
}
Also used : PathPatternVisitor(com.inova8.pathql.processor.PathPatternVisitor) CommonTokenStream(org.antlr.v4.runtime.CommonTokenStream) QueryStringContext(com.inova8.pathql.pathPattern.PathPatternParser.QueryStringContext) PathElement(com.inova8.pathql.element.PathElement) PathPatternParser(com.inova8.pathql.pathPattern.PathPatternParser) PathPatternLexer(com.inova8.pathql.pathPattern.PathPatternLexer)

Aggregations

PathElement (com.inova8.pathql.element.PathElement)2 PathPatternLexer (com.inova8.pathql.pathPattern.PathPatternLexer)2 PathPatternParser (com.inova8.pathql.pathPattern.PathPatternParser)2 QueryStringContext (com.inova8.pathql.pathPattern.PathPatternParser.QueryStringContext)2 CommonTokenStream (org.antlr.v4.runtime.CommonTokenStream)2 PathErrorListener (com.inova8.pathql.processor.PathErrorListener)1 PathPatternException (com.inova8.pathql.processor.PathPatternException)1 PathPatternVisitor (com.inova8.pathql.processor.PathPatternVisitor)1 CharStream (org.antlr.v4.runtime.CharStream)1