Initialized logging
This commit is contained in:
+18
-1
@@ -2,6 +2,9 @@ from parsers.BaseParser import BaseParser, Node, ErrorNode
|
||||
from dataclasses import dataclass
|
||||
import ast
|
||||
import copy
|
||||
import logging
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@dataclass()
|
||||
@@ -17,7 +20,7 @@ class PythonNode(Node):
|
||||
|
||||
def __repr__(self):
|
||||
return "PythonNode(" + ast.dump(self.ast) + ")"
|
||||
#return "PythonNode(" + self.source + ")"
|
||||
# return "PythonNode(" + self.source + ")"
|
||||
|
||||
|
||||
class PythonParser(BaseParser):
|
||||
@@ -73,3 +76,17 @@ class PythonParser(BaseParser):
|
||||
return eval(compile(self.expr_to_expression(last_ast.body[0]), "<ast>", "eval"), globals())
|
||||
else:
|
||||
exec(compile(last_ast, "<ast>", "exec"), globals())
|
||||
|
||||
|
||||
class PythonGetNamesVisitor(ast.NodeVisitor):
|
||||
"""
|
||||
This visitor will find all the name declared in the ast
|
||||
"""
|
||||
def __init__(self):
|
||||
self.names = set()
|
||||
log.debug("Searching for names.")
|
||||
|
||||
def visit_Name(self, node):
|
||||
log.debug(f"Found name : {node.id}")
|
||||
self.names.add(node.id)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user