How to use the pyang.util.is_prefixed function in pyang

To help you get started, we’ve selected a few pyang examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github mbj4668 / pyang / pyang / translators / xsd.py View on Github external
def is_appinfo(keyword):
        if util.is_prefixed(keyword) == True:
            return False
        (argname, argiselem, argappinfo) = yang_keywords[keyword]
        return argappinfo
github mbj4668 / pyang / pyang / grammar.py View on Github external
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:
github mbj4668 / pyang / pyang / grammar.py View on Github external
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:
github mbj4668 / pyang / pyang / grammar.py View on Github external
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
github mbj4668 / pyang / pyang / statements.py View on Github external
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)
github mbj4668 / pyang / pyang / yang_parser.py View on Github external
def ppkeywd(tok):
    if util.is_prefixed(tok):
        return tok[0] + ':' + tok[1]
    else:
        return tok
github mbj4668 / pyang / pyang / grammar.py View on Github external
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:
github mbj4668 / pyang / pyang / translators / yang.py View on Github external
def get_kwd_class(keyword):
    if util.is_prefixed(keyword):
        return 'extension'
    else:
        try:
            return _kwd_class[keyword]
        except KeyError:
            return 'body'