gritql icon indicating copy to clipboard operation
gritql copied to clipboard

Cannot rewrite empty field nodes

Open morgante opened this issue 1 year ago • 1 comments

Currently, if a field is null we can't rewrite/insert into it (because we don't have an associated range for a field that wasn't found).

Workaround

Rewrite the entire parent node that contained the null field.

Example

engine marzano(0.1)
language python

pattern test_func($name, $parameters, $return_type, $body) {
    function_definition($name, $parameters, $return_type, $body) as $function where {
        $name <: r"test_.*",
    }
}

pattern test_class($name, $superclasses, $body) {
    class_definition($name, $superclasses, $body) as $cls where {
        $superclasses <: contains `TestCase`,
    }
}

test_func($return_type) as $function where {
    $function <: within test_class(),
    $return_type => `None`
}

morgante avatar Mar 29 '24 21:03 morgante

This keeps coming up and the solution of rewriting the parent isn't very elegant. We should try to solve by inspecting the grammar and finding the "empty" binding.

morgante avatar Jul 02 '24 06:07 morgante