Skip to content

Commit

Permalink
Add source field to ParserVisitor
Browse files Browse the repository at this point in the history
  • Loading branch information
knutwannheden committed Aug 12, 2024
1 parent 9023939 commit 163901b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import ast
from dataclasses import dataclass
from pathlib import Path

import rewrite.java.tree as J
Expand All @@ -13,6 +14,13 @@ def map_type(node):


class ParserVisitor(ast.NodeVisitor):
_source: str
_cursor: int = 0

def __init__(self, source: str):
super().__init__()
self._source = source

def visit_Module(self, node: ast.Module) -> Py.CompilationUnit:
return Py.CompilationUnit(
random_id(),
Expand Down
2 changes: 1 addition & 1 deletion rewrite/rewrite-python/tests/parser_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ def bar(x):
tree = ast.parse(source)

# Create the visitor and visit the AST
visitor = ParserVisitor()
visitor = ParserVisitor(source)
visitor.visit(tree)

0 comments on commit 163901b

Please sign in to comment.