|
1 | 1 | import ast |
2 | 2 | import token |
3 | 3 |
|
4 | | -from PythonVoiceCodingPlugin.third_party.asttokens import asttokens as asttokens |
| 4 | +from PythonVoiceCodingPlugin.third_party.asttokens import asttokens |
5 | 5 |
|
6 | 6 | from PythonVoiceCodingPlugin.library import previous_token,next_token |
7 | 7 | from PythonVoiceCodingPlugin.library.modification import ModificationHandler |
|
12 | 12 |
|
13 | 13 | def filter_asynchronous(atok,m = None, timestamp = 0): |
14 | 14 | m = m if m else ModificationHandler(atok.text) |
15 | | - candidates = [x for x in atok.tokens if x.type== 52 and x.string=="async"] |
| 15 | + candidates = [x for x in atok.tokens if x.string=="async"] |
16 | 16 | for c in candidates: |
17 | | - y = next_token(c) |
| 17 | + y = next_token(atok,c) |
18 | 18 | # async_stmt: 'async' (funcdef | with_stmt | for_stmt) |
19 | | - if y and y.type==52 and y.string in ["def","for","with"]: |
| 19 | + if y and y.string in ["def","for","with"]: |
20 | 20 | m.modify_from(timestamp,(c.startpos,y.startpos),"","async_"+y.string) |
21 | 21 | return m |
22 | 22 |
|
23 | 23 |
|
24 | 24 | def filter_await(atok,m = None, timestamp = 0): |
25 | 25 | m = m if m else ModificationHandler(atok.text) |
26 | | - candidates = [x for x in atok.tokens if x.type== 52 and x.string=="await"] |
| 26 | + candidates = [x for x in atok.tokens if x.string=="await"] |
27 | 27 | for c in candidates: |
28 | 28 | m.modify_from(timestamp,(c.startpos,c.endpos),"yield from","await") |
29 | 29 | return m |
30 | 30 |
|
31 | 31 | def filter_fstrings(atok,m = None, timestamp = 0): |
32 | 32 | m = m if m else ModificationHandler(atok.text) |
33 | | - candidates = [x for x in atok.tokens if x.type== 52 and x.string=="f"] |
| 33 | + candidates = [x for x in atok.tokens if x.string=="f"] |
34 | 34 | for c in candidates: |
35 | | - y = next_token(c) |
| 35 | + y = next_token(atok,c) |
36 | 36 | if y and y.type==token.STRING: |
37 | | - m.modify_from(timestamp,(c.startpos,c.endpos),"","fstring") |
| 37 | + m.modify_from(timestamp,(c.startpos,y.endpos),y.string,"fstring") |
38 | 38 | return m |
39 | 39 |
|
40 | 40 | def filter_everything(atok, m = None, timestamp = 0): |
41 | | - print(m) |
42 | 41 | m = m if m else ModificationHandler(atok.text) |
43 | | - print(" inside everything after initialization",m) |
44 | 42 | m = filter_asynchronous(atok,m, timestamp) |
45 | | - print("1",m) |
46 | 43 | m = filter_fstrings(atok,m, timestamp) |
47 | | - print("2",m) |
48 | 44 | m = filter_await(atok,m, timestamp) |
49 | | - print(m) |
50 | 45 | return m |
51 | 46 |
|
52 | 47 |
|
|
0 commit comments