How to use the tatsu.contexts.closure 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 / 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
github neogeny / TatSu / tatsu / contexts.py View on Github external
def _positive_closure(self, block, sep=None, omitsep=False):
        self._push_cst()
        try:
            block()
            self.cst = [self.cst]
            self._repeat(block, prefix=sep, dropprefix=omitsep)
            cst = closure(self.cst)
        finally:
            self._pop_cst()
        self._add_cst_node(cst)
        self.last_node = cst
        return cst
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 srix / pytamil / pytamil / தமிழ் / புணர்ச்சி.py View on Github external
def varumozhiexpression(self, ast):
        பதம் = ast[1].strip()
        filters = ast[0]
        for i in range(len(filters)-1,-1,-1):
            filter = filters[i]
            if type(filter) is list or type(filter) is  tatsu.contexts.closure:
                func = filter[0]
                params = '\'' + பதம் + '\''  # default paramater
                params = params + ',' + '\'' + filter[1] + '\'' # additional parameter from rules
            else:
                func = filter
                params = '\'' + பதம் + '\''  # default paramater

            பதம் =  eval(func+'(' + params + ')')

        return பதம்
github neogeny / TatSu / tatsu / contexts.py View on Github external
def _closure(self, block, sep=None, omitsep=False):
        self._push_cst()
        try:
            self.cst = []
            with self._optional():
                block()
                self.cst = [self.cst]
            self._repeat(block, prefix=sep, dropprefix=omitsep)
            cst = closure(self.cst)
        finally:
            self._pop_cst()
        self._add_cst_node(cst)
        self.last_node = cst
        return cst