How to use the tatsu.exceptions.CodegenError 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 / objectmodel.py View on Github external
if PY33:
        name = cls.__qualname__
    else:
        name = cls.__name__

    # Try to reference the class
    try:
        idents = name.split('.')
        _cls = getattr(module, idents[0])
        for ident in idents[1:]:
            _cls = getattr(_cls, ident)

        assert _cls == cls
    except AttributeError:
        raise CodegenError("Couldn't find base type, it has to be importable")

    return modulename, name
github neogeny / TatSu / tatsu / codegen / objectmodel.py View on Github external
def _get_full_name(cls):
    if not inspect.isclass(cls):
        raise CodegenError("Base type has to be a class")
    module = inspect.getmodule(cls)
    if not module:
        raise CodegenError("Base type has to be inside a module")
    modulename = module.__name__

    if PY33:
        name = cls.__qualname__
    else:
        name = cls.__name__

    # Try to reference the class
    try:
        idents = name.split('.')
        _cls = getattr(module, idents[0])
        for ident in idents[1:]:
            _cls = getattr(_cls, ident)

        assert _cls == cls
    except AttributeError:
github neogeny / TatSu / tatsu / codegen / objectmodel.py View on Github external
def _get_full_name(cls):
    if not inspect.isclass(cls):
        raise CodegenError("Base type has to be a class")
    module = inspect.getmodule(cls)
    if not module:
        raise CodegenError("Base type has to be inside a module")
    modulename = module.__name__

    if PY33:
        name = cls.__qualname__
    else:
        name = cls.__name__

    # Try to reference the class
    try:
        idents = name.split('.')
        _cls = getattr(module, idents[0])
        for ident in idents[1:]:
            _cls = getattr(_cls, ident)
github neogeny / TatSu / tatsu / codegen / python.py View on Github external
def render(self, **fields):
        if {()} in self.node.exp.lookahead():
            raise CodegenError('may repeat empty sequence')
        return '\n' + super().render(**fields)
github neogeny / TatSu / tatsu / codegen / __init__.py View on Github external
def codegen(model, target='python'):
    if target.lower() == 'python':
        from tatsu.codegen import python
        return python.codegen(model)
    else:
        raise CodegenError('Unknown target language: %s' % target)
github neogeny / TatSu / tatsu / codegen / objectmodel.py View on Github external
def _find_renderer_class(self, item):
        if not isinstance(item, Node):
            return None

        name = item.__class__.__name__
        renderer = globals().get(name)
        if not renderer or not issubclass(renderer, ModelRenderer):
            raise CodegenError('Renderer for %s not found' % name)
        return renderer
github neogeny / TatSu / tatsu / codegen / cgbase.py View on Github external
node_class_name = node.__class__.__name__
        classes = [node.__class__]
        while classes:
            cls = classes.pop()

            name = cls.__name__
            if name in self._renderers:
                renderer = self._renderers[name]
                self._renderers[node_class_name] = renderer
                return renderer

            for base in cls.__bases__:
                if base not in classes:
                    classes.append(base)

        raise CodegenError('Renderer for %s not found' % node_class_name)
github neogeny / TatSu / tatsu / codegen / python.py View on Github external
def _find_renderer_class(self, node):
        if not isinstance(node, Node):
            return None

        name = node.__class__.__name__
        renderer = globals().get(name)
        if not renderer or not issubclass(renderer, Base):
            raise CodegenError('Renderer for %s not found' % name)
        return renderer