Skip to content

Commit

Permalink
typo fix for pegen meta parser
Browse files Browse the repository at this point in the history
  • Loading branch information
yf-yang committed Jun 19, 2024
1 parent a0dce37 commit c9df78b
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 24 deletions.
38 changes: 19 additions & 19 deletions Tools/peg_generator/pegen/c_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ def visit_NameLeaf(self, node: NameLeaf) -> FunctionCall:
)
return FunctionCall(
assigned_variable=f"{name.lower()}_var",
function=f"_PyPegen_expect_token",
function="_PyPegen_expect_token",
arguments=["p", name],
nodetype=NodeTypes.GENERIC_TOKEN,
return_type="Token *",
Expand Down Expand Up @@ -199,7 +199,7 @@ def visit_StringLeaf(self, node: StringLeaf) -> FunctionCall:
type = self.exact_tokens[val]
return FunctionCall(
assigned_variable="_literal",
function=f"_PyPegen_expect_token",
function="_PyPegen_expect_token",
arguments=["p", type],
nodetype=NodeTypes.GENERIC_TOKEN,
return_type="Token *",
Expand All @@ -212,7 +212,7 @@ def visit_Rhs(self, node: Rhs) -> FunctionCall:
if node.can_be_inlined:
self.cache[node] = self.generate_call(node.alts[0].items[0])
else:
name = self.gen.artifical_rule_from_rhs(node)
name = self.gen.artificial_rule_from_rhs(node)
self.cache[node] = FunctionCall(
assigned_variable=f"{name}_var",
function=f"{name}_rule",
Expand All @@ -233,26 +233,26 @@ def lookahead_call_helper(self, node: Lookahead, positive: int) -> FunctionCall:
call = self.generate_call(node.node)
if call.nodetype == NodeTypes.NAME_TOKEN:
return FunctionCall(
function=f"_PyPegen_lookahead_with_name",
function="_PyPegen_lookahead_with_name",
arguments=[positive, call.function, *call.arguments],
return_type="int",
)
elif call.nodetype == NodeTypes.SOFT_KEYWORD:
return FunctionCall(
function=f"_PyPegen_lookahead_with_string",
function="_PyPegen_lookahead_with_string",
arguments=[positive, call.function, *call.arguments],
return_type="int",
)
elif call.nodetype in {NodeTypes.GENERIC_TOKEN, NodeTypes.KEYWORD}:
return FunctionCall(
function=f"_PyPegen_lookahead_with_int",
function="_PyPegen_lookahead_with_int",
arguments=[positive, call.function, *call.arguments],
return_type="int",
comment=f"token={node.node}",
)
else:
return FunctionCall(
function=f"_PyPegen_lookahead",
function="_PyPegen_lookahead",
arguments=[positive, f"(void *(*)(Parser *)) {call.function}", *call.arguments],
return_type="int",
)
Expand All @@ -272,7 +272,7 @@ def visit_Forced(self, node: Forced) -> FunctionCall:
type = self.exact_tokens[val]
return FunctionCall(
assigned_variable="_literal",
function=f"_PyPegen_expect_forced_token",
function="_PyPegen_expect_forced_token",
arguments=["p", type, f'"{val}"'],
nodetype=NodeTypes.GENERIC_TOKEN,
return_type="Token *",
Expand All @@ -284,7 +284,7 @@ def visit_Forced(self, node: Forced) -> FunctionCall:
call.comment = None
return FunctionCall(
assigned_variable="_literal",
function=f"_PyPegen_expect_forced_result",
function="_PyPegen_expect_forced_result",
arguments=["p", str(call), f'"{node.node.rhs!s}"'],
return_type="void *",
comment=f"forced_token=({node.node.rhs!s})",
Expand Down Expand Up @@ -331,7 +331,7 @@ def visit_Repeat1(self, node: Repeat1) -> FunctionCall:
def visit_Gather(self, node: Gather) -> FunctionCall:
if node in self.cache:
return self.cache[node]
name = self.gen.artifical_rule_from_gather(node)
name = self.gen.artificial_rule_from_gather(node)
self.cache[node] = FunctionCall(
assigned_variable=f"{name}_var",
function=f"{name}_rule",
Expand Down Expand Up @@ -410,7 +410,7 @@ def call_with_errorcheck_goto(self, call_text: str, goto_target: str) -> None:
self.print(f"if ({error_var}) {{")
with self.indent():
self.print(f"goto {goto_target};")
self.print(f"}}")
self.print("}")

def out_of_memory_return(
self,
Expand All @@ -424,14 +424,14 @@ def out_of_memory_return(
self.print("p->error_indicator = 1;")
self.print("PyErr_NoMemory();")
self.add_return("NULL")
self.print(f"}}")
self.print("}")

def out_of_memory_goto(self, expr: str, goto_target: str) -> None:
self.print(f"if ({expr}) {{")
with self.indent():
self.print("PyErr_NoMemory();")
self.print(f"goto {goto_target};")
self.print(f"}}")
self.print("}")

def generate(self, filename: str) -> None:
self.collect_rules()
Expand Down Expand Up @@ -567,10 +567,10 @@ def _set_up_rule_memoization(self, node: Rule, result_type: str) -> None:
self.print("if (_raw == NULL || p->mark <= _resmark)")
with self.indent():
self.print("break;")
self.print(f"_resmark = p->mark;")
self.print("_resmark = p->mark;")
self.print("_res = _raw;")
self.print("}")
self.print(f"p->mark = _resmark;")
self.print("p->mark = _resmark;")
self.add_return("_res")
self.print("}")
self.print(f"static {result_type}")
Expand Down Expand Up @@ -626,7 +626,7 @@ def _handle_loop_rule_body(self, node: Rule, rhs: Rhs) -> None:
if memoize:
self.print("int _start_mark = p->mark;")
self.print("void **_children = PyMem_Malloc(sizeof(void *));")
self.out_of_memory_return(f"!_children")
self.out_of_memory_return("!_children")
self.print("Py_ssize_t _children_capacity = 1;")
self.print("Py_ssize_t _n = 0;")
if any(alt.action and "EXTRA" in alt.action for alt in rhs.alts):
Expand All @@ -644,7 +644,7 @@ def _handle_loop_rule_body(self, node: Rule, rhs: Rhs) -> None:
self.add_return("NULL")
self.print("}")
self.print("asdl_seq *_seq = (asdl_seq*)_Py_asdl_generic_seq_new(_n, p->arena);")
self.out_of_memory_return(f"!_seq", cleanup_code="PyMem_Free(_children);")
self.out_of_memory_return("!_seq", cleanup_code="PyMem_Free(_children);")
self.print("for (int i = 0; i < _n; i++) asdl_seq_SET_UNTYPED(_seq, i, _children[i]);")
self.print("PyMem_Free(_children);")
if memoize and node.name:
Expand Down Expand Up @@ -779,7 +779,7 @@ def handle_alt_normal(self, node: Alt, is_gather: bool, rulename: Optional[str])
self.emit_default_action(is_gather, node)

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

def handle_alt_loop(self, node: Alt, is_gather: bool, rulename: Optional[str]) -> None:
Expand All @@ -806,7 +806,7 @@ def handle_alt_loop(self, node: Alt, is_gather: bool, rulename: Optional[str]) -
self.print(
"void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *));"
)
self.out_of_memory_return(f"!_new_children", cleanup_code="PyMem_Free(_children);")
self.out_of_memory_return("!_new_children", cleanup_code="PyMem_Free(_children);")
self.print("_children = _new_children;")
self.print("}")
self.print("_children[_n++] = _res;")
Expand Down
4 changes: 2 additions & 2 deletions Tools/peg_generator/pegen/parser_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ def keyword_type(self) -> int:
self.keyword_counter += 1
return self.keyword_counter

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

def artifical_rule_from_gather(self, node: Gather) -> str:
def artificial_rule_from_gather(self, node: Gather) -> str:
self.counter += 1
name = f"_gather_{self.counter}"
self.counter += 1
Expand Down
6 changes: 3 additions & 3 deletions Tools/peg_generator/pegen/python_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ def visit_Rhs(self, node: Rhs) -> Tuple[Optional[str], str]:
if len(node.alts) == 1 and len(node.alts[0].items) == 1:
self.cache[node] = self.visit(node.alts[0].items[0])
else:
name = self.gen.artifical_rule_from_rhs(node)
name = self.gen.artificial_rule_from_rhs(node)
self.cache[node] = name, f"self.{name}()"
return self.cache[node]

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

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

if is_loop:
self.print(f"children.append({action})")
self.print(f"mark = self._mark()")
self.print("mark = self._mark()")
else:
if "UNREACHABLE" in action:
action = action.replace("UNREACHABLE", self.unreachable_formatting)
Expand Down

0 comments on commit c9df78b

Please sign in to comment.