-
Notifications
You must be signed in to change notification settings - Fork 1
Open
Labels
Description
Issue Description
The current ThinkPy parser incorrectly includes statements outside of loop bodies within the loop's AST. This causes premature loop termination when executing statements that should be outside the loop.
Example of the Problem
# Original Code
objective "Test list operations"
task "Lists":
step "Process":
items = []
for i in range(3):
items = items + [i]
print(items)
print(items[1])
run "Lists"
Current Parser Behavior
The parser incorrectly includes both print statements in the loop's body in the AST:
'body': [
{'type': 'assignment', ...},
{'type': 'function_call', 'name': 'print', 'arguments': ['items']},
{'type': 'function_call', 'name': 'print', 'arguments': [{'type': 'index'...}]}
]
Constraints
The solution must:
- Clearly define loop body boundaries
- Not require additional keywords (like 'end')
- Not use curly braces or parentheses
- Not use semicolons
- Not rely on specific keywords after the loop
- Not require additional step definitions
- Keep the language simple and Pythonic
- Support multiple statements within loop bodies
Desired Solution
- Move to a indent/dedent syntax
Temporary Hack
- Use END to indicate the end of a loop body
# Original Code
objective "Test list operations"
task "Lists":
step "Process":
items = []
for i in range(3):
items = items + [I]
end
print(items)
print(items[1])
run "Lists"
Questions to Consider
- How can we unambiguously determine where a loop body ends?
- What parsing strategies could maintain simplicity while providing clear boundaries?
- Are there existing language designs that solve this elegantly without the above constraints?
Impact
This issue affects:
- Loop execution
- Program flow control
- Statement grouping
- AST generation accuracy
Labels
- bug
- parser
- needs-discussion
- syntax-design
Priority
High - This affects basic program flow control and execution accuracy.