corenova / yang-js

YANG parser and composer
Apache License 2.0
56 stars 18 forks source link

Question about Pattern syntax #50

Closed sirikothe closed 7 years ago

sirikothe commented 7 years ago

I am unable to compile the following yang: https://github.com/YangModels/yang/blob/master/vendor/cisco/xr/612/Cisco-IOS-XR-types.yang throws following error: ElementError: invalid YANG syntax detected around: '"(([a-f0-9]{16}-)(([1-9]?[0-9]|1[0-9][0-9]|2[0-4]"+ "[0-9]|25[0-5]).){3}([1-9]?[0-9]|1[0-9]'

At this statement: typedef Bgp-ipv4-tunnel-addr { type string { pattern "((0:|[1-9][0-9]{0,4}:)"+ "(([1-9]?[0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5]).){3}"+ "([1-9]?[0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5]))"; } It passes the syntax in the following scenarios. If I change the pattern to (Remove \ before .) pattern "(([a-f0-9]{16}-)(([1-9]?[0-9]|1[0-9][0-9]|2[0-4]"+ "[0-9]|25[0-5]).){3}([1-9]?[0-9]|1[0-9][0-9]|2[0-4][0-9]"+ "|25[0-5]))";

or to (replace " with ') pattern '(([a-f0-9]{16}-)(([1-9]?[0-9]|1[0-9][0-9]|2[0-4]'+ '[0-9]|25[0-5]).){3}([1-9]?[0-9]|1[0-9][0-9]|2[0-4][0-9]'+ '|25[0-5]))';

Not sure what is the correct way of representing this syntax. Thanks for your help.

sirikothe commented 7 years ago

Looks like this is a duplicate of #16 ? Is there any workaround?

sekur commented 7 years ago

Yes it's a duplicate of #16. The underlying issue is with the yang-parser module and I haven't yet taken the time to investigate the issue with variable intropolation taking place for " strings which is breaking the regexp parsing.

The quickest workaround (for now) is to simply change the " into ' on the schema itself... but clearly that is not a long term solution.

Any ideas?

sirikothe commented 7 years ago

I am trying to parse hundreds of yangs that have used this in several places. So, changing them manually may be a problem. May be some kind of callback that will be called before parsing, so that application code can process before being parsed? For example, the call back then can replace " with ' for now so that the parsing will pass?

sekur commented 7 years ago

Ok - I'll take a look to see if we can disable the interpolation from the syntax parser.

sekur commented 7 years ago

@sirikothe - I've bundled the yang-parser and made the fix inside the yang-parser library to honor any special escape sequence characters in a double quoted string. I've also published new yang-js 0.16.23 that includes this fix.