How to use the tatsu.util.indent 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 / codegen / python.py View on Github external
parseinfo = self.node.directives.get('parseinfo', True)

        namechars = repr(self.node.directives.get('namechars') or '')

        rules = '\n'.join([
            self.get_renderer(rule).render() for rule in self.node.rules
        ])

        version = str(tuple(int(n) for n in str(timestamp()).split('.')))

        keywords = [str(k) for k in self.keywords]
        keywords = '\n'.join("    %s," % repr(k) for k in keywords)
        if keywords:
            keywords = '\n%s\n' % keywords

        fields.update(rules=indent(rules),
                      start=self.node.rules[0].name,
                      abstract_rules=abstract_rules,
                      version=version,
                      whitespace=whitespace,
                      nameguard=nameguard,
                      ignorecase=ignorecase,
                      comments_re=comments_re,
                      eol_comments_re=eol_comments_re,
                      left_recursion=left_recursion,
                      parseinfo=parseinfo,
                      keywords=keywords,
                      namechars=namechars,
                      )
github neogeny / TatSu / tatsu / codegen / python.py View on Github external
def render_fields(self, fields):
        template = trim(self.option_template)
        options = [
            template.format(
                option=indent(self.rend(o))) for o in self.node.options
        ]
        options = '\n'.join(o for o in options)
        firstset = ' '.join(f[0] for f in sorted(self.node.lookahead()) if f)
        if firstset:
            error = 'expecting one of: ' + firstset
        else:
            error = 'no available options'
        fields.update(n=self.counter(),
                      options=indent(options),
                      error=repr(error)
                      )
github neogeny / TatSu / tatsu / codegen / python.py View on Github external
def render_fields(self, fields):
        template = trim(self.option_template)
        options = [
            template.format(
                option=indent(self.rend(o))) for o in self.node.options
        ]
        options = '\n'.join(o for o in options)
        firstset = ' '.join(f[0] for f in sorted(self.node.lookahead()) if f)
        if firstset:
            error = 'expecting one of: ' + firstset
        else:
            error = 'no available options'
        fields.update(n=self.counter(),
                      options=indent(options),
                      error=repr(error)
                      )
github neogeny / TatSu / tatsu / grammars.py View on Github external
def _to_str(self, lean=False):
        sexp = str(self.exp._to_str(lean=lean))
        if len(sexp.splitlines()) <= 1:
            return '{%s}' % sexp
        else:
            return '{\n%s\n}' % indent(sexp)
github neogeny / TatSu / tatsu / rendering.py View on Github external
def indent(self, item, ind=1, multiplier=4):
        return indent(self.rend(item), indent=ind, multiplier=4)
github neogeny / TatSu / tatsu / codegen / objectmodel.py View on Github external
def render_fields(self, fields):
        defs = [safe_name(d) for d, l in compress_seq(self.defines())]
        defs = list(sorted(set(defs)))
        spec = fields["spec"]

        kwargs = '\n'.join('%s = None' % d for d in defs)
        if kwargs:
            kwargs = indent(kwargs)
        else:
            kwargs = indent('pass')

        fields.update(
            class_name=spec.class_name,
            base=spec.base,
            kwargs=kwargs,
        )
github neogeny / TatSu / tatsu / grammars.py View on Github external
params = '(%s, %s)' % (params, kwparams)
            elif kwparams:
                params = '(%s)' % (kwparams)
            elif params:
                if len(self.params) == 1:
                    params = '::%s' % params
                else:
                    params = '(%s)' % params

        base = ' < %s' % str(self.base.name) if self.base else ''

        return trim(self.str_template).format(
            name=self.name,
            base=base,
            params=params,
            exp=indent(self.exp._to_str(lean=lean)),
            comments=comments,
            is_name='@name\n' if self.is_name else '',
        )
github neogeny / TatSu / tatsu / codegen / python.py View on Github external
def render_fields(self, fields):
        abstract_template = trim(self.abstract_rule_template)
        abstract_rules = [
            abstract_template.format(name=safe_name(rule.name))
            for rule in self.node.rules
        ]
        abstract_rules = indent('\n'.join(abstract_rules))

        whitespace = self.node.whitespace or self.node.directives.get('whitespace')
        if not whitespace:
            whitespace = 'None'
        elif isinstance(whitespace, RETYPE):
            whitespace = repr(whitespace)
        else:
            whitespace = 're.compile({0})'.format(repr(whitespace))

        if self.node.nameguard is not None:
            nameguard = repr(self.node.nameguard)
        elif self.node.directives.get('nameguard') is not None:
            nameguard = self.node.directives.get('nameguard')
        else:
            nameguard = 'None'
github neogeny / TatSu / tatsu / grammars.py View on Github external
def _to_str(self, lean=False):
        exp = self.exp._to_str(lean=lean)
        if len(exp.splitlines()) > 1:
            return '(\n%s\n)' % indent(exp)
        else:
            return '(%s)' % trim(exp)