Search in sources :

Example 1 with IriRefContext

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);
    }
}
Also used : PathPatternVisitor(com.inova8.pathql.processor.PathPatternVisitor) CommonTokenStream(org.antlr.v4.runtime.CommonTokenStream) PathElement(com.inova8.pathql.element.PathElement) PathPatternParser(com.inova8.pathql.pathPattern.PathPatternParser) IriRefValueElement(com.inova8.pathql.element.IriRefValueElement) PathPatternException(com.inova8.pathql.processor.PathPatternException) PathPatternLexer(com.inova8.pathql.pathPattern.PathPatternLexer) CharStream(org.antlr.v4.runtime.CharStream) PathPatternException(com.inova8.pathql.processor.PathPatternException) RecognitionException(org.antlr.v4.runtime.RecognitionException) IriRefContext(com.inova8.pathql.pathPattern.PathPatternParser.IriRefContext)

Example 2 with IriRefContext

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;
}
Also used : IriRefValueElement(com.inova8.pathql.element.IriRefValueElement) ScriptFailedException(com.inova8.intelligentgraph.exceptions.ScriptFailedException)

Aggregations

IriRefValueElement (com.inova8.pathql.element.IriRefValueElement)2 ScriptFailedException (com.inova8.intelligentgraph.exceptions.ScriptFailedException)1 PathElement (com.inova8.pathql.element.PathElement)1 PathPatternLexer (com.inova8.pathql.pathPattern.PathPatternLexer)1 PathPatternParser (com.inova8.pathql.pathPattern.PathPatternParser)1 IriRefContext (com.inova8.pathql.pathPattern.PathPatternParser.IriRefContext)1 PathPatternException (com.inova8.pathql.processor.PathPatternException)1 PathPatternVisitor (com.inova8.pathql.processor.PathPatternVisitor)1 CharStream (org.antlr.v4.runtime.CharStream)1 CommonTokenStream (org.antlr.v4.runtime.CommonTokenStream)1 RecognitionException (org.antlr.v4.runtime.RecognitionException)1