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

Method visit_Forced

Tools/peg_generator/pegen/c_generator.py:267–294  ·  view source on GitHub ↗
(self, node: Forced)

Source from the content-addressed store, hash-verified

265 return self.lookahead_call_helper(node, 0)
266
267 def visit_Forced(self, node: Forced) -> FunctionCall:
268 call = self.generate_call(node.node)
269 if isinstance(node.node, Leaf):
270 assert isinstance(node.node, Leaf)
271 val = ast.literal_eval(node.node.value)
272 assert val in self.exact_tokens, f"{node.node.value} is not a known literal"
273 type = self.exact_tokens[val]
274 return FunctionCall(
275 assigned_variable="_literal",
276 function="_PyPegen_expect_forced_token",
277 arguments=["p", type, f'"{val}"'],
278 nodetype=NodeTypes.GENERIC_TOKEN,
279 return_type="Token *",
280 comment=f"forced_token='{val}'",
281 )
282 if isinstance(node.node, Group):
283 call = self.visit(node.node.rhs)
284 call.assigned_variable = None
285 call.comment = None
286 return FunctionCall(
287 assigned_variable="_literal",
288 function="_PyPegen_expect_forced_result",
289 arguments=["p", str(call), f'"{node.node.rhs!s}"'],
290 return_type="void *",
291 comment=f"forced_token=({node.node.rhs!s})",
292 )
293 else:
294 raise NotImplementedError(f"Forced tokens don't work with {node.node} nodes")
295
296 def visit_Opt(self, node: Opt) -> FunctionCall:
297 call = self.generate_call(node.node)

Callers

nothing calls this directly

Calls 4

generate_callMethod · 0.95
FunctionCallClass · 0.85
strFunction · 0.85
visitMethod · 0.45

Tested by

no test coverage detected