From a5c50262d905037ca69c80debb46aba3cc381201 Mon Sep 17 00:00:00 2001 From: Stephan Seitz Date: Fri, 15 May 2020 18:49:21 +0200 Subject: Add python locals.scm --- README.md | 2 +- queries/python/locals.scm | 65 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+), 1 deletion(-) create mode 100644 queries/python/locals.scm diff --git a/README.md b/README.md index d9d9b8f2..e87bc2ad 100644 --- a/README.md +++ b/README.md @@ -158,7 +158,7 @@ List of currently supported languages: - [ ] go - [ ] cpp - [ ] rust -- [ ] python +- [x] python (maintained by @theHamsta) - [ ] javascript - [ ] typescript - [ ] tsx diff --git a/queries/python/locals.scm b/queries/python/locals.scm new file mode 100644 index 00000000..763d1b77 --- /dev/null +++ b/queries/python/locals.scm @@ -0,0 +1,65 @@ +;;; Programm structure +(module) @scope + +(class_definition + body: (block + (expression_statement + (assignment + left: (expression_list + (identifier) @definition.associated))))) @scope + +; Function with parameters, defines parameters +(function_definition + name: (identifier) + parameters: (parameters + (identifier) @definition.var)) + +; Function defines function and scope +(function_definition + name: (identifier) @definition.function) @scope + +(class_definition + name: (identifier) @definition.type) @scope + +(class_definition + body: (block + (function_definition + name: (identifier) @definition.method))) + +;;; Loops +; not a scope! +(for_statement + left: (variables + (identifier) @definition.var)) + +; not a scope! +;(while_statement) @scope + +; for in list comprehension +(for_in_clause + left: (variables + (identifier) @definition.var)) + +(dictionary_comprehension) @scope +(list_comprehension) @scope +(set_comprehension) @scope + +;;; Assignments + +(assignment + left: (expression_list + (identifier) @definition.var)) + +(assignment + left: (expression_list + (attribute + (identifier) + (identifier) @definition.field))) + +; Walrus operator x := 1 +(named_expression + (identifier) @definition.var) + + +;;; REFERENCES +(identifier) @reference -- cgit v1.2.3