use of com.inova8.pathql.pathPattern.PathPatternParser.IriRefContext 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.PathPatternParser.IriRefContext in project com.inova8.intelligentgraph by peterjohnlawrence.
the class PathPatternVisitor method visitIriRef.
/**
* Visit iri ref.
*
* @param ctx the ctx
* @return the iri ref value element
*/
@Override
public IriRefValueElement visitIriRef(IriRefContext ctx) {
// iriRef : IRI_REF | qname | pname_ns ;
IriRefValueElement iriRefElement = new IriRefValueElement(this.repositoryContext);
if (ctx.qname() != null) {
iriRefElement.setIri(((IriRefValueElement) visit(ctx.qname())).getIri());
} else if (ctx.pname_ns() != null) {
iriRefElement.setIri(((IriRefValueElement) visit(ctx.pname_ns())).getIri());
} else if (ctx.IRI_REF() != null) {
String iri = ctx.IRI_REF().getText();
iri = iri.substring(1, iri.length() - 1);
iriRefElement.setIri(iri(iri));
} else {
throw new ScriptFailedException(String.format("Error identifying iriRef %s", ctx.getText()));
}
return iriRefElement;
}
Aggregations