How to use the tatsu.ast.AST 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 / grammars.py View on Github external
def __init__(self, ast=None, **kwargs):
        super().__init__(ast=AST(name='@', exp=ast))
github reswitched / SwIPC / idparser.py View on Github external
def parseType(type):
	if not isinstance(type, tatsu.ast.AST) or 'template' not in type or 'structFields' not in type or 'enumFields' not in type:
		return type
	assert(not(type['template'] is not None and type['structFields'] is not None and type['enumFields'] is not None))
	name, template, structFields, enumFields = type['name'], type['template'], type['structFields'], type['enumFields']
	if structFields is not None:
		return ["struct"] + [list(map(lambda x: [x['name'], parseType(x['type']), list(map(lambda x: x.line, x['doc']))], structFields))]
	elif enumFields is not None:
		return ["enum"] + [list(map(lambda x: [x['name'], x['value'], list(map(lambda x: x.line, x['doc']))], enumFields))] + [template[0]['name']]
	elif template is not None:
		return [name] + list(map(parseType, template))
	else:
		return [name]
github neogeny / TatSu / tatsu / grammars.py View on Github external
def __init__(self, ast=None, **kwargs):
        self.comment = None
        super().__init__(ast=AST(comment=ast))
github neogeny / TatSu / examples / calc / calc.py View on Github external
def expression(self, ast):
        if not isinstance(ast, AST):
            return ast
        elif ast.op == '+':
            return ast.left + ast.right
        elif ast.op == '-':
            return ast.left - ast.right
        else:
            raise Exception('Unknown operator', ast.op)
github neogeny / TatSu / tatsu / ast.py View on Github external
def __reduce__(self):
        return (AST, (), None, None, iter(self.items()))
github nitros12 / A-Compiler / wewcompiler / objects / astnode.py View on Github external
def __init__(self, *, ast: Optional[AST] = None):
        self.context: 'CompileContext' = None
        self.ast = ast

        self.namespace = ""

        if ast is not None:
            assert isinstance(ast, AST)
            self._info: ParseInfo = ast.parseinfo
        else:
            self._info = None
github neogeny / TatSu / tatsu / infos.py View on Github external
def __init__(self, ast=None, cst=None):
        self.ast = AST() if ast is None else ast
        self.cst = cst
github neogeny / TatSu / tatsu / g2e / semantics.py View on Github external
def negative(self, ast):
        neg = model.NegativeLookahead(ast)
        any = model.Pattern('.')
        return model.Sequence(AST(sequence=[neg, any]))
github neogeny / TatSu / tatsu / g2e / semantics.py View on Github external
def elements(self, ast):
        elements = [e for e in ast if e is not None]
        if not elements:
            return model.Void()
        elif len(elements) == 1:
            return elements[0]
        else:
            return model.Sequence(AST(sequence=elements))
github neogeny / TatSu / tatsu / yaml.py View on Github external
def ast_load(stream, **kwargs):
    return load(stream, object_pairs_hook=AST, **kwargs)