-
Notifications
You must be signed in to change notification settings - Fork 344
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve YANG parsing especially for comments and spacing #244
Conversation
Conflicts: pyang/yang_parser.py
@mbj4668 I suggest ignoring (rejecting) this PR. This is because the |
I've decided to give up on this one and am closing it. Comment processing has been improved since I created it (over two years ago!). You still can't put comments before or after the module/submodule statement, but this is a theoretical rather than a practical problem. Also, comment locations aren't always preserved (e.g. inline comments go onto the next line, possibly preceded by a blank line) but again this isn't really a huge issue! I have rescued the "smart quoting" part of this code and contributed it and some other minor changes via a new PR #436. |
This is the first of three pull requests, each of which builds on the previous one. The first step is to improve the YANG parsing and YANG output format so that well-written YANG will be unchanged by being passed through
pyang
. The second step is to add a newyang-edit
output format that can edit the YANG in various ways. One advantage of this approach (over, for example, YIN and XSLT) is that the fullpyang
parse tree is available and therefore quite sophisticated editing operations are easily implemented. A YIN/XSLT approach would in any case need the YANG parsing improvements.The pull requests (referring to them by their branch names) are:
yang-parse
: (this one) The main emphasis is on comment handling (including allowing comments to precede the module/submodule statement) and line-handling (so the output can retain things like blank lines and trailing comments). The implementation approach was chosen to minimise change from the current implementation but a better approach would probably be to completely re-think how comments are handled (they are currently handled as statements but this doesn't really work, because they should be syntactically equivalent to white space).yang-output
: (includes theyang-parse
commits) The main changes are supporting a new--yang-keep-blank-lines
option and pretty-printing quoted strings (including splitting them into multiple lines where necessary in order to avoid exceeding designated maximum line lengths).yang-edit
: (includes theyang-output
commits) Defines a newyang-edit
output format that inherits from theyang
output format. Currently supports various specific--yang-edit-xxx
options with various heuristics for how the replacement values are specified. Could support generic XPath-based editing operations.