class SymbolRule: child: Optional[SymbolRule] node: Optional[SymbolRule] attr1 = synthesized() attr2 = synthesized() test_synthesized = synthesized() attr3 = inherited() @synthesized def attr1(self): pass @synthesized def attr2(self): pass @synthesized def test_synthesized(self, node): return node.attr1, node.attr2 @pushdown def test_inheritable(self, node) -> SymbolRule.attr3 @ child: return node.attr1, node.attr2 @pushdown def test_inheritable2(self) -> SymbolRule.attr3 @ node: pass
class Rule: child: Optional[Rule] node: Optional[Child] attr1 = synthesized() attr2 = synthesized() attr3 = synthesized() attr4 = synthesized() @synthesized def attr1(self): return object() @synthesized def attr2(self): return self.attr1.__class__ @synthesized def attr3(self): return [self.attr2(type)] @synthesized def attr4(self, child, node): print(self.child) print(self.node) print(child.child) print(child.node) return str(self.attr3[0]) + node.some_attribute
class Test: print = synthesized() test = synthesized() @synthesized def print(self): print("this should be printed once!") return 0 @synthesized def test(self: {Test.print}): return "this should be printed after the above string"
class Term(ASTNode): # Inherited Attributes implicit_pushdown = inherited(implicit_pushdown=True) depth = inherited() index = inherited() # Synthesized Attributes index2 = synthesized() value = synthesized() type = synthesized() subtree_depth = synthesized() string = synthesized() summary = synthesized() # Default Rule Implementations @synthesized def summary(self): return "%s, %s" % (self.value, self.type) @synthesized def index2(self): if self.index is None: return None return self.index * 2 @pushdown def rule_index(self) -> Term.index @ All: return None @pushdown def rule_depth(self) -> Term.depth @ All: return self.depth + 1
def synthesized_once(f): # TODO lru_cache(None)( return synthesized(f)
class Stat: ok: bool = synthesized() env: dict = inherited() same: list = inherited()
class Decl: new: Tuple[(str, str)] = synthesized() env: dict = inherited() ok: bool = synthesized()
class Block: ok: bool = synthesized() env: dict = inherited() procs: dict = synthesized() same: list = inherited()
def index2(self): if self.index is None: return None return self.index * 2 @pushdown def rule_index(self) -> Term.index @ All: return None @pushdown def rule_depth(self) -> Term.depth @ All: return self.depth + 1 Term.set_in_module = synthesized() with rules_for(Term): @synthesized def set_in_module(): return "Success" @production class Sum(Term): addends: List[Term] def __init__(self, *addends): super().__init__() self.addends = list(addends)
class Parent: child1: ChildA child2: ChildA default = synthesized(default="Default Synth")
class NodeD(NodeBase): test = synthesized() @synthesized def test(self): return self.a
class Child: some_attribute = synthesized() @synthesized def some_attribute(self): pass