Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Question] Error when running demo/find_replace_custom_cleanup_demos.py #707

Open
sasidv opened this issue Nov 5, 2024 · 1 comment
Open

Comments

@sasidv
Copy link

sasidv commented Nov 5, 2024

Hi Team,

I'm trying to run the find_replace_custom_cleanup_demos.py file as the first step in getting started with Polyglot Piranha, but I encountered the following error when executing the python_demo() function.

thread '<unnamed>' panicked at src/utilities/tree_sitter_utilities.rs:191:3:
Could not fetch range or node for replace_node @assignment. Context: ["i", "list", "assignment"]
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Traceback (most recent call last):
  File "/Users/xxx/Documents/TreeSitter/TreeSitter/src/demo/find_replace_custom_cleanup_demos.py", line 80, in <module>
    python_demo()
  File "/Users/xxx/Documents/TreeSitter/TreeSitter/src/demo/find_replace_custom_cleanup_demos.py", line 67, in python_demo
    _ = execute_piranha(args)
pyo3_runtime.PanicException: Could not fetch range or node for replace_node @assignment. Context: ["i", "list", "assignment"]

However, I also noticed that when I remove the following entry from the only_lists.py file, the error disappears. Does anyone have any idea why this might be happening?

    deps3 = ['dependency2']

@danieltrt
Copy link
Contributor

Ah, so one of the rules under piranha/demo/find_replace_custom_cleanup/python/configurations/rules.toml is a bit convoluted.

try to replace

# Deletes an assignment to an empty list. Example: `a = []`
#
# Note the multiple escapes (`\`) for the regex below
# `\[` (match the `[` character) -> `\\\\[`
# `\s*` (match zero or more empty spaces) -> `\\\\s*`
[[rules]]
name = "delete_empty_list_assignment"
query = """
(
(assignment
        left: (_) @i
        right: (list) @list
) @assignment
(#match? @list "\\\\[\\\\s*,?\\\\]")
)
"""
replace_node = "@assignment"
replace = ""
is_seed_rule = false

with

[[rules]]
name = "delete_empty_list_assignment"
query = """cs :[variable] = []"""
replace_node = "*"
replace = ""
is_seed_rule = false

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants