Skip to content
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

Fix issue#399: keep yang line number in yin file #400

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions pyang/statements.py
Original file line number Diff line number Diff line change
Expand Up @@ -2692,8 +2692,11 @@ def follow_path(ptr, up, dn):
if ptr.keyword in _keyword_with_children:
ptr = search_data_node(ptr.i_children, module_name, name,
last_skipped)
if not is_submodule_included(path, ptr):
ptr = None

## comment out following 2 lines to fix issue #396
##if not is_submodule_included(path, ptr):
## ptr = None

if ptr is None:
err_add(ctx.errors, pathpos, 'LEAFREF_IDENTIFIER_NOT_FOUND',
(module_name, name, stmt.arg, stmt.pos))
Expand Down
11 changes: 9 additions & 2 deletions pyang/translators/yin.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ def add_opts(self, optparser):
dest="yin_pretty_strings",
action="store_true",
help="Pretty print strings"),
optparse.make_option("--yin-keep-line-number",
dest="yin_keep_line_number",
action="store_true",
help="Keep YANG file line number in yin file"),
]
g = optparser.add_option_group("YIN output specific options")
g.add_options(optlist)
Expand Down Expand Up @@ -117,14 +121,17 @@ def emit_stmt(ctx, module, stmt, fd, indent, indentstep):
(argname, argiselem) = syntax.yin_map[stmt.raw_keyword]
tag = stmt.raw_keyword
if argiselem == False or argname is None:
posatt = '' # fix issue#399 to add line number
if ctx.opts.yin_keep_line_number is not None:
posatt = ' line=' + quoteattr(str(stmt.pos.line))
if argname is None:
attr = ''
else:
attr = ' ' + argname + '=' + quoteattr(stmt.arg)
if len(stmt.substmts) == 0:
fd.write(indent + '<' + tag + attr + '/>\n')
fd.write(indent + '<' + tag + attr + posatt + '/>\n')
else:
fd.write(indent + '<' + tag + attr + '>\n')
fd.write(indent + '<' + tag + attr + posatt + '>\n')
for s in stmt.substmts:
emit_stmt(ctx, module, s, fd, indent + indentstep,
indentstep)
Expand Down
3 changes: 2 additions & 1 deletion pyang/yin_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,8 @@ def check_attr(self, pos, attrs):
for at in attrs:
(ns, local_name) = self.split_qname(at)
if ns is None:
error.err_add(self.ctx.errors, pos,
if local_name != 'line': # fix issue#399
error.err_add(self.ctx.errors, pos,
'UNEXPECTED_ATTRIBUTE', local_name)
elif ns == yin_namespace:
error.err_add(self.ctx.errors, pos,
Expand Down