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;
}
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;
}
Aggregations