From d6bd5f4096144f38b24b2f7ac5a6a5a1cbed8693 Mon Sep 17 00:00:00 2001 From: AcerecA Date: Fri, 19 Jun 2026 17:52:31 +0200 Subject: [PATCH] [gemma4] update parser logic --- skillls/parser.py | 52 +++++++++++++++++++++++++---------------------- 1 file changed, 28 insertions(+), 24 deletions(-) diff --git a/skillls/parser.py b/skillls/parser.py index e3a74d4..36a2e85 100644 --- a/skillls/parser.py +++ b/skillls/parser.py @@ -44,38 +44,42 @@ class SkillParser: def _traverse_tree( self, - node, + root_node, content: str, diagnostics: list[Diagnostic], symbols: list[DocumentSymbol] ) -> None: - """Recursively traverses the AST to find errors and symbols.""" - - # 1. Handle Errors (Diagnostics) - if node.type in ERROR_NODE_TYPES: - start_point = node.start_point - end_point = node.end_point + """Iteratively traverses the AST to find errors and symbols.""" + stack = [root_node] + + while stack: + node = stack.pop() - diagnostics.append( - Diagnostic( - range=Range( - start=Position(start_point[0], start_point[1]), - end=Position(end_point[0], end_point[1]) - ), - message=f"Syntax error: unexpected {node.type} token", - severity=DiagnosticSeverity.Error, + # 1. Handle Errors (Diagnostics) + if node.type in ERROR_NODE_TYPES: + start_point = node.start_point + end_point = node.end_point + + diagnostics.append( + Diagnostic( + range=Range( + start=Position(start_point[0], start_point[1]), + end=Position(end_point[0], end_point[1]) + ), + message=f"Syntax error: unexpected {node.type} token", + severity=DiagnosticSeverity.Error, + ) ) - ) - # 2. Handle Symbols (Document Symbols / Outline) - if self._is_symbol_node(node): - symbol = self._create_document_symbol(node, content) - if symbol: - symbols.append(symbol) + # 2. Handle Symbols (Document Symbols / Outline) + if self._is_symbol_node(node): + symbol = self._create_document_symbol(node, content) + if symbol: + symbols.append(symbol) - # 3. Continue traversal - for child in node.children: - self._traverse_tree(child, content, diagnostics, symbols) + # 3. Continue traversal - push children in reverse order to maintain original DFS order + for child in reversed(node.children): + stack.append(child) def _is_symbol_node(self, node) -> bool: """Determines if a node is significant enough to be an outline symbol."""