use of com.inova8.pathql.processor.PathErrorListener 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.processor.PathErrorListener in project com.inova8.intelligentgraph by peterjohnlawrence.
the class PathPatternTests method test_11.
/**
* Test 11.
*/
@Test
@Order(11)
void test_11() {
try {
String expression = ":Location@:appearsOn[eq id:Calc2Graph2]#";
CharStream input = CharStreams.fromString(expression);
PathPatternLexer lexer = new PathPatternLexer(input);
PathErrorListener errorListener = new PathErrorListener(expression);
lexer.removeErrorListeners();
lexer.addErrorListener(errorListener);
CommonTokenStream tokens = new CommonTokenStream(lexer);
PathPatternParser parser = new PathPatternParser(tokens);
parser.removeErrorListeners();
parser.addErrorListener(errorListener);
PathPatternContext pathPatternTree = parser.pathPattern();
PathPatternVisitor pathPatternVisitor = new PathPatternVisitor(repositoryContext);
PathElement element = pathPatternVisitor.visit(pathPatternTree);
assertEquals("<http://default/Location>@<http://default/appearsOn>[eq <http://id/Calc2Graph2> ]#", element.toString());
} catch (Exception e) {
assertEquals("<http://default/Location>@<http://default/appearsOn>[eq <http://id/Calc2Graph2> ;]#", "");
}
}
use of com.inova8.pathql.processor.PathErrorListener in project com.inova8.intelligentgraph by peterjohnlawrence.
the class PathPatternQueryExpressionTests method test_11.
/**
* Test 11.
*/
@Test
@Order(11)
void test_11() {
try {
String expression = ":Location@:appearsOn[eq id:Calc2Graph2]#";
CharStream input = CharStreams.fromString(expression);
PathPatternLexer lexer = new PathPatternLexer(input);
PathErrorListener errorListener = new PathErrorListener(expression);
lexer.removeErrorListeners();
lexer.addErrorListener(errorListener);
CommonTokenStream tokens = new CommonTokenStream(lexer);
PathPatternParser parser = new PathPatternParser(tokens);
parser.removeErrorListeners();
parser.addErrorListener(errorListener);
PathPatternContext pathPatternTree = parser.pathPattern();
PathPatternVisitor pathPatternVisitor = new PathPatternVisitor(repositoryContext);
PathElement element = pathPatternVisitor.visit(pathPatternTree);
// Query.assertEqualsWOSpaces
assertEquals("Join\r\n" + " Join\r\n" + " StatementPattern\r\n" + " Variable (name=rnull)\r\n" + " Variable (name=subjectnull, value=http://www.w3.org/1999/02/22-rdf-syntax-ns#subject)\r\n" + " Variable (name=nnull)\r\n" + " StatementPattern\r\n" + " Variable (name=rnull)\r\n" + " Variable (name=propertynull, value=http://www.w3.org/1999/02/22-rdf-syntax-ns#predicate)\r\n" + " Variable (name=p_nnull_nnull, value=http://default/appearsOn)\r\n" + " StatementPattern\r\n" + " Variable (name=rnull)\r\n" + " Variable (name=objectnull, value=http://www.w3.org/1999/02/22-rdf-syntax-ns#object)\r\n" + " Variable (name=nnull, value=http://id/Calc2Graph2)\r\n" + "", element.pathPatternQuery().toString());
} catch (Exception e) {
Query.assertEqualsWOSpaces("<http://default/Location>@<http://default/appearsOn>[eq <http://id/Calc2Graph2> ;]#", "");
}
}
Aggregations