Skip to content

Commit 7d9fbbb

Browse files
authored
Merge pull request #37 from mpourmpoulis/develop-0.1.0
Develop 0.1.3 first attempt
2 parents e105f65 + 8389c8b commit 7d9fbbb

29 files changed

+267
-261
lines changed

.pylintrc

+4
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,8 @@ init-hook="from pylint.config import find_pylintrc; import os, sys; sys.path.app
77

88
[MESSAGES CONTROL]
99
disable=all
10+
11+
12+
1013
enable=E
14+

Main.sublime-menu

+8-8
Original file line numberDiff line numberDiff line change
@@ -35,49 +35,49 @@
3535
"caption": "Argument Queries",
3636
"command": "open_url",
3737
"args":{
38-
"url": "http://github.com/mpourmpoulis/PythonVoiceCodingPlugin/blob/master/doc/SelectArgument.md"
38+
"url": "https://pythonvoicecodingplugin.readthedocs.io/en/latest/SelectArgument/"
3939
}
4040
},
4141
{
4242
"caption": "Big Roi Queries",
4343
"command": "open_url",
4444
"args":{
45-
"url":"https://github.com/mpourmpoulis/PythonVoiceCodingPlugin/blob/master/doc/SelectBigROI.md"
45+
"url":"https://pythonvoicecodingplugin.readthedocs.io/en/latest/SelectBigROI/"
4646
}
4747
},
4848
{
4949
"caption": "General Documentation",
5050
"command": "open_url",
5151
"args":{
52-
"url":"https://github.com/mpourmpoulis/PythonVoiceCodingPlugin/blob/master/doc/README.md"
52+
"url":"https://pythonvoicecodingplugin.readthedocs.io/en/latest/"
5353
}
5454
},
5555
{
5656
"caption": "Operations",
5757
"command": "open_url",
5858
"args":{
59-
"url": "https://github.com/mpourmpoulis/PythonVoiceCodingPlugin/blob/master/doc/Operations.md"
59+
"url": "https://pythonvoicecodingplugin.readthedocs.io/en/latest/Operations/"
6060
}
6161
},
6262
{
6363
"caption": "Sub Indexing",
6464
"command": "open_url",
6565
"args":{
66-
"url": "https://github.com/mpourmpoulis/PythonVoiceCodingPlugin/blob/master/doc/SubIndexing.md"
66+
"url": "https://pythonvoicecodingplugin.readthedocs.io/en/latest/SubIndexing/"
6767
}
6868
},
6969
{
7070
"caption": "CollectionQueries",
7171
"command": "open_url",
7272
"args":{
73-
"url": "https://github.com/mpourmpoulis/PythonVoiceCodingPlugin/blob/master/doc/CollectionQueries.md"
73+
"url": "https://pythonvoicecodingplugin.readthedocs.io/en/latest/CollectionQueries/"
7474
}
7575
},
7676
{
7777
"caption": "Unofficial",
7878
"command": "open_url",
7979
"args":{
80-
"url": "https://github.com/mpourmpoulis/PythonVoiceCodingPlugin/blob/master/doc/README.md#experiment-or-unofficial-and-so-on-features-you-need-to-enable-manually"
80+
"url": "https://pythonvoicecodingplugin.readthedocs.io/en/latest/#experiment-or-unofficial-and-so-on-features-you-need-to-enable-manually"
8181
}
8282
}
8383

@@ -125,7 +125,7 @@
125125
"caption": "Grammar Installation Doc",
126126
"command": "open_url",
127127
"args":{
128-
"url": "https://github.com/mpourmpoulis/PythonVoiceCodingPlugin/blob/master/bundles/README.md"
128+
"url": "https://pythonvoicecodingplugin.readthedocs.io/en/latest/Installation/"
129129
}
130130
},
131131
{

application/application.py

+3
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,12 @@ def __init__(self,vid):
3030
self.ui_controller = None
3131
self.vid = vid
3232

33+
@staticmethod
3334
def create_application_for_view(vid):
3435
if vid not in Application.active_applications:
3536
Application.active_applications[vid] = Application(vid)
3637

38+
@staticmethod
3739
def get_application(vid):
3840
Application.create_application_for_view(vid)
3941
return Application.active_applications[vid]
@@ -77,6 +79,7 @@ def respond_to_query(self,interface,query_description,secondary=False):
7779
except Exception as e:
7880
# check if there are exceptions with parsing
7981
if s.exceptions_raised:
82+
# traceback.print_tb(s.exceptions_raised)
8083
interface.clear_actions()
8184
interface.push_action(PopUpErrorAction(str(s.exceptions_raised)))
8285
return False

bundles/Caster/python_voice_coding_plugin_caster_v0-5-11.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737

3838
#########################################################################################
3939

40-
GRAMMAR_VERSION = (0,1,2)
40+
GRAMMAR_VERSION = (0,1,3)
4141

4242
#########################################################################################
4343

bundles/Caster/python_voice_coding_plugin_caster_v0-6-11.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737

3838
#########################################################################################
3939

40-
GRAMMAR_VERSION = (0,1,2)
40+
GRAMMAR_VERSION = (0,1,3)
4141

4242
#########################################################################################
4343

bundles/Caster/python_voice_coding_plugin_caster_v1-0-0.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737

3838
#########################################################################################
3939

40-
GRAMMAR_VERSION = (0,1,2)
40+
GRAMMAR_VERSION = (0,1,3)
4141

4242
#########################################################################################
4343

interface/common/actions.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -232,10 +232,11 @@ class PopUpErrorAction(InterfaceAction):
232232
"""docstring for DisplayErrorAction"""
233233
def __init__(self, text):
234234
self.text = text
235+
235236
def execute(self,view,settings, sublime,**kwargs):
236237
if not settings.get("show_error",False):
237238
return
238-
final_text = "<p></p><h>Something is off!</h>" + "<p>" + html.escape(self.text) + "</p>"
239+
final_text = "<p></p><h>Something is off!</h>" + "<p>" + html.escape(self.text,quote = False) + "</p>"
239240
def on_hide():
240241
view.show_popup(final_text,max_width=1024, max_height=10000, flags= sublime.HIDE_ON_MOUSE_MOVE_AWAY)
241242
view.show_popup(final_text,max_width=1024, max_height=10000,

library/LCA.py

+6-3
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def visit(self, node):
3737
def get_depth(self, node):
3838
return self.sequence[self.visits[node][0]][0]
3939

40-
def __call__(self,first_node,second_node,include_depth = False):
40+
def __call__(self,first_node,second_node,only_depth = False,node_and_depth = True):
4141
try :
4242
x,y = self.visits[first_node]
4343
w,v = self.visits[second_node]
@@ -52,9 +52,12 @@ def __call__(self,first_node,second_node,include_depth = False):
5252
r = max(y,v)
5353

5454
ancestor = self.tree.query(l,r,"min")
55-
if include_depth:
55+
if node_and_depth:
56+
return ancestor
57+
elif only_depth:
5658
return ancestor[0]
57-
return ancestor[1]
59+
else:
60+
return ancestor[1]
5861

5962
def get_field_with_respect_to(self,node,parent_node):
6063
index = bisect.bisect_left(self.field_history[parent_node],(self.visits[node][0],))

library/info.py

+29-16
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,9 @@ def fake_attribute_from_tokens(root,tokens,**kwargs):
129129

130130
def is_store(root):
131131
return match_node(root,ast.Store) or (match_node(root,ast.Name) and match_node(root.ctx,ast.Store))
132+
132133
def single(root):
133-
return match_parent(node,(),ast.Attribute)
134+
return match_parent(root,(),ast.Attribute)
134135

135136
def name(root):
136137
return match_node(root,ast.Name)
@@ -207,8 +208,6 @@ def get_weak_header(root,atok):
207208
root.items if match_node(root,(ast.With)) else
208209
root.type if match_node(root,(ast.ExceptHandler)) else None
209210
)
210-
def get_body(root):
211-
return root.body if match_node(root,(ast.IfExp, ast.If ,ast.For,ast.While, ast.Try)) else None
212211

213212

214213

@@ -255,12 +254,12 @@ def get_return_value(root):
255254
# need to revisit
256255
def get_elements(root):
257256
return (
258-
root.elts if hasattr(root,elts) else None
257+
root.elts if hasattr(root,"elts") else None
259258
)
260259

261260
def get_context(root):
262261
return (
263-
root.ctx if hasattr(root,ctx) else None
262+
root.ctx if hasattr(root,"ctx") else None
264263
)
265264

266265
def get_key_value(root):
@@ -321,6 +320,17 @@ def get_container_check(root):
321320
def get_membership(root):
322321
return root if match_node(root,ast.Compare) and all([match_node(x,(ast.In,ast.NotIn)) for x in root.ops]) else None
323322

323+
324+
# Extracting Identity Left And Right
325+
def get_identity_check_left(root):
326+
return root.left if match_node(root,ast.Compare) and all([match_node(x,(ast.Is,ast.IsNot)) for x in root.ops]) else None
327+
328+
def get_identity_check_right(root):
329+
return root.comparators[-1] if match_node(root,ast.Compare) and all([match_node(x,(ast.Is,ast.IsNot)) for x in root.ops]) else None
330+
331+
def get_identity_check(root):
332+
return root if match_node(root,ast.Compare) and all([match_node(x,(ast.Is,ast.IsNot)) for x in root.ops]) else None
333+
324334
# Extract Left Middle And Right from numerical comparisons
325335
def get_comparison_left_side(root):
326336
return root.left if match_node(root,ast.Compare) else None
@@ -667,28 +677,29 @@ def get_subparts_of_string(root,name_mode = False):
667677
start_position = 1
668678
if not check_fake(root):
669679
x = root.first_token.string
670-
# print("String:\n",x)
671680
y1 = x.find("'")
672681
y2 = x.find("\"")
673682
if y1>=0 and y2>=0:
674-
z = mean(y1,y2)
683+
z = min(y1,y2)
675684
elif y1>=0:
676685
z = y1
677686
elif y2>=0:
678687
z = y2
679688
else:
680689
raise Exception("problem with splitting a string , there is no beginning!")
690+
try :
691+
if x[z]==x[z+1]==x[z+2]:
692+
z = z + 2
693+
except :
694+
pass
681695
start_position += z
682696
start_position += root.first_token.startpos
683-
# print("Start Position:\n",start_position)
684-
# start_position = root.first_token.startpos + ( 1+(len(root.first_token.string) if root.first_token.type==tokenize.NAME else 0) if not name_mode else 0)
685697
original = root.s if not name_mode else root.id
686698
try :
687699
splitted = split_string(root.s if not name_mode else root.id,even_letters = False if name_mode else True)
688700
except :
689701
print(" exceptions were thrown")
690702
index = 0
691-
print("splitted ",splitted)
692703
for s in splitted:
693704
if not s:
694705
continue
@@ -881,12 +892,11 @@ def get_raw(root):
881892

882893
def correspond_to_index_in_call(root, index,field,field_index):
883894
x = get_argument_from_call(root,index)
884-
print("entering index taking \n",ast.dump(x))
885895
if not x:
886896
return False
887897
if x.parent_field=="value":
888898
x = x.parent
889-
print("inside checking for index ",(x.parent_field,x.parent_field_index),(field,field_index))
899+
# print("inside checking for index ",(x.parent_field,x.parent_field_index),(field,field_index))
890900
return (field, field_index)==(x.parent_field,x.parent_field_index) if x else False
891901

892902

@@ -1016,6 +1026,9 @@ def fix_alias(root,atok):
10161026
def fix_argument(root,atok,token = None):
10171027
if already_fixed(root):
10181028
return token
1029+
# the following check was introduced to work around issue #17
1030+
if not match_node(root.parent.parent,ast.FunctionDef):
1031+
return None
10191032
if token is None:
10201033
fix_definition(root.parent.parent,atok)
10211034
if not already_fixed(root):
@@ -1037,15 +1050,14 @@ def fix_argument(root,atok,token = None):
10371050
def fix_argument_list(root,atok):
10381051
if not match_node(root,ast.arguments):
10391052
return False
1040-
if already_fixed(root) or fix_definition(root.parent,atok):
1053+
if already_fixed(root) or match_node(root.parent,(ast.FunctionDef)) and fix_definition(root.parent,atok):
10411054
return True
10421055
return False
10431056

10441057

10451058
def fix_definition(root,atok):
10461059
if already_fixed(root):
10471060
return True
1048-
10491061
# there is a discrepancy between the 3.3 and 3.4 versions of the abstract syntax tree
10501062
# in 3.3 the variable arguments and the variable keyboard arguments are stored in a little bit differently
10511063
x = root.args
@@ -1116,12 +1128,13 @@ def fix_exception_handler(root,atok):
11161128
if not root.type or not root.name:
11171129
mark_fixed(root)
11181130
return True
1119-
print("Exception Handler:\n",[root.first_token,root.last_token])
1131+
11201132
token = root.type.last_token
11211133
token = atok.find_token(next_token(atok,token),tokenize.NAME, root.name)
11221134
f = root.type.first_token
11231135
f = atok.find_token(previous_token(atok,f),tokenize.NAME, "except",reverse = True)
1124-
fake_name_node = create_fake(root,ast.Name,real_tokens = token,id = token.string,ctx = ast.Load())
1136+
fake_name_node = create_fake(root,ast.Name,real_tokens = token,id = token.string,ctx = ast.Load(),
1137+
parent = root,parent_field = "name")
11251138
set_fake(root,"name",fake_name_node)
11261139
# root.first_token=root.type.first_token
11271140
# root.last_token = token

library/modification.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def add_modification_from(self,timestamp, origin, destination,original_code =
5858
return self.add_modification(origin, destination, original_code, destination_code,comment)
5959

6060
def add_modification_updated(self, origin, destination,original_code = None,destination_code = "", comment= None):
61-
return add_modification_from(self.current_time, origin, destination,original_code ,destination_code , comment)
61+
return self.add_modification_from(self.current_time, origin, destination,original_code ,destination_code , comment)
6262

6363

6464

library/repair.py

+13-5
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ def get_dummy(atok):
1818

1919
def neighbors(atok,t):
2020
x = next_token(atok,t)
21+
x = x if x and x.type != 0 else None
2122
y = next_token(atok,x) if x else None
2223
z = previous_token(atok,t)
2324
w = previous_token(atok,z) if z else None
@@ -92,15 +93,15 @@ def finish_atom(t):
9293
def before_star(t):
9394
# of these does not check all cases
9495
return t[-1] is None or not (
95-
finish_atom(t[-1]) or t[-1].string in ["(","[","{",",","import","for"] or t[-1].type in [token.INDENT]
96+
finish_atom(t[-1]) or t[-1].string in ["(","[","{",",","import","for","lambda"] or t[-1].type in [token.INDENT]
9697
)
9798

9899

99100
def after_star(t):
100101
# of these does not check all cases
101102
return t[1] is None or not (
102103
start_atom(t[1]) or t[-1] is not None and (
103-
(t[-1].string,t[1].string) in [('(',','),(',',","),(",",")")] or
104+
# (t[-1].string,t[1].string) in [('(',','),(',',","),(",",")")] or
104105
t[-1].string in ["import"]
105106

106107
)
@@ -123,7 +124,7 @@ def after_both_sides(t):
123124
return t[1] is None or not(
124125
start_atom(t[1]) or
125126
t[1].string in STARTING_UNARY or
126-
(t[1].string,t[2].string) in STARTING_UNARY
127+
(t[2] is not None and (t[1].string,t[2].string) in STARTING_UNARY)
127128
)
128129

129130
def before_both_sides(t):
@@ -151,7 +152,7 @@ def after_unary(t):
151152
def after_comma(t):
152153
return t[1] is None or t[1].string ==","
153154
def before_comma(t):
154-
return t[ -1] is None or t[-1].string in ["(","[","{"]
155+
return t[ -1] is None or t[-1].string in ["(","[","{","lambda"]
155156

156157
def after_bracket(t):
157158
return t[1] is None or t[1].string in ["for","if","while","with"] or (
@@ -168,7 +169,13 @@ def after_double_dot(t):
168169
return t[1] is None or not(
169170
start_atom(t[1]) or
170171
t[1].string.isspace() or
171-
t[1].string=="]"
172+
t[1].string in [
173+
"]","assert","raise"
174+
"break","continue","pass",
175+
"return","yield","await","del",
176+
"global","nonlocal",
177+
"import","from"
178+
]
172179
)
173180

174181
def before_double_dot(t):
@@ -208,6 +215,7 @@ def after_else(t):
208215
start_atom(t[1]) or t[1].string in [":"]
209216
)
210217
'''
218+
211219
def handle_empty_compound(atok ,t,l,b,dummy):
212220
n = neighbors(atok, t)
213221
left,right = expand_to_line_or_statement(atok,t, l, b)

0 commit comments

Comments
 (0)