Skip to content

Commit 63345b5

Browse files
committed
Tag case-elses directly to the case
less ambiguous error messages
1 parent 3f728da commit 63345b5

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

nmfu.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2541,6 +2541,7 @@ def convert(self, current_error_handlers):
25412541
# ... and reattach them to the new else state machine
25422542
trans.to(sub_dfas[original_backreference[None]].starting_state).attach(*else_actions)
25432543
ProgramData.imbue(trans, DebugTag.NAME, "else action on case node")
2544+
ProgramData.imbue(trans, DebugTag.PARENT, self)
25442545
# We have to add that DFA's state to the overall dfa's states array, since it won't get picked up by mergable_ds _UNLESS_ original_backreference contains more than frozenset({None})
25452546
if len(original_backreference[None]) == 1:
25462547
for state in sub_dfas[original_backreference[None]].states:
@@ -2556,6 +2557,7 @@ def convert(self, current_error_handlers):
25562557
trans.to(new_state).attach(*else_actions, prepend=True).fallthrough() # this is an error handler, make sure it's a fallthrough
25572558
# give the transition better debug info
25582559
ProgramData.imbue(trans, DebugTag.NAME, "else action on case node")
2560+
ProgramData.imbue(trans, DebugTag.PARENT, self)
25592561

25602562
# Go through and link up all the states
25612563
for i in mergeable_ds:
@@ -3130,7 +3132,10 @@ def _parse_stmt(self, stmt: lark.Tree) -> Node:
31303132
return self._parse_assign_stmt(stmt, stmt.data == "append_stmt")
31313133
elif stmt.data == "case_stmt":
31323134
# Find all of the matches
3133-
return CaseNode({k: v for k, v in (self._parse_case_clause(x) for x in stmt.children)})
3135+
return ProgramData.imbue(ProgramData.imbue(CaseNode({k: v for k, v in (self._parse_case_clause(x) for x in stmt.children)}),
3136+
DebugTag.SOURCE_LINE, stmt.line),
3137+
DebugTag.SOURCE_COLUMN, stmt.column
3138+
)
31343139
elif stmt.data == "optional_stmt":
31353140
return OptionalNode(self._parse_stmt_seq(stmt.children))
31363141
elif stmt.data == "loop_stmt":

0 commit comments

Comments
 (0)