# Path: penman/types.py



from typing import Dict, List, Tuple, Set, Mapping, Any, Iterator
from penman.types import (Variable, Branch, Node)

def _format_branch(branch: Branch, level: int) -> str:
    role, target = branch
    if is_atomic(target):
        target = repr(target)
    else:
        target = _format(target, level)
    return f'({role!r}, {target})'


def _nodes(node: Node) -> List[Node]:
    var, branches = node
    ns = [] if var is None else [node]
    for _, target in branches:
        # if target is not atomic, assume it's a valid tree node
        if not is_atomic(target):
            ns.extend(_nodes(target))
    return ns


def _walk(node: Node, path: Tuple[int, ...]) -> Iterator[_Step]:
    var, branches = node
    for i, branch in enumerate(branches):
        curpath = path + (i,)
        yield (curpath, branch)
        _, target = branch
        if not is_atomic(target):
            yield from _walk(target, curpath)



# Path: penman/types.py



# Path: penman/tree.py
from typing import Dict, List, Tuple, Set, Mapping, Any, Iterator
from penman.types import (Variable, Branch, Node)


def _format_branch(branch: Branch, level: int) -> str:
    role, target = branch
    if is_atomic(target):
        target = repr(target)
    else:
        target = _format(target, level)
    return f'({role!r}, {target})'


def _nodes(node: Node) -> List[Node]:
    var, branches = node
    ns = [] if var is None else [node]
    for _, target in branches:
        # if target is not atomic, assume it's a valid tree node
        if not is_atomic(target):
            ns.extend(_nodes(target))
    return ns


def _walk(node: Node, path: Tuple[int, ...]) -> Iterator[_Step]:
    var, branches = node
    for i, branch in enumerate(branches):
        curpath = path + (i,)
        yield (curpath, branch)
        _, target = branch
        if not is_atomic(target):
            yield from _walk(target, curpath)



def _default_variable_prefix(concept: Any) -> Variable: