Closed lwgray closed 1 week ago
Level: Knight
Implement sophisticated newline handling to support indentation-based syntax while properly handling special cases like multi-line expressions, comments, and blank lines.
Update lexer state tracking:
def __init__(self): self.paren_count = 0 # Track nested parentheses self.bracket_count = 0 # Track nested brackets # ... existing init code ...
Enhance newline handling:
def t_NEWLINE(self, t): r'\n+' t.lexer.lineno += len(t.value) # Ignore newlines inside parentheses/brackets if self.paren_count == 0 and self.bracket_count == 0: return t
def t_LPAREN(self, t): r'(' self.paren_count += 1 return t
def t_RPAREN(self, t): r')' self.paren_count -= 1 return t
3. Add comment handling: ```python def t_COMMENT(self, t): r'\#.*' # Comments don't generate tokens pass
task "MultiLine" x = (1 + 2 + 3) y = 4
Should treat the multi-line expression as a single statement.
objective "Test" # Comment at root level task "Comments" # Indented comment x = 1 # Comment with blank line above y = 2
Should handle comments and blank lines properly.
task "Nested" x = [1, 2, 3, 4] step "Inner" y = (5 + 6)
Should handle nested structures with multi-line expressions.
task "Invalid" if x > 0: # This should raise an error y = 1
Should detect invalid line breaks.
Enhanced Newline Handling
Level: Knight
Description
Implement sophisticated newline handling to support indentation-based syntax while properly handling special cases like multi-line expressions, comments, and blank lines.
Technical Details
Changes Needed in parser.py
Update lexer state tracking:
Enhance newline handling:
def t_LPAREN(self, t): r'(' self.paren_count += 1 return t
def t_RPAREN(self, t): r')' self.paren_count -= 1 return t
Test Cases
Test Case 1: Multi-line Expression
Should treat the multi-line expression as a single statement.
Test Case 2: Comments and Blank Lines
Should handle comments and blank lines properly.
Test Case 3: Nested Structures
Should handle nested structures with multi-line expressions.
Test Case 4: Invalid Newlines
Should detect invalid line breaks.
Completion Criteria
Dependencies
Documentation Updates Needed
Testing Instructions