-
Notifications
You must be signed in to change notification settings - Fork 1
Open
Labels
complexity: padawanIntermediate issues requiring some experienceIntermediate issues requiring some experiencedocumentationImprovements or additions to documentationImprovements or additions to documentationenhancementNew feature or requestNew feature or requestparser
Description
Overview
Add support for single-line comments in Think using the '#' symbol, similar to Python's comment syntax. This will allow users to add explanatory notes and documentation within their Think programs.
Current State
Currently, Think has no support for comments. Users cannot add explanatory text or disable code without removing it.
Proposed Change
Add support for '#' style comments that:
- Can appear on their own line
- Can appear at the end of code lines
- Extend from the '#' character to the end of the line
Example Usage
# This is a full-line comment
objective "Calculate student grades" # This is an end-of-line comment
task "Process Grades": # Process student examination scores
# Initialize variables
step "Setup":
scores = [85, 92, 78] # Raw test scores
Implementation Details
1. Lexer Changes (parser.py)
Add a new token rule to the lexer that ignores everything from '#' to the end of the line:
def t_COMMENT(t):
r'\#.*'
pass # Comments should be ignored by the lexer
This rule should be added to the ThinkParser class before the IDENTIFIER rule to ensure proper precedence.
2. Update Tests (test_parser.py)
Add new test cases to verify comment handling:
def test_comments(self, parser):
"""Test parsing of comments in various positions."""
code = '''# Full line comment
objective "Test" # End of line comment
task "Example": # Task comment
step "Do Something": # Step comment
x = 42 # Variable assignment comment
run "Example" # Final comment'''
ast = parser.parse(code)
assert ast['objective'] == 'Test'
assert len(ast['tasks']) == 1
assert ast['tasks'][0]['name'] == 'Example'
3. Documentation Updates
- Update Think Language Style Guide (PEP 1)
- Add examples to README.md
- Update Jupyter notebook examples
- Update educational materials
4. Error Handling Considerations
- Ensure comments are properly handled in error messages and line number reporting
- Update the source context display in error messages to show comments
- Verify that comments don't interfere with indentation parsing
Migration Impact
This is a backward-compatible change. Existing Think programs will continue to work as before.
Testing Plan
-
Basic Comment Tests:
- Full-line comments
- End-of-line comments
- Multiple consecutive comment lines
- Comments with special characters
- Unicode characters in comments
-
Integration Tests:
- Comments in all program sections (objective, task, step, etc.)
- Comments with indentation
- Comments in control structures (if/else, loops)
- Comments in error scenarios
-
Edge Cases:
- Empty comments (#)
- Comments at file start/end
- Multiple #'s in one line
- Comments with quotes/brackets
- Very long comments
Acceptance Criteria
- Parser correctly ignores comments during execution
- Error messages show correct line numbers with comments present
- Source context in error messages includes comments
- All existing tests pass
- Documentation is updated
- Examples include comment usage
- No performance degradation in parsing
Related Documentation
- Current parser implementation: parser.py
- Test suite: test_parser.py
- Style guide: PEP 1 - ThinkPy Style Guide.md
Metadata
Metadata
Assignees
Labels
complexity: padawanIntermediate issues requiring some experienceIntermediate issues requiring some experiencedocumentationImprovements or additions to documentationImprovements or additions to documentationenhancementNew feature or requestNew feature or requestparser