Skip to content

Conversation

@sgg
Copy link

@sgg sgg commented Sep 3, 2025

This diff adds support for prefixes in list keys as well as some unit tests.

Context

Where an identifier is something like interfaces, an identifier with a prefix might be openconfig-interfaces:interface. The ABNF in the YANG RFCs refers to these as node-identifier rules.

The current xpath implementation does not allow prefixed identifiers in list keys, however per RFC 6020 and RFC 7950 these are valid.

We can look to openconfig for a real world example.

For completeness I've lifted some relevant grammar snippets from the YANG RFCs:

   identifier          = (ALPHA / "_")
                         *(ALPHA / DIGIT / "_" / "-" / ".")

   prefix              = identifier

   node-identifier     = [prefix ":"] identifier

   absolute-path       = 1*("/" (node-identifier *path-predicate))

   relative-path       = 1*(".." "/") descendant-path

   descendant-path     = node-identifier
                         [*path-predicate absolute-path]

   key-arg             = node-identifier *(sep node-identifier)

   key-arg-str         = < a string that matches the rule
                           key-arg >

   key-stmt            = key-keyword sep key-arg-str stmtend

This diff adds support for prefixes in list keys as well as some unit
tests.

**Context**

Where an identifier is something like `interfaces`, an identifier with a
prefix might be `openconfig-interfaces:interface`. The ABNF in the YANG
RFCs refers to these as `node-identifier` rules.

The current xpath implementation does not allow prefixed identifiers in
list keys, however per [RFC 6020](https://datatracker.ietf.org/doc/html/rfc6020#section-12) and [RFC 7950](https://datatracker.ietf.org/doc/html/rfc7950#section-14) these
are valid.

We can look to openconfig for a [real world example](https://github.com/openconfig/public/blob/edf48ec7092fc2be9775937512dac8a1115483fb/release/models/interfaces/openconfig-interfaces.yang#L237-L242).

For completeness I've lifted some relevant grammar snippets from the YANG RFCs:

```
   identifier          = (ALPHA / "_")
                         *(ALPHA / DIGIT / "_" / "-" / ".")

   prefix              = identifier

   node-identifier     = [prefix ":"] identifier

   absolute-path       = 1*("/" (node-identifier *path-predicate))

   relative-path       = 1*(".." "/") descendant-path

   descendant-path     = node-identifier
                         [*path-predicate absolute-path]

   key-arg             = node-identifier *(sep node-identifier)

   key-arg-str         = < a string that matches the rule
                           key-arg >

   key-stmt            = key-keyword sep key-arg-str stmtend
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant