You've already forked langkit-query-language
mirror of
https://github.com/AdaCore/langkit-query-language.git
synced 2026-02-12 13:03:42 -08:00
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.
24 lines
890 B
Python
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()
|