Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def is_appinfo(keyword):
if util.is_prefixed(keyword) == True:
return False
(argname, argiselem, argappinfo) = yang_keywords[keyword]
return argappinfo
def is_rule_less_than(ra, rb):
rka = ra[0]
rkb = rb[0]
if not util.is_prefixed(rkb):
# old rule is non-prefixed; append new rule after
return False
if not util.is_prefixed(rka):
# old rule prefixed, but new rule is not, insert
return True
# both are prefixed, compare modulename
return rka[0] < rkb[0]
for s in stmts:
def is_rule_less_than(ra, rb):
rka = ra[0]
rkb = rb[0]
if not util.is_prefixed(rkb):
# old rule is non-prefixed; append new rule after
return False
if not util.is_prefixed(rka):
# old rule prefixed, but new rule is not, insert
return True
# both are prefixed, compare modulename
return rka[0] < rkb[0]
for s in stmts:
canonical)
if match_res != None:
# this case branch matched, use it.
# remove the choice and add res to the spec.
nspec = spec[:i] + match_res[0] + spec[i+1:]
return (nspec, canspec)
# we must not report errors on non-matching branches
ctx.errors = save_errors
j += 1
elif keywd == '$interleave':
cspec = occurance
match_res = _match_stmt(ctx, stmt, (cspec, cspec), canonical)
if match_res != None:
# we got a match
return (spec, canspec)
elif util.is_prefixed(stmt.keyword):
# allow extension statements mixed with these
# set canonical to False in this call to just remove the
# matching stmt from the spec
match_res = _match_stmt(ctx, stmt, (spec[i+1:], canspec), False)
if match_res != None:
return (spec[:i+1] + match_res[0], canspec)
else:
return None
elif keywd == '$cut':
# any non-optional statements left are errors
for (keywd, occurance) in spec[:i]:
if occurance == '1' or occurance == '+':
error.err_add(ctx.errors, stmt.pos, 'UNEXPECTED_KEYWORD_1',
(util.keyword_to_str(stmt.raw_keyword),
util.keyword_to_str(keywd)))
# consume them so we don't report the same error again
def find_identifier(identifier):
if util.is_prefixed(identifier):
(prefix, name) = identifier
pmodule = prefix_to_module(path.i_module, prefix, stmt.pos,
ctx.errors)
if pmodule is None:
raise NotFound
return (pmodule, name)
elif in_typedef and stmt.i_module.i_version != '1':
raise Abort
else: # local identifier
return (local_module, identifier)
def ppkeywd(tok):
if util.is_prefixed(tok):
return tok[0] + ':' + tok[1]
else:
return tok
def _chk_stmts(ctx, pos, stmts, parent, spec, canonical):
for stmt in stmts:
stmt.is_grammatically_valid = False
if stmt.keyword == '_comment':
chk_grammar = False
elif not util.is_prefixed(stmt.keyword):
chk_grammar = True
else:
(modname, _identifier) = stmt.keyword
if modname in extension_modules:
chk_grammar = True
else:
chk_grammar = False
if chk_grammar == True:
match_res = _match_stmt(ctx, stmt, spec, canonical)
else:
match_res = None
if match_res is None and chk_grammar == True:
if canonical == True:
save_errors = ctx.errors
ctx.errors = []
if _match_stmt(ctx, stmt, (spec[1], []), False) is not None:
def get_kwd_class(keyword):
if util.is_prefixed(keyword):
return 'extension'
else:
try:
return _kwd_class[keyword]
except KeyError:
return 'body'