Skip to content

Commit

Permalink
Make argument queries work with negative indices
Browse files Browse the repository at this point in the history
#38 for argument queries
  • Loading branch information
mpourmpoulis committed Aug 22, 2020
1 parent 635e9ae commit 0e1fd16
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions queries/argument.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,25 @@ class SelectArgument(SelectionQuery):

def get_information(self,query_description):
# print(self,query_description)
def decrement_positive(x):
return x-1 if x>0 else x

if "argument_index" in query_description:
if query_description["argument_index"]==0:
return make_information(get_argument_from_empty_call)
return make_information(get_argument_from_call,query_description["argument_index"]-1)
else:
return make_information(get_argument_from_call,decrement_positive(query_description["argument_index"]))
elif "keyword_index" in query_description:
return make_information(get_keyword_argument,query_description["keyword_index"]-1,only_keyword=True)
return make_information(get_keyword_argument,decrement_positive(query_description["keyword_index"]),only_keyword=True)
elif "keyword_value_index" in query_description:
return make_information(get_keyword_argument,query_description["keyword_value_index"]-1,only_value=True)
return make_information(get_keyword_argument,decrement_positive(query_description["keyword_value_index"]),only_value=True)
elif "entire_keyword_index" in query_description:
return make_information(get_keyword_argument,query_description["entire_keyword_index"]-1,only_keyword=False,only_value = False)
return make_information(get_keyword_argument,decrement_positive(query_description["entire_keyword_index"]),only_keyword=False,only_value = False)
elif "caller" in query_description:
if "sub_index" not in query_description:
return get_caller
else:
i = query_description["sub_index"] - 1
i = decrement_positive(query_description["sub_index"])
return lambda x:get_sub_index(get_caller(x),i)
else:
return identity(match_node,ast.Call)
Expand Down

0 comments on commit 0e1fd16

Please sign in to comment.