From 0e1fd16a3e286f9ffdd1e9c360e0c23813fe5885 Mon Sep 17 00:00:00 2001 From: mpourmpoulis <35875229+mpourmpoulis@users.noreply.github.com> Date: Sat, 22 Aug 2020 18:56:13 +0300 Subject: [PATCH] Make argument queries work with negative indices #38 for argument queries --- queries/argument.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/queries/argument.py b/queries/argument.py index 564bda2..6307bb2 100644 --- a/queries/argument.py +++ b/queries/argument.py @@ -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)