MCPcopy Index your code
hub / github.com/python/cpython / visit_Rule

Method visit_Rule

Tools/peg_generator/pegen/c_generator.py:673–711  ·  view source on GitHub ↗
(self, node: Rule)

Source from the content-addressed store, hash-verified

671 self.add_return("_seq")
672
673 def visit_Rule(self, node: Rule) -> None:
674 is_loop = node.is_loop()
675 is_gather = node.is_gather()
676 rhs = node.flatten()
677 if is_loop or is_gather:
678 result_type = "asdl_seq *"
679 elif node.type:
680 result_type = node.type
681 else:
682 result_type = "void *"
683
684 for line in str(node).splitlines():
685 self.print(f"// {line}")
686 if node.left_recursive and node.leader:
687 self.print(f"static {result_type} {node.name}_raw(Parser *);")
688
689 self.print(f"static {result_type}")
690 self.print(f"{node.name}_rule(Parser *p)")
691
692 if node.left_recursive and node.leader:
693 self._set_up_rule_memoization(node, result_type)
694
695 self.print("{")
696
697 if node.name.endswith("without_invalid"):
698 with self.indent():
699 self.print("int _prev_call_invalid = p->call_invalid_rules;")
700 self.print("p->call_invalid_rules = 0;")
701 self.cleanup_statements.append("p->call_invalid_rules = _prev_call_invalid;")
702
703 if is_loop:
704 self._handle_loop_rule_body(node, rhs)
705 else:
706 self._handle_default_rule_body(node, rhs, result_type)
707
708 if node.name.endswith("without_invalid"):
709 self.cleanup_statements.pop()
710
711 self.print("}")
712
713 def visit_NamedItem(self, node: NamedItem) -> None:
714 call = self.callmakervisitor.generate_call(node)

Callers

nothing calls this directly

Calls 13

strFunction · 0.85
is_loopMethod · 0.80
is_gatherMethod · 0.80
flattenMethod · 0.45
splitlinesMethod · 0.45
printMethod · 0.45
endswithMethod · 0.45
indentMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected