Skip to content

Commit 0e1dbeb

Browse files
python
1 parent 715e2f9 commit 0e1dbeb

File tree

2 files changed

+84
-9
lines changed

2 files changed

+84
-9
lines changed
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
if True:
2+
pass
3+
elif False:
4+
pass
5+
else:
6+
pass
7+
---
8+
9+
[#1 Content] =
10+
[#1 Domain] = 0:0-1:8
11+
>--------
12+
0| if True:
13+
1| pass
14+
--------<
15+
16+
[#1 Removal] = 0:0-2:2
17+
>--------
18+
0| if True:
19+
1| pass
20+
2| elif False:
21+
--<
22+
23+
[#1 Insertion delimiter] = "\n"
24+
25+
26+
[#2 Content] =
27+
[#2 Domain] = 2:0-3:8
28+
>-----------
29+
2| elif False:
30+
3| pass
31+
--------<
32+
33+
[#2 Removal] = 2:0-4:0
34+
>-----------
35+
2| elif False:
36+
3| pass
37+
4| else:
38+
<
39+
40+
[#2 Insertion delimiter] = "\n"
41+
42+
43+
[#3 Content] =
44+
[#3 Domain] = 4:0-5:8
45+
>-----
46+
4| else:
47+
5| pass
48+
--------<
49+
50+
[#3 Removal] = 3:8-5:8
51+
>
52+
3| pass
53+
4| else:
54+
5| pass
55+
--------<
56+
57+
[#3 Insertion delimiter] = "\n"

queries/python.scm

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
(function_definition)
1919
(future_import_statement)
2020
(global_statement)
21-
(if_statement)
2221
(import_from_statement)
2322
(import_statement)
2423
(match_statement)
@@ -30,6 +29,8 @@
3029
(try_statement)
3130
(while_statement)
3231
(with_statement)
32+
;; Disabled on purpose. We have a better definition of this below.
33+
;; (if_statement)
3334
] @statement
3435

3536
;;!! a = 25
@@ -395,10 +396,6 @@
395396
")" @value.iteration.end.startOf @name.iteration.end.startOf @type.iteration.end.startOf
396397
)
397398

398-
;;!! if true: pass
399-
;;! ^^^^^^^^^^^^^
400-
(if_statement) @ifStatement
401-
402399
;;!! foo()
403400
;;! ^^^^^
404401
(call) @functionCall
@@ -507,11 +504,34 @@
507504
(#not-parent-type? @_.removal case_clause)
508505
) @_.domain
509506

507+
;;!! if true: pass else: pass
508+
;;! ^^^^^^^^^^^^^^^^^^^^^^^^
509+
(if_statement) @ifStatement @statement @branch.iteration
510+
511+
;;!! if True: pass
512+
;;! ^^^^^^^^^^^^^
513+
(if_statement
514+
"if" @interior.domain.start
515+
consequence: (_) @interior @interior.domain.end
516+
)
517+
510518
;;!! if True: pass
511519
;;! ^^^^^^^^^^^^^
512520
(if_statement
513-
"if" @branch.start @interior.domain.start
514-
consequence: (_) @branch.end @interior @interior.domain.end
521+
"if" @branch.start @branch.removal.start
522+
consequence: (_) @branch.end @branch.removal.end
523+
alternative: (else_clause)? @branch.removal.end.startOf
524+
)
525+
526+
;;!! if True: pass elif False: pass
527+
;;! ^^^^^^^^^^^^^
528+
(if_statement
529+
"if" @branch.start @branch.removal.start
530+
consequence: (_) @branch.end @branch.removal.end
531+
alternative: (elif_clause
532+
"elif" @branch.removal.end.startOf
533+
(#character-range! @branch.removal.end.startOf 2)
534+
)
515535
)
516536

517537
;;!! elif True: pass
@@ -526,8 +546,6 @@
526546
body: (_) @interior
527547
) @branch @interior.domain
528548

529-
(if_statement) @branch.iteration
530-
531549
;;!! try: pass
532550
;;! ^^^^^^^^^
533551
(try_statement

0 commit comments

Comments
 (0)