[YANGTOOLS-15] Provide new Parser constructor Created: 12/Sep/13  Updated: 10/Apr/22  Resolved: 26/Sep/13

Status: Resolved
Project: yangtools
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Improvement
Reporter: Christopher Hartley Assignee: Unassigned
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Operating System: Windows
Platform: PC



 Description   

What I need is an option like

parseYangModels(File yangFile, File directory)

Currently I need to do something like this this :

List<File> yangFiles = new ArrayList<File>();
yangFiles.add(new File("IF-MIB.yang"));
yangFiles.add(new File("iana-if-type.yang"));
yangFiles.add(new File("SNMPv2-TC.yang"));
yangFiles.add(new File("ietf-yang-types.yang"));

YangModelParser parser = new YangParserImpl();
Set<Module> modules = new HashSet<Module>();
modules = parser.parseYangModels(yangFiles);

Of course hard-coding won't work, so otherwise I'll need to parse each Yang file and compute the import transitive closure myself.

I think this would be a useful addition to the API.



 Comments   
Comment by Martin Vitez [ 24/Sep/13 ]

I am not sure if I fully understand your suggestion. Currently parser provides a couple of parse* methods which take List of files or streams and return collection of modules. Do you want to add method to parser for parsing single file which returns single Module object?

Comment by Christopher Hartley [ 25/Sep/13 ]

Martin,

the issue comes that if a module imports other modules (take IF-MIB.yang as an example) then I currently need to by hand look inside the yang files and determine all the imports than add them to the list before I call parseYangModels().

What I need is a convenience method that I can give the main file to and a path where my Yang files are. The convenience method would determine all of the files required to parse the original file, then call parseYangModels(ArrayList<File>) with a list of all the files needed to parse the original file.

So based on my original example, I could do something like this

YangModelParser parser = new YangParserImpl();
Set<Module> modules = new HashSet<Module>();
modules = parser.parseYangModels(("IF-MIB.yang", "C:\yang");

modules would contain IF-MIB.yang, iana-if-type, SNMPv2-TC and ietf-yang-types

Comment by Martin Vitez [ 26/Sep/13 ]

Implemented in version 0.5.8-SNAPSHOT.

Comment by Christopher Hartley [ 26/Sep/13 ]

thanks for this.

I looked in build 117
https://jenkins.opendaylight.org/yangtools/job/yangtools-merge/117/
and all the changes are in yang-parser-impl, but
there is no jar file. It just says "yang-parser-impl (didn’t run)"

Generated at Wed Feb 07 20:52:01 UTC 2024 using Jira 8.20.10#820010-sha1:ace47f9899e9ee25d7157d59aa17ab06aee30d3d.