Skip to content

Commit ceeacea

Browse files
committed
Preparing for 0.0.1
1 parent 398b8d8 commit ceeacea

File tree

9 files changed

+102
-33
lines changed

9 files changed

+102
-33
lines changed

README.md

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
[![License](https://img.shields.io/badge/License-BSD%202--Clause-orange.svg)](https://opensource.org/licenses/BSD-2-Clause)
44

5-
![]( https://img.shields.io/static/v1?label=Caster&message=0.5.11&color=blue )
5+
![]( https://img.shields.io/static/v1?label=Caster&message=0.5.11&color=blue)
6+
7+
![]( https://img.shields.io/static/v1?label=Version&message=0.0.1&color=green)
68

79
PythonVoiceCodingPlugin is a Sublime Text 3 plugin meant to enhance user experience
810
when coding python 3 by voice.
@@ -20,7 +22,7 @@ need to be taken to get there. What if you could instead simply describe (syntac
2022
![](doc/gif/big3.gif)
2123

2224
PythonVoiceCodingPlugin tries to enable you to do just that!
23-
To provide this functionality, it ships with bundles the implement a grammar, hopefully expressive enough for describing regions of interest, while running on the voice coding macro system side and
25+
To provide this functionality, it ships with bundles the implement a grammar, hopefully expressive enough for describing regions of interest, while running on the voice coding macro system side. These bundles
2426
cooperate with the core plugin, running on the editor side, arguably the more suitable of the two environments
2527
for analyzing source code and decoding the meaning of queries within the given context.
2628

@@ -59,7 +61,8 @@ Needless to say, while coding PythonVoiceCodingPlugin , PythonVoiceCodingPlugin
5961

6062
The code is available on [github](https://github.com/mpourmpoulis/PythonVoiceCodingPlugin)
6163
along with its initial release (0.0.0)!
62-
64+
65+
Update:
6366

6467

6568

@@ -140,9 +143,11 @@ So effectively we trigger the command our plugin provides in its top file and pa
140143

141144
Of course this does not work across virtual machine barriers:)
142145

143-
to counter this issue the simplest idea, which involves only keystrokes, is to open with some key command sublime console and using a text command to invoke the PythonVoiceCodingPlugin command from the command line. But
144-
This is often way to slow if there are a lot of parameters to pass and messes up with user-interface.
145-
so this is not implemented, even though it does not need custom rpc.
146+
To counter this issue the simplest idea, which involves only keystrokes, is to open with some key command sublime console and using a text command to invoke the PythonVoiceCodingPlugin command from the command line. But
147+
from my experience this is often way to slow if there are a lot of parameters to pass and messes up with user-interface, as it opens up the console.
148+
149+
So this is not implemented, even though it does not need custom rpc.
150+
146151

147152
For the time being I have bundles for 0.5.11 release of Caster that work as expected on Windows 10 64bit.
148153

doc/SelectBigROI.md

Lines changed: 41 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Select Big Region of Interest Command
22

3-
These commands are responsible for selecting "big" regions of interest. By "big" we refer to things like "if condition" or "assignment right" in contrast to say the first entry of a dictionary.
3+
These commands are responsible for selecting "big" regions of interest. By "big" we refer to things like "if condition" or "assignment right" in contrast to say the first entry of a dictionary, though we will see later, by means of subindexes we can select [smaller stuff!](#SubIndexes)
44

55
![](./gif/big2.gif)
66

@@ -13,7 +13,7 @@ Choice("big_roi",{
1313
"else if condition" : "else if condition",
1414
"while condition" : "while condition",
1515

16-
"if expression condition" : "if´´ expression condition",
16+
"if expression condition" : "if expression condition",
1717
"if expression body" : "if expression body",
1818
"if expression":"if expression",
1919

@@ -64,16 +64,8 @@ As you might expect, the plugin will try to find matches to big roi description
6464

6565
![](./gif/big1.gif)
6666

67-
However,there are cases where you are interested in only a portion of this whole ROI. For instance there may be multiple targets in the left hand of an assignment and you want to select only one of them. Or your function may return multiple values. In those cases the
67+
t is also important to note that with exception of the import statements, all other queries search only within the current function.
6868

69-
```python
70-
IntegerRefST("big_roi_sub_index",0,10),
71-
```
72-
comes in useful:
73-
74-
![](./gif/big2.gif)
75-
76-
it is also important to note that with exception of the import statements, all other queries search only within the current function.
7769

7870
# Case two
7971

@@ -148,3 +140,41 @@ Once we have established which function we are to search, the command will then
148140
but will search inside that function!
149141

150142
![](./gif/big5.gif)
143+
144+
# SubIndexes
145+
146+
So far we have seen cases where we can select an entire region of interest.
147+
However,there are cases where you are interested in only a portion of this whole ROI. For instance there may be multiple targets in the left hand of an assignment and you want to select only one of them. Or your function may return multiple values. In those cases the
148+
149+
```python
150+
IntegerRefST("big_roi_sub_index",0,10),
151+
```
152+
comes in useful:
153+
154+
155+
![](./gif/big2.gif)
156+
157+
Okay , can we do something similar for other cases? like select only a portion of an if condition?
158+
159+
![](./gif/big6.gif)
160+
161+
As illustrated above, you need to pay attention to how the various conditions are bound together
162+
(or binds weaker causing it to be higher in the AST) in the can only select smaller conditions from the outermost level!
163+
164+
This feature existed ever since the initial release but was only documented on 0.0.1 . This release also expanded the feature from applying only to ast.BoolOp nodes to encompass ast.Compare nodes as well! in plain English:
165+
166+
![](./gif/big7.gif)
167+
168+
furthermore, big_roi_sub_index can make our lives easier even in cases like the one below:
169+
170+
![](./gif/big8.gif)
171+
172+
where we want to play with the indexes of a subscript!
173+
174+
Finally, we clarify one more thing! What about relative vertical offsets when using above? We know that these abstract vertical keywords only count interesting lines, but what do we count as interesting here? To stay compatible with all of the above, we count all lines containing our desired big region of interest regardless of whether we can extract or not from them information with the sub index! As an example:
175+
176+
![](./gif/big9.gif)
177+
178+
179+
180+

doc/gif/big7.gif

151 KB
Loading

doc/gif/big8.gif

272 KB
Loading

doc/gif/big9.gif

297 KB
Loading

library/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ def build_tree(code : str):
1414
return root,atok
1515

1616
def get_source_region(atok, element):
17+
if element is None:
18+
return None
1719
if isinstance(element,ast.AST):
1820
return atok.get_text_range(element)
1921
else:

library/repair.py

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -149,44 +149,50 @@ def after_bracket(t):
149149

150150

151151
def before_dot(t):
152-
# return t[ - 1] is None or not t[-1].string in ["from",".","import"]
152+
return t[ - 1] is None or not (
153+
t[-1].string in ["from",".","import"] or
154+
finish_atom(t[-1])
155+
)
153156
return False
154157

155158
def after_dot(t):
156-
# return t[1] is None or not (
157-
# t[1].string in ["."] and
158-
# t[-1] is not None and
159-
# t[-1].string in ["from",".","import"]
160-
# )
159+
return t[1] is None or not (
160+
start_atom(t[1]) or (
161+
t[1].string in ["."] and
162+
t[-1] is not None and
163+
t[-1].string in ["from",".","import"]
164+
)
165+
)
161166
return False
162167

163168
def handle_empty_compound(atok ,t,l,b,dummy):
164169
n = neighbors(atok, t)
165170
left,right = expand_to_line_or_statement(atok,t, l, b)
166171
if token.DEDENT==left.type:
167172
left = next_token(atok,left)
168-
# print("empty compound ",left,right)
169-
if t.string=="elif":
173+
print("empty compound ",[left,right])
174+
if t.string=="elif" and left.string!="elif":
170175
left = next_token(atok,left)
171176
if left is t and right.string == ":" :
172177
rh = next_token(atok,right)
173178
# print("rh is",[rh])
174-
while rh and (rh.line.isspace() or rh.line == right.line):
179+
while rh and (rh.line.isspace() or rh.start[0]==right.start[0]):
175180
# print("rh is",[rh])
176181
rh = next_token(atok, rh)
177182
temporary = left.line
178183
ls = temporary[:len(temporary) - len(temporary.lstrip())]
179184
temporary = rh.line if rh else ""
180185
rs = temporary[:len(temporary) - len(temporary.lstrip())]
181-
# (print("\nstarting new variation\n",[t],"\n",ls,rs,"these are the indentations",len(ls),len(rs),[left,rh]))
186+
(print("\nstarting new variation\n",[t],"\n",ls,rs,"these are the indentations",len(ls),len(rs),[left,rh]))
182187
if len(ls)>=len(rs):
183188
return True , right.endpos," pass ", False
184189
else:
185190
return (False,)
186-
elif t.string=="if" and right is t:
187-
return True , right.endpos, " " + dummy + " else " + dummy,True
188-
else:
189191

192+
# these needs to be updated
193+
elif t.string=="if" and right is t:
194+
return True , right.endpos, " " + dummy + " else " + dummy,True
195+
else:
190196
return (False,)
191197

192198

queries/big_roi.py

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,30 @@ def modified_information(x, information,index):
8484
elif match_node(data,(ast.BoolOp)) :
8585
if index<len(data.values):
8686
return data.values[index]
87+
elif match_node(data,(ast.Compare)) :
88+
temporary = [data.left] + data.comparators
89+
if index<len(temporary):
90+
return temporary[index]
91+
92+
elif match_node(data,(ast.Subscript)):
93+
data = data.slice
94+
if match_node(data,(ast.Index)):
95+
temporary = [data.value]
96+
if match_node(data.value,(ast.List,ast.Tuple,ast.Set)):
97+
temporary = data.value.elts
98+
elif match_node(data,(ast.Slice)):
99+
temporary = [data.lower,data.upper, data.step]
100+
elif match_node(data,(ast.ExtSlice)):
101+
temporary = data.dims
102+
temporary = [x for x in temporary if x]
103+
if index<len(temporary):
104+
return temporary[index]
105+
87106
else:
88107
return None
89-
return (temporary[0],temporary[1], lambda x: modified_information(x,temporary[2],index-1))
108+
y = lambda x: temporary[2](x)
109+
y.secondary = lambda x: modified_information(x,temporary[2],index-1)
110+
return (temporary[0],temporary[1],y)
90111

91112

92113
def case_one(self,view_information,query_description, extra = {}):
@@ -95,6 +116,7 @@ def case_one(self,view_information,query_description, extra = {}):
95116
###############################################################
96117
build, selection, origin, definition_node = self.preliminary(view_information, query_description,extra)
97118
targets, exclusions, information = self.decode(query_description)
119+
information = getattr(information,"secondary",information)
98120
candidates = tiebreak_on_lca(definition_node,origin,find_all_nodes(definition_node, targets, exclusions))
99121
candidates = [information(x) for x in candidates if information(x)]
100122
result, alternatives = obtain_result(None, candidates)
@@ -123,6 +145,7 @@ def case_two(self,view_information,query_description, extra = {}):
123145
information_nodes = find_matching(definition_node,temporary_information),
124146
**additional_parameters
125147
)
148+
information = getattr(information,"secondary",information)
126149
result = information(result) if result else None
127150
alternatives =[ information(x) for x in alternatives] if alternatives else []
128151
return self._backward_result(result, alternatives,build)
@@ -149,6 +172,7 @@ def case_three(self,view_information,query_description, extra = {}):
149172
alternatives = tiebreak_on_lca(new_definition_node,result,find_all_nodes(new_definition_node,targets , exclusions))
150173

151174
result, alternatives = obtain_result(result, alternatives)
175+
information = getattr(information,"secondary",information)
152176
result = information(result) if result else None
153177
alternatives = [information(x) for x in alternatives] if alternatives else []
154178
return self._backward_result(result, alternatives,build)
@@ -170,6 +194,7 @@ def case_four(self,view_information,query_description, extra = {}):
170194

171195
t = decode_abstract_vertical(root,atok,targets,row, ndir + bonus,direction,True,temporary_information)
172196
if query_description["adjective"]=="None":
197+
information = getattr(information,"secondary",information)
173198
candidates = tiebreak_on_lca(root,definition_node,find_all_nodes(t, targets, exclusions))
174199
candidates = [information(x) for x in candidates if information(x)]
175200
result, alternatives = obtain_result(None, candidates)
@@ -184,6 +209,7 @@ def case_four(self,view_information,query_description, extra = {}):
184209
information_nodes = find_matching(t,lambda x: information(x) if match_node(x,targets,exclusions) else None),
185210
**additional_parameters
186211
)
212+
information = getattr(information,"secondary",information)
187213
result = information(result) if result else None
188214
alternatives =[ information(x) for x in alternatives] if alternatives else []
189215
return self._backward_result(result, alternatives,build)

queries/strategies/obtain.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
def obtain_result(result, alternatives):
22
if result:
3-
return result, alternatives if alternatives is not None else []
3+
return result, [x for x in alternatives if x is not result] if alternatives is not None else []
44
else:
55
if alternatives is None or len( alternatives )==0:
66
return None,None
77
else:
8-
return alternatives[0], alternatives[1:]
8+
return alternatives[0], [x for x in alternatives[1:] if x is not alternatives[0]]
99

1010
# bug if result is in alternatives

0 commit comments

Comments
 (0)