Skip to content

Commit 7d9be6a

Browse files
committed
refactor: Streamline condition handling in CodeReader
This commit simplifies the condition handling in the CodeReader class by removing the compatibility check for custom conditions. The class now directly builds the combined conditions set from separated categories, enhancing clarity and maintainability. Additionally, the documentation has been updated to reflect the new language reader pattern, emphasizing the automatic combination of condition categories for improved usability.
1 parent 5aa5987 commit 7d9be6a

File tree

3 files changed

+9
-26
lines changed

3 files changed

+9
-26
lines changed

lizard_languages/code_reader.py

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,6 @@ class CodeReader:
100100
_logical_operators = {'&&', '||'}
101101
_case_keywords = {'case'}
102102
_ternary_operators = {'?'}
103-
104-
# For compatibility with custom readers that may define _conditions directly
105-
_conditions = None
106103

107104
@classmethod
108105
def _build_conditions(cls):
@@ -119,13 +116,8 @@ def __init__(self, context):
119116
self.parallel_states = []
120117
self.context = context
121118

122-
# Build combined conditions set
123-
if self.__class__._conditions is not None:
124-
# Subclass defines _conditions directly
125-
self.conditions = copy(self.__class__._conditions)
126-
else:
127-
# Build from separated categories
128-
self.conditions = copy(self.__class__._build_conditions())
119+
# Build combined conditions set from separated categories
120+
self.conditions = copy(self.__class__._build_conditions())
129121

130122
# Expose individual categories for extensions
131123
self.control_flow_keywords = copy(self.__class__._control_flow_keywords)

ongoing/code-structure-reference.md

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -202,24 +202,20 @@ reader.ternary_operators # Set: Ternary operators only
202202

203203
All are mutable sets that extensions can modify.
204204

205-
## Backward Compatibility
205+
## Language Reader Pattern
206206

207-
The base class supports two approaches for defining conditions:
207+
All language readers define separated condition categories:
208208

209209
```python
210-
# Approach 1: Define _conditions directly (for compatibility)
211-
class CustomReader(CodeReader):
212-
_conditions = {'if', 'for', '&&', '||', 'case', '?'} # Combined set
213-
214-
# Approach 2: Use separated categories (recommended)
215-
class ModernReader(CodeReader):
210+
class LanguageReader(CodeReader):
211+
# Define each category based on language syntax
216212
_control_flow_keywords = {'if', 'for'}
217213
_logical_operators = {'&&', '||'}
218214
_case_keywords = {'case'}
219215
_ternary_operators = {'?'}
220216
```
221217

222-
Both approaches work identically. Separated categories provide better semantics and enable extensions to target specific types.
218+
The base class automatically combines these into `self.conditions` for CCN calculation, while also exposing individual categories for extensions to use.
223219

224220
## Quick Reference Table
225221

ongoing/todo_list.md

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,8 @@
22

33
## Completed
44

5-
### Separate Conditions Refactoring ✅
6-
- [x] Separated condition concepts into 4 distinct categories
7-
- [x] Updated all 21+ language readers
8-
- [x] Updated all 4 extensions
9-
- [x] Comprehensive test coverage (1021 tests passing)
10-
- [x] Documentation created
11-
- [x] Fully backward compatible
5+
### Condition Categories Refactoring ✅
6+
All phases complete. See `CONDITIONS_REFACTORING.md` for details.
127

138
## Active
149

0 commit comments

Comments
 (0)