Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def __init__(self, ast=None, **kwargs):
super().__init__(ast=AST(name='@', exp=ast))
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]
def __init__(self, ast=None, **kwargs):
self.comment = None
super().__init__(ast=AST(comment=ast))
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)
def __reduce__(self):
return (AST, (), None, None, iter(self.items()))
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
def __init__(self, ast=None, cst=None):
self.ast = AST() if ast is None else ast
self.cst = cst
def negative(self, ast):
neg = model.NegativeLookahead(ast)
any = model.Pattern('.')
return model.Sequence(AST(sequence=[neg, any]))
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))
def ast_load(stream, **kwargs):
return load(stream, object_pairs_hook=AST, **kwargs)