From a9a3164c2467806108f729a9979c8af1c587e18d Mon Sep 17 00:00:00 2001 From: LordBaryhobal Date: Thu, 9 Jul 2026 18:57:26 +0200 Subject: [PATCH] fix: implement missing methods on printer and highlighter --- midas/ast/printer/python_ast.py | 18 ++++++++++++++++++ midas/cli/highlighter.py | 9 +++++++++ 2 files changed, 27 insertions(+) diff --git a/midas/ast/printer/python_ast.py b/midas/ast/printer/python_ast.py index 70a2223..d7de89c 100644 --- a/midas/ast/printer/python_ast.py +++ b/midas/ast/printer/python_ast.py @@ -117,6 +117,24 @@ class PythonAstPrinter( stmt.iterator.accept(self) self._write_sequence("body", stmt.body, last=True) + def visit_import_stmt(self, stmt: p.ImportStmt) -> None: + self._write_line("ImportStmt") + with self._child_level(single=True): + self._write_sequence("imports", stmt.imports, print_func=self._print_import) + + def visit_from_import_stmt(self, stmt: p.FromImportStmt) -> None: + self._write_line("FromImportStmt") + with self._child_level(): + self._write_line(f'module: "{stmt.module}"') + self._write_sequence("imports", stmt.imports, print_func=self._print_import) + self._write_line(f"level: {stmt.level}", last=True) + + def _print_import(self, import_: p.ImportAlias) -> None: + self._write_line("ImportAlias") + with self._child_level(): + self._write_line(f'name: "{import_.name}"') + self._write_line(f'alias: "{import_.alias}"') + def visit_raw_stmt(self, stmt: p.RawStmt) -> None: self._write_line("RawStmt") with self._child_level(single=True): diff --git a/midas/cli/highlighter.py b/midas/cli/highlighter.py index 6086463..81cc444 100644 --- a/midas/cli/highlighter.py +++ b/midas/cli/highlighter.py @@ -198,6 +198,10 @@ class PythonHighlighter( for body_stmt in stmt.body: body_stmt.accept(self) + def visit_import_stmt(self, stmt: p.ImportStmt) -> None: ... + + def visit_from_import_stmt(self, stmt: p.FromImportStmt) -> None: ... + def visit_binary_expr(self, expr: p.BinaryExpr) -> None: ... def visit_compare_expr(self, expr: p.CompareExpr) -> None: ... @@ -265,6 +269,11 @@ class MidasHighlighter( def highlight(self, node: Highlightable[MidasHighlighter]): node.accept(self) + def visit_alias_stmt(self, stmt: m.AliasStmt) -> None: + self.wrap(stmt, "alias-stmt") + self.wrap(LocatableToken(stmt.name), "type-name") + stmt.type.accept(self) + def visit_type_stmt(self, stmt: m.TypeStmt) -> None: self.wrap(stmt, "type-stmt") self.wrap(LocatableToken(stmt.name), "type-name")