Search in sources :

Example 1 with DerefSteps

use of org.opendaylight.yangtools.yang.model.api.PathExpression.DerefSteps in project yangtools by opendaylight.

the class PathExpressionParserTest method testDerefPath.

@Test
public void testDerefPath() {
    // deref() is not valid as per RFC7950, but we tolarate it.
    final PathExpression deref = parser.parseExpression(ctx, "deref(../id)/../type");
    final Steps steps = deref.getSteps();
    assertThat(steps, isA(DerefSteps.class));
    final DerefSteps derefSteps = (DerefSteps) steps;
    assertEquals(YangLocationPath.relative(YangXPathAxis.PARENT.asStep(), YangXPathAxis.CHILD.asStep(UnresolvedQName.unqualified("type"))), derefSteps.getRelativePath());
    assertEquals(YangLocationPath.relative(YangXPathAxis.PARENT.asStep(), YangXPathAxis.CHILD.asStep(UnresolvedQName.unqualified("id"))), derefSteps.getDerefArgument());
}
Also used : Steps(org.opendaylight.yangtools.yang.model.api.PathExpression.Steps) DerefSteps(org.opendaylight.yangtools.yang.model.api.PathExpression.DerefSteps) LocationPathSteps(org.opendaylight.yangtools.yang.model.api.PathExpression.LocationPathSteps) PathExpression(org.opendaylight.yangtools.yang.model.api.PathExpression) DerefSteps(org.opendaylight.yangtools.yang.model.api.PathExpression.DerefSteps) Test(org.junit.Test)

Example 2 with DerefSteps

use of org.opendaylight.yangtools.yang.model.api.PathExpression.DerefSteps in project yangtools by opendaylight.

the class PathExpressionParser method parseExpression.

PathExpression parseExpression(final StmtContext<?, ?, ?> ctx, final String pathArg) {
    final LeafRefPathLexer lexer = new LeafRefPathLexer(CharStreams.fromString(pathArg));
    final LeafRefPathParser parser = new LeafRefPathParser(new CommonTokenStream(lexer));
    final Path_argContext path = SourceExceptionParser.parse(lexer, parser, parser::path_arg, ctx.sourceReference());
    final ParseTree childPath = path.getChild(0);
    final Steps steps;
    if (childPath instanceof Path_strContext) {
        steps = new LocationPathSteps(parsePathStr(ctx, pathArg, (Path_strContext) childPath));
    } else if (childPath instanceof Deref_exprContext) {
        final Deref_exprContext deref = (Deref_exprContext) childPath;
        steps = new DerefSteps(parseRelative(ctx, pathArg, getChild(deref, 0, Deref_function_invocationContext.class).getChild(Relative_pathContext.class, 0)), parseRelative(ctx, pathArg, getChild(deref, deref.getChildCount() - 1, Relative_pathContext.class)));
    } else {
        throw new IllegalStateException("Unsupported child " + childPath);
    }
    return new ParsedPathExpression(steps, pathArg);
}
Also used : LocationPathSteps(org.opendaylight.yangtools.yang.model.api.PathExpression.LocationPathSteps) Steps(org.opendaylight.yangtools.yang.model.api.PathExpression.Steps) DerefSteps(org.opendaylight.yangtools.yang.model.api.PathExpression.DerefSteps) Path_strContext(org.opendaylight.yangtools.yang.parser.antlr.LeafRefPathParser.Path_strContext) CommonTokenStream(org.antlr.v4.runtime.CommonTokenStream) LocationPathSteps(org.opendaylight.yangtools.yang.model.api.PathExpression.LocationPathSteps) DerefSteps(org.opendaylight.yangtools.yang.model.api.PathExpression.DerefSteps) Deref_function_invocationContext(org.opendaylight.yangtools.yang.parser.antlr.LeafRefPathParser.Deref_function_invocationContext) Path_argContext(org.opendaylight.yangtools.yang.parser.antlr.LeafRefPathParser.Path_argContext) LeafRefPathLexer(org.opendaylight.yangtools.yang.parser.antlr.LeafRefPathLexer) LeafRefPathParser(org.opendaylight.yangtools.yang.parser.antlr.LeafRefPathParser) Deref_exprContext(org.opendaylight.yangtools.yang.parser.antlr.LeafRefPathParser.Deref_exprContext) ParseTree(org.antlr.v4.runtime.tree.ParseTree)

Aggregations

DerefSteps (org.opendaylight.yangtools.yang.model.api.PathExpression.DerefSteps)2 LocationPathSteps (org.opendaylight.yangtools.yang.model.api.PathExpression.LocationPathSteps)2 Steps (org.opendaylight.yangtools.yang.model.api.PathExpression.Steps)2 CommonTokenStream (org.antlr.v4.runtime.CommonTokenStream)1 ParseTree (org.antlr.v4.runtime.tree.ParseTree)1 Test (org.junit.Test)1 PathExpression (org.opendaylight.yangtools.yang.model.api.PathExpression)1 LeafRefPathLexer (org.opendaylight.yangtools.yang.parser.antlr.LeafRefPathLexer)1 LeafRefPathParser (org.opendaylight.yangtools.yang.parser.antlr.LeafRefPathParser)1 Deref_exprContext (org.opendaylight.yangtools.yang.parser.antlr.LeafRefPathParser.Deref_exprContext)1 Deref_function_invocationContext (org.opendaylight.yangtools.yang.parser.antlr.LeafRefPathParser.Deref_function_invocationContext)1 Path_argContext (org.opendaylight.yangtools.yang.parser.antlr.LeafRefPathParser.Path_argContext)1 Path_strContext (org.opendaylight.yangtools.yang.parser.antlr.LeafRefPathParser.Path_strContext)1