use of com.inova8.pathql.pathPattern.PathPatternLexer in project com.inova8.intelligentgraph by peterjohnlawrence.
the class PathPatternQueryExpressionTests 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();
PathPatternVisitor pathPatternVisitor = new PathPatternVisitor(repositoryContext);
PathElement element = pathPatternVisitor.visit(pathPatternTree);
element.indexVisitor(null, 0, null);
element.setIterations(Iterations.create(element));
// element.setPathBindings(PathBindings.create(element));
return element;
}
use of com.inova8.pathql.pathPattern.PathPatternLexer in project com.inova8.intelligentgraph by peterjohnlawrence.
the class PathPatternTests 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();
PathPatternVisitor pathPatternVisitor = new PathPatternVisitor(repositoryContext);
PathElement element = pathPatternVisitor.visit(pathPatternTree);
return element;
}
use of com.inova8.pathql.pathPattern.PathPatternLexer in project com.inova8.intelligentgraph by peterjohnlawrence.
the class PathParser method parseIriRef.
/**
* Parses the iri ref.
*
* @param repositoryContext the repository context
* @param uriPattern the uri pattern
* @return the iri ref value element
* @throws RecognitionException the recognition exception
* @throws PathPatternException the path pattern exception
*/
public static IriRefValueElement parseIriRef(RepositoryContext repositoryContext, String uriPattern) throws RecognitionException, PathPatternException {
try {
pathPatternVisitor = new PathPatternVisitor(repositoryContext);
CharStream input = CharStreams.fromString(uriPattern);
PathPatternLexer lexer = new PathPatternLexer(input);
CommonTokenStream tokens = new CommonTokenStream(lexer);
PathPatternParser parser = new PathPatternParser(tokens);
IriRefContext pathPatternTree = parser.iriRef();
PathElement iriRefValueElement = pathPatternVisitor.visit(pathPatternTree);
return (IriRefValueElement) iriRefValueElement;
} catch (Exception qe) {
throw new PathPatternException(qe.getMessage(), null);
}
}
use of com.inova8.pathql.pathPattern.PathPatternLexer in project com.inova8.intelligentgraph by peterjohnlawrence.
the class PathParser method parsePredicate.
/**
* Parses the predicate.
*
* @param repositoryContext the repository context
* @param uriPattern the uri pattern
* @return the predicate element
* @throws RecognitionException the recognition exception
* @throws PathPatternException the path pattern exception
*/
public static PredicateElement parsePredicate(RepositoryContext repositoryContext, String uriPattern) throws RecognitionException, PathPatternException {
pathPatternVisitor = new PathPatternVisitor(repositoryContext);
CharStream input = CharStreams.fromString(uriPattern);
PathPatternLexer lexer = new PathPatternLexer(input);
CommonTokenStream tokens = new CommonTokenStream(lexer);
PathPatternParser parser = new PathPatternParser(tokens);
PathEltOrInverseContext pathPatternTree = parser.pathEltOrInverse();
PathElement iriRefValueElement = pathPatternVisitor.visit(pathPatternTree);
return (PredicateElement) iriRefValueElement;
}
use of com.inova8.pathql.pathPattern.PathPatternLexer 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;
}
Aggregations