Skip to content

Commit e354ab1

Browse files
author
Cedric Halbronn
committed
Python value iteration scopes
1 parent 3fa6e08 commit e354ab1

File tree

2 files changed

+51
-3
lines changed

2 files changed

+51
-3
lines changed

data/playground/python/values.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
# Useful commands:
2+
# "visualize value"
3+
# "visualize value iteration"
4+
# "take value"
5+
# "chuck value"
6+
# "chuck every value"
17

28
# the argument value "True" that is part of "b=True"
39
# is "value" scope
@@ -19,12 +25,28 @@ def func(b=True, c=True):
1925
val = 1.5
2026
val /= 25
2127

22-
val1, val2 = 0, 5
28+
val1, val2 = 0, 5
29+
val1 = 0, val2 = 5
2330
val1 = val2
2431

32+
def my_funk(value: str) -> str:
33+
print(value)
34+
35+
# we can say "change every value" to allow modifying all the values in one go
36+
def foo():
37+
a = 0
38+
b = 1
39+
c = 2
40+
41+
# But we don't support outside of a function yet
42+
a = 0
43+
b = 1
44+
c = 2
2545

2646
# values of a Python "dictionary" are "value" scope
47+
# we can say "chuck every value" to convert the dict into a set
2748
d1 = {"a": 1, "b": 2, "c": 3}
49+
2850
_ = {value: key for (key, value) in d1.items()}
2951

3052
# complex ones

queries/python.scm

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,32 @@
135135
(module) @statement.iteration
136136
(module) @namedFunction.iteration @functionName.iteration
137137
(class_definition) @namedFunction.iteration @functionName.iteration
138-
(_
139-
body: (_) @statement.iteration
138+
139+
;; _ = {value: key for (key, value) in d1.items()}
140+
;; **********
141+
;;(_
142+
;; body: (_) @statement.iteration @value.iteration
143+
;;)
144+
145+
;; def foo():
146+
;; a = 0
147+
;; *****
148+
;; b = 1
149+
;; *****
150+
;; c = 2
151+
;; *****
152+
(block) @statement.iteration @value.iteration
153+
154+
;; {"a": 1, "b": 2, "c": 3}
155+
;; **********************
156+
(dictionary
157+
"{" @value.iteration.start.endOf
158+
"}" @value.iteration.end.startOf
159+
)
160+
161+
;; def func(a=0, b=1):
162+
;; ********
163+
(parameters
164+
"(" @value.iteration.start.endOf
165+
")" @value.iteration.end.startOf
140166
)

0 commit comments

Comments
 (0)