Files
langkit-query-language/utils/refactoring/simplify_binding_patterns.py
Raphaël AMIARD 434cb2e8cd Allow binding pattern without value pattern
So now those are valid patterns:

    a
    (a, b)
    ...

Also attach the refactoring script that automatically transforms `a@*` into
`a`, and simplify every binding pattern that can be simplified.
2024-04-22 15:40:52 +02:00

24 lines
890 B
Python

import refactor
import liblkqllang as lkql
from refactor import Action, ActionKind
class App(refactor.Refactor):
def preprocess(self, unit):
for binding_pat in unit.root.findall(lkql.BindingPattern):
# Remove every token from the @ token to the last whitespace after the '*' token
if binding_pat.f_value_pattern and binding_pat.f_value_pattern.is_a(lkql.UniversalPattern):
cur_tok = refactor.first_with_pred(binding_pat.token_start, lambda t: t.kind == 'At')
if cur_tok.previous.kind == 'Whitespace':
cur_tok = cur_tok.previous
end_tok = binding_pat.token_end.next
while cur_tok != end_tok:
self.add_action(cur_tok, Action(ActionKind.replace, ""))
cur_tok = cur_tok.next
if __name__ == '__main__':
App.run()