Skip to content

Commit c9df78b

Browse files
committed
typo fix for pegen meta parser
1 parent a0dce37 commit c9df78b

File tree

3 files changed

+24
-24
lines changed

3 files changed

+24
-24
lines changed

Tools/peg_generator/pegen/c_generator.py

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ def visit_NameLeaf(self, node: NameLeaf) -> FunctionCall:
167167
)
168168
return FunctionCall(
169169
assigned_variable=f"{name.lower()}_var",
170-
function=f"_PyPegen_expect_token",
170+
function="_PyPegen_expect_token",
171171
arguments=["p", name],
172172
nodetype=NodeTypes.GENERIC_TOKEN,
173173
return_type="Token *",
@@ -199,7 +199,7 @@ def visit_StringLeaf(self, node: StringLeaf) -> FunctionCall:
199199
type = self.exact_tokens[val]
200200
return FunctionCall(
201201
assigned_variable="_literal",
202-
function=f"_PyPegen_expect_token",
202+
function="_PyPegen_expect_token",
203203
arguments=["p", type],
204204
nodetype=NodeTypes.GENERIC_TOKEN,
205205
return_type="Token *",
@@ -212,7 +212,7 @@ def visit_Rhs(self, node: Rhs) -> FunctionCall:
212212
if node.can_be_inlined:
213213
self.cache[node] = self.generate_call(node.alts[0].items[0])
214214
else:
215-
name = self.gen.artifical_rule_from_rhs(node)
215+
name = self.gen.artificial_rule_from_rhs(node)
216216
self.cache[node] = FunctionCall(
217217
assigned_variable=f"{name}_var",
218218
function=f"{name}_rule",
@@ -233,26 +233,26 @@ def lookahead_call_helper(self, node: Lookahead, positive: int) -> FunctionCall:
233233
call = self.generate_call(node.node)
234234
if call.nodetype == NodeTypes.NAME_TOKEN:
235235
return FunctionCall(
236-
function=f"_PyPegen_lookahead_with_name",
236+
function="_PyPegen_lookahead_with_name",
237237
arguments=[positive, call.function, *call.arguments],
238238
return_type="int",
239239
)
240240
elif call.nodetype == NodeTypes.SOFT_KEYWORD:
241241
return FunctionCall(
242-
function=f"_PyPegen_lookahead_with_string",
242+
function="_PyPegen_lookahead_with_string",
243243
arguments=[positive, call.function, *call.arguments],
244244
return_type="int",
245245
)
246246
elif call.nodetype in {NodeTypes.GENERIC_TOKEN, NodeTypes.KEYWORD}:
247247
return FunctionCall(
248-
function=f"_PyPegen_lookahead_with_int",
248+
function="_PyPegen_lookahead_with_int",
249249
arguments=[positive, call.function, *call.arguments],
250250
return_type="int",
251251
comment=f"token={node.node}",
252252
)
253253
else:
254254
return FunctionCall(
255-
function=f"_PyPegen_lookahead",
255+
function="_PyPegen_lookahead",
256256
arguments=[positive, f"(void *(*)(Parser *)) {call.function}", *call.arguments],
257257
return_type="int",
258258
)
@@ -272,7 +272,7 @@ def visit_Forced(self, node: Forced) -> FunctionCall:
272272
type = self.exact_tokens[val]
273273
return FunctionCall(
274274
assigned_variable="_literal",
275-
function=f"_PyPegen_expect_forced_token",
275+
function="_PyPegen_expect_forced_token",
276276
arguments=["p", type, f'"{val}"'],
277277
nodetype=NodeTypes.GENERIC_TOKEN,
278278
return_type="Token *",
@@ -284,7 +284,7 @@ def visit_Forced(self, node: Forced) -> FunctionCall:
284284
call.comment = None
285285
return FunctionCall(
286286
assigned_variable="_literal",
287-
function=f"_PyPegen_expect_forced_result",
287+
function="_PyPegen_expect_forced_result",
288288
arguments=["p", str(call), f'"{node.node.rhs!s}"'],
289289
return_type="void *",
290290
comment=f"forced_token=({node.node.rhs!s})",
@@ -331,7 +331,7 @@ def visit_Repeat1(self, node: Repeat1) -> FunctionCall:
331331
def visit_Gather(self, node: Gather) -> FunctionCall:
332332
if node in self.cache:
333333
return self.cache[node]
334-
name = self.gen.artifical_rule_from_gather(node)
334+
name = self.gen.artificial_rule_from_gather(node)
335335
self.cache[node] = FunctionCall(
336336
assigned_variable=f"{name}_var",
337337
function=f"{name}_rule",
@@ -410,7 +410,7 @@ def call_with_errorcheck_goto(self, call_text: str, goto_target: str) -> None:
410410
self.print(f"if ({error_var}) {{")
411411
with self.indent():
412412
self.print(f"goto {goto_target};")
413-
self.print(f"}}")
413+
self.print("}")
414414

415415
def out_of_memory_return(
416416
self,
@@ -424,14 +424,14 @@ def out_of_memory_return(
424424
self.print("p->error_indicator = 1;")
425425
self.print("PyErr_NoMemory();")
426426
self.add_return("NULL")
427-
self.print(f"}}")
427+
self.print("}")
428428

429429
def out_of_memory_goto(self, expr: str, goto_target: str) -> None:
430430
self.print(f"if ({expr}) {{")
431431
with self.indent():
432432
self.print("PyErr_NoMemory();")
433433
self.print(f"goto {goto_target};")
434-
self.print(f"}}")
434+
self.print("}")
435435

436436
def generate(self, filename: str) -> None:
437437
self.collect_rules()
@@ -567,10 +567,10 @@ def _set_up_rule_memoization(self, node: Rule, result_type: str) -> None:
567567
self.print("if (_raw == NULL || p->mark <= _resmark)")
568568
with self.indent():
569569
self.print("break;")
570-
self.print(f"_resmark = p->mark;")
570+
self.print("_resmark = p->mark;")
571571
self.print("_res = _raw;")
572572
self.print("}")
573-
self.print(f"p->mark = _resmark;")
573+
self.print("p->mark = _resmark;")
574574
self.add_return("_res")
575575
self.print("}")
576576
self.print(f"static {result_type}")
@@ -626,7 +626,7 @@ def _handle_loop_rule_body(self, node: Rule, rhs: Rhs) -> None:
626626
if memoize:
627627
self.print("int _start_mark = p->mark;")
628628
self.print("void **_children = PyMem_Malloc(sizeof(void *));")
629-
self.out_of_memory_return(f"!_children")
629+
self.out_of_memory_return("!_children")
630630
self.print("Py_ssize_t _children_capacity = 1;")
631631
self.print("Py_ssize_t _n = 0;")
632632
if any(alt.action and "EXTRA" in alt.action for alt in rhs.alts):
@@ -644,7 +644,7 @@ def _handle_loop_rule_body(self, node: Rule, rhs: Rhs) -> None:
644644
self.add_return("NULL")
645645
self.print("}")
646646
self.print("asdl_seq *_seq = (asdl_seq*)_Py_asdl_generic_seq_new(_n, p->arena);")
647-
self.out_of_memory_return(f"!_seq", cleanup_code="PyMem_Free(_children);")
647+
self.out_of_memory_return("!_seq", cleanup_code="PyMem_Free(_children);")
648648
self.print("for (int i = 0; i < _n; i++) asdl_seq_SET_UNTYPED(_seq, i, _children[i]);")
649649
self.print("PyMem_Free(_children);")
650650
if memoize and node.name:
@@ -779,7 +779,7 @@ def handle_alt_normal(self, node: Alt, is_gather: bool, rulename: Optional[str])
779779
self.emit_default_action(is_gather, node)
780780

781781
# As the current option has parsed correctly, do not continue with the rest.
782-
self.print(f"goto done;")
782+
self.print("goto done;")
783783
self.print("}")
784784

785785
def handle_alt_loop(self, node: Alt, is_gather: bool, rulename: Optional[str]) -> None:
@@ -806,7 +806,7 @@ def handle_alt_loop(self, node: Alt, is_gather: bool, rulename: Optional[str]) -
806806
self.print(
807807
"void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *));"
808808
)
809-
self.out_of_memory_return(f"!_new_children", cleanup_code="PyMem_Free(_children);")
809+
self.out_of_memory_return("!_new_children", cleanup_code="PyMem_Free(_children);")
810810
self.print("_children = _new_children;")
811811
self.print("}")
812812
self.print("_children[_n++] = _res;")

Tools/peg_generator/pegen/parser_generator.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ def keyword_type(self) -> int:
167167
self.keyword_counter += 1
168168
return self.keyword_counter
169169

170-
def artifical_rule_from_rhs(self, rhs: Rhs) -> str:
170+
def artificial_rule_from_rhs(self, rhs: Rhs) -> str:
171171
self.counter += 1
172172
name = f"_tmp_{self.counter}" # TODO: Pick a nicer name.
173173
self.all_rules[name] = Rule(name, None, rhs)
@@ -183,7 +183,7 @@ def artificial_rule_from_repeat(self, node: Plain, is_repeat1: bool) -> str:
183183
self.all_rules[name] = Rule(name, None, Rhs([Alt([NamedItem(None, node)])]))
184184
return name
185185

186-
def artifical_rule_from_gather(self, node: Gather) -> str:
186+
def artificial_rule_from_gather(self, node: Gather) -> str:
187187
self.counter += 1
188188
name = f"_gather_{self.counter}"
189189
self.counter += 1

Tools/peg_generator/pegen/python_generator.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ def visit_Rhs(self, node: Rhs) -> Tuple[Optional[str], str]:
116116
if len(node.alts) == 1 and len(node.alts[0].items) == 1:
117117
self.cache[node] = self.visit(node.alts[0].items[0])
118118
else:
119-
name = self.gen.artifical_rule_from_rhs(node)
119+
name = self.gen.artificial_rule_from_rhs(node)
120120
self.cache[node] = name, f"self.{name}()"
121121
return self.cache[node]
122122

@@ -168,7 +168,7 @@ def visit_Repeat1(self, node: Repeat1) -> Tuple[str, str]:
168168
def visit_Gather(self, node: Gather) -> Tuple[str, str]:
169169
if node in self.cache:
170170
return self.cache[node]
171-
name = self.gen.artifical_rule_from_gather(node)
171+
name = self.gen.artificial_rule_from_gather(node)
172172
self.cache[node] = name, f"self.{name}()" # No trailing comma here either!
173173
return self.cache[node]
174174

@@ -333,7 +333,7 @@ def visit_Alt(self, node: Alt, is_loop: bool, is_gather: bool) -> None:
333333

334334
if is_loop:
335335
self.print(f"children.append({action})")
336-
self.print(f"mark = self._mark()")
336+
self.print("mark = self._mark()")
337337
else:
338338
if "UNREACHABLE" in action:
339339
action = action.replace("UNREACHABLE", self.unreachable_formatting)

0 commit comments

Comments
 (0)