How to use the tatsu.util.is_list function in TatSu

To help you get started, we’ve selected a few TatSu 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 neogeny / TatSu / tatsu / ast.py View on Github external
def set(self, key, value, force_list=False):
        key = self._safekey(key)

        previous = self.get(key)
        if previous is None:
            if force_list:
                super(AST, self).__setitem__(key, [value])
            else:
                super(AST, self).__setitem__(key, value)
            self._order.append(key)
        elif is_list(previous):
            previous.append(value)
        else:
            super(AST, self).__setitem__(key, [previous, value])
        return self
github neogeny / TatSu / tatsu / contexts.py View on Github external
def _extend_cst(self, node):
        if node is None:
            return
        previous = self.cst
        if previous is None:
            self.cst = self._copy_node(node)
        elif is_list(node):
            if is_list(previous):
                previous.extend(node)
            else:
                self.cst = [previous] + node
        elif is_list(previous):
            previous.append(node)
        else:
            self.cst = [previous, node]
github neogeny / TatSu / tatsu / walkers.py View on Github external
def walk(self, node, *args, **kwargs):
        supers_walk = super().walk
        if isinstance(node, Node):
            children = [self.walk(c, *args, **kwargs) for c in node.children()]
            return supers_walk(node, children, *args, **kwargs)
        elif isinstance(node, Mapping):
            return {n: self.walk(e, *args, **kwargs) for n, e in node.items()}
        elif is_list(node):
            return [self.walk(e, *args, **kwargs) for e in iter(node)]
        else:
            return supers_walk(node, [], *args, **kwargs)
github neogeny / TatSu / tatsu / contexts.py View on Github external
def _save_result(self, key, result):
        if is_list(result.node):
            result = RuleResult(closure(result.node), result.newpos, result.newstate)
        self._results[key] = result
github neogeny / TatSu / tatsu / contexts.py View on Github external
def _add_cst_node(self, node):
        if node is None:
            return
        previous = self.cst
        if previous is None:
            self.cst = self._copy_node(node)
        elif is_list(previous):
            previous.append(node)
        else:
            self.cst = [previous, node]
github neogeny / TatSu / tatsu / contexts.py View on Github external
def _isolate(self, block, drop=False):
        self._push_cst()
        try:
            block()
            cst = self.cst
        finally:
            self._pop_cst()

        if is_list(cst):
            cst = closure(cst)
        if not drop:
            self._add_cst_node(cst)
        return cst