@@ -23,6 +23,12 @@ class AST_Semantic_Parser(ast.NodeVisitor):
2323 """
2424 A "Rosetta Stone" that translates Python AST nodes into
2525 DIVE-V2 conceptual keywords.
26+
27+ This parser walks through Python's Abstract Syntax Tree and categorizes
28+ code constructs into semantic dimensions (Love, Justice, Power, Wisdom).
29+
30+ Note: Visitor methods don't "visit" in the semantic sense - they record
31+ and categorize AST nodes into semantic concepts for later analysis.
2632 """
2733
2834 def __init__ (self , vocabulary : Set [str ]):
@@ -150,7 +156,13 @@ def _add_concept(self, node: ast.AST, concept: str):
150156 self ._node_map [node ] = concept
151157 self ._concepts_found .add (concept )
152158
153- def visit_Call (self , node : ast .Call ):
159+ def visit_Call (self , node : ast .Call ) -> None :
160+ """
161+ Records function/method calls and categorizes them semantically.
162+
163+ Maps method names to semantic dimensions (e.g., 'execute' -> Power,
164+ 'validate' -> Justice, 'get' -> Wisdom).
165+ """
154166 concept = None
155167 if isinstance (node .func , ast .Attribute ):
156168 method_name = node .func .attr
@@ -171,36 +183,83 @@ def visit_Call(self, node: ast.Call):
171183 self ._add_concept (node , concept )
172184 self .generic_visit (node )
173185
174- def visit_If (self , node : ast .If ):
186+ def visit_If (self , node : ast .If ) -> None :
187+ """
188+ Records If statements as Justice concepts (control flow/decision-making).
189+
190+ If statements enforce conditions and control execution flow, which
191+ aligns with Justice (rules, structure, enforcement).
192+ """
175193 self ._add_concept (node , "justice" )
176194 self .generic_visit (node )
177195
178- def visit_Assert (self , node : ast .Assert ):
196+ def visit_Assert (self , node : ast .Assert ) -> None :
197+ """
198+ Records Assert statements as Justice concepts (validation/enforcement).
199+
200+ Assertions enforce invariants and preconditions, directly representing
201+ Justice principles of validation and rule enforcement.
202+ """
179203 self ._add_concept (node , "justice" )
180204 self .generic_visit (node )
181205
182- def visit_Try (self , node : ast .Try ):
206+ def visit_Try (self , node : ast .Try ) -> None :
207+ """
208+ Records Try-Except blocks with dual semantics.
209+
210+ Try blocks represent Justice (structural error handling), while
211+ exception handlers represent Love (mercy, graceful recovery).
212+ """
183213 self ._add_concept (node , "justice" )
184214 if node .handlers :
185215 self ._add_concept (node .handlers [0 ], "love" )
186216 self .generic_visit (node )
187217
188- def visit_Raise (self , node : ast .Raise ):
218+ def visit_Raise (self , node : ast .Raise ) -> None :
219+ """
220+ Records Raise statements as Power concepts (forceful action).
221+
222+ Raising exceptions is an active, forceful interruption of normal
223+ flow, representing Power (control, force, action).
224+ """
189225 self ._add_concept (node , "power" )
190226 self .generic_visit (node )
191227
192- def visit_For (self , node : ast .For ):
228+ def visit_For (self , node : ast .For ) -> None :
229+ """
230+ Records For loops as Justice concepts (structured iteration).
231+
232+ For loops impose structure and order on iteration, representing
233+ Justice (rules, patterns, systematic processing).
234+ """
193235 self ._add_concept (node , "justice" )
194236 self .generic_visit (node )
195237
196- def visit_While (self , node : ast .While ):
238+ def visit_While (self , node : ast .While ) -> None :
239+ """
240+ Records While loops as Justice concepts (conditional iteration).
241+
242+ While loops enforce conditions for continued iteration, representing
243+ Justice (rules, enforcement, conditional control).
244+ """
197245 self ._add_concept (node , "justice" )
198246 self .generic_visit (node )
199247
200- def visit_Return (self , node : ast .Return ):
248+ def visit_Return (self , node : ast .Return ) -> None :
249+ """
250+ Records Return statements as Wisdom concepts (providing results).
251+
252+ Return statements deliver computed results or knowledge back to
253+ callers, representing Wisdom (information, knowledge transfer).
254+ """
201255 self ._add_concept (node , "wisdom" )
202256 self .generic_visit (node )
203257
204- def generic_visit (self , node : ast .AST ):
205- """This is the default visitor that just continues the walk."""
258+ def generic_visit (self , node : ast .AST ) -> None :
259+ """
260+ Default visitor that continues traversing the AST.
261+
262+ This method is called for AST node types that don't have
263+ specific visitor methods defined.
264+ """
206265 super ().generic_visit (node )
0 commit comments