def test_generate_ignore_root_type(self): action_sequence = ActionSequence() action_sequence.eval( ApplyRule( ExpandTreeRule( NodeType(Root(), NodeConstraint.Node, False), [("root", NodeType(Root(), NodeConstraint.Node, False))]))) action_sequence.eval( ApplyRule( ExpandTreeRule(NodeType("op", NodeConstraint.Node, False), []))) assert Node("op", []) == action_sequence.generate()
def test_clone(self): action_sequence = ActionSequence() rule = ExpandTreeRule( NodeType("expr", NodeConstraint.Node, False), [("elems", NodeType("expr", NodeConstraint.Node, True))]) action_sequence.eval(ApplyRule(rule)) action_sequence2 = action_sequence.clone() assert action_sequence.generate() == action_sequence2.generate() action_sequence2.eval(ApplyRule(rule)) assert \ action_sequence._tree.children != action_sequence2._tree.children assert \ action_sequence._tree.parent != action_sequence2._tree.parent assert \ action_sequence.action_sequence != action_sequence2.action_sequence assert action_sequence._head_action_index != \ action_sequence2._head_action_index assert action_sequence._head_children_index != \ action_sequence2._head_children_index assert action_sequence.generate() != action_sequence2.generate()
def test_generate(self): funcdef = ExpandTreeRule( NodeType("def", NodeConstraint.Node, False), [("name", NodeType("value", NodeConstraint.Token, True)), ("body", NodeType("expr", NodeConstraint.Node, True))]) expr = ExpandTreeRule( NodeType("expr", NodeConstraint.Node, False), [("op", NodeType("value", NodeConstraint.Token, False)), ("arg0", NodeType("value", NodeConstraint.Token, False)), ("arg1", NodeType("value", NodeConstraint.Token, False))]) action_sequence = ActionSequence() action_sequence.eval(ApplyRule(funcdef)) action_sequence.eval(GenerateToken("name", "f")) action_sequence.eval(GenerateToken("name", "_")) action_sequence.eval(GenerateToken("name", "0")) action_sequence.eval(ApplyRule(CloseVariadicFieldRule())) action_sequence.eval(ApplyRule(expr)) action_sequence.eval(GenerateToken("value", "+")) action_sequence.eval(GenerateToken("value", "1")) action_sequence.eval(GenerateToken("value", "2")) action_sequence.eval(ApplyRule(CloseVariadicFieldRule())) assert action_sequence.head is None assert Node("def", [ Field("name", "value", [Leaf("name", "f"), Leaf("name", "_"), Leaf("name", "0")]), Field("body", "expr", [ Node("expr", [ Field("op", "value", Leaf("value", "+")), Field("arg0", "value", Leaf("value", "1")), Field("arg1", "value", Leaf("value", "2")) ]) ]) ]) == action_sequence.generate()