def register_set_in_scope(ir_set: irast.Set, *, path_scope: irast.ScopeTreeNode = None, ctx: context.ContextLevel) -> None: if path_scope is None: path_scope = ctx.path_scope try: path_scope.attach_path(ir_set.path_id) except irast.InvalidScopeConfiguration as e: raise errors.QueryError(e.args[0], context=ir_set.context) from e
def _try_namespace_fix( scope: irast.ScopeTreeNode, obj: Union[irast.ScopeTreeNode, irast.Set], ) -> None: if obj.path_id is None: return for prefix in obj.path_id.iter_prefixes(): replacement = scope.find_visible(prefix) if (replacement and replacement.path_id and replacement.path_id != prefix): new = obj.path_id.replace_prefix(prefix, replacement.path_id) obj.path_id = new break
def _try_namespace_fix( scope: irast.ScopeTreeNode, obj: Union[irast.ScopeTreeNode, irast.Set], ) -> None: if obj.path_id is None: return for prefix in obj.path_id.iter_prefixes(): replacement = scope.find_visible(prefix, allow_group=True) if (replacement and replacement.path_id and replacement.path_id.namespace != obj.path_id.namespace): new = obj.path_id.strip_namespace(obj.path_id.namespace - replacement.path_id.namespace) obj.path_id = new break
def register_set_in_scope( ir_set: irast.Set, *, path_scope: irast.ScopeTreeNode=None, fence_points: FrozenSet[irast.PathId]=frozenset(), ctx: context.ContextLevel) -> List[irast.ScopeTreeNode]: if path_scope is None: path_scope = ctx.path_scope try: return path_scope.attach_path( ir_set.path_id, fence_points=fence_points, ) except irast.InvalidScopeConfiguration as e: raise errors.QueryError( e.args[0], context=ir_set.context) from e
def _get_set_scope(ir_set: irast.Set, scope_tree: irast.ScopeTreeNode) -> irast.ScopeTreeNode: if ir_set.path_scope_id: # Work-around the fact that unique ids are not actually # unique, and search our local tree first. new_scope = scope_tree.find_by_unique_id(ir_set.path_scope_id) if new_scope is None: new_scope = scope_tree.root.find_by_unique_id(ir_set.path_scope_id) if new_scope is None: raise errors.InternalServerError( f'dangling scope pointer to node with uid' f':{ir_set.path_scope_id} in {ir_set!r}') else: new_scope = scope_tree return new_scope
def register_set_in_scope( ir_set: irast.Set, *, path_scope: irast.ScopeTreeNode = None, optional: bool = False, fence_points: FrozenSet[irast.PathId] = frozenset(), ctx: context.ContextLevel) -> List[irast.ScopeTreeNode]: if path_scope is None: path_scope = ctx.path_scope if ctx.path_log is not None: ctx.path_log.append(ir_set.path_id) return path_scope.attach_path( ir_set.path_id, optional=optional, fence_points=fence_points, context=ir_set.context, )
def fuse_scope_branch(ir_set: irast.Set, parent: irast.ScopeTreeNode, branch: irast.ScopeTreeNode, *, ctx: context.ContextLevel) -> None: if parent.path_id is None: parent.attach_subtree(branch) else: if branch.path_id is None and len(branch.children) == 1: target_branch = next(iter(branch.children)) else: target_branch = branch if parent.path_id == target_branch.path_id: new_root = irast.new_scope_tree() for child in tuple(target_branch.children): new_root.attach_child(child) parent.attach_subtree(new_root) else: parent.attach_subtree(branch)