Skip to content

Commit 3cb4002

Browse files
committed
Support for all the various Boolean left arithmetic left and so on subscript and so on
1 parent 9ce993d commit 3cb4002

File tree

2 files changed

+81
-0
lines changed

2 files changed

+81
-0
lines changed

library/info.py

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,13 @@ def get_with_items(root):
284284
root.items if match_node(root,ast.With) else None
285285
)
286286

287+
#########################################################################
288+
# stuff for small regions
289+
#########################################################################
290+
291+
# Extracting things from subscript
292+
def get_subscript_body(root):
293+
return root.value if match_node(root,ast.Subscript) else None
287294

288295
def get_subscript_key(root):
289296
return (
@@ -325,8 +332,66 @@ def get_comparison_middle(root):
325332
return root.comparators[0] if match_node(root,ast.Compare) and len(root.comparators)==2 else None
326333

327334

335+
# Extract Left Middle and Right from arithmetical operations
336+
def get_arithmetic_left(root):
337+
if not match_node(root,ast.BinOp):
338+
return None
339+
items = get_sub_index(root,None)
340+
if len(items)>=1:
341+
return items[0]
342+
return None
343+
344+
def get_arithmetic_right(root):
345+
if not match_node(root,ast.BinOp):
346+
return None
347+
items = get_sub_index(root,None)
348+
if len(items)>=2:
349+
return items[-1]
350+
return None
351+
352+
def get_arithmetic_middle(root):
353+
if not match_node(root,ast.BinOp):
354+
return None
355+
items = get_sub_index(root,None)
356+
if len(items)==3:
357+
return items[1]
358+
return None
359+
360+
361+
# Extract Left Middle Right from Boolean expressions
362+
363+
def get_boolean_left(root):
364+
if not match_node(root,ast.BoolOp):
365+
return None
366+
items = root.values
367+
if len(items)>=1:
368+
return items[0]
369+
return None
370+
371+
def get_boolean_right(root):
372+
if not match_node(root,ast.BoolOp):
373+
return None
374+
items = root.values
375+
if len(items)>=2:
376+
return items[-1]
377+
return None
378+
379+
def get_boolean_middle(root):
380+
if not match_node(root,ast.BoolOp):
381+
return None
382+
items = root.values
383+
if len(items)==3:
384+
return items[1]
385+
return None
386+
387+
def get_boolean_and(root):
388+
return root if match_node(root,ast.BoolOp) and match_node(root.op,ast.And) else None
389+
328390

391+
def get_boolean_or(root):
392+
return root if match_node(root,ast.BoolOp) and match_node(root.op,ast.Or) else None
329393

394+
##########################################################################
330395
# need to revisit this
331396
def get_body(root):
332397
return (

queries/big_roi.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,14 +109,19 @@ def standard(x):
109109
"set":((ast.Set),(),standard),
110110
"tuple":((ast.Tuple),(),standard),
111111
"list":((ast.List),(),standard),
112+
113+
"subscript":((ast.Subscript),(),standard),
114+
"subscript body":((ast.Subscript),(),get_subscript_body),
112115
"key":((ast.Subscript),(),get_subscript_key),
113116
"lower":((ast.Slice),(),get_slice_lower),
114117
"upper":((ast.Slice),(),get_slice_upper),
115118
"step":((ast.Slice),(),get_slice_step),
119+
116120
"attribute":((ast.Attribute),(),standard),
117121
"comparison":((ast.Compare),(),standard),
118122
"arithmetic":((ast.BinOp),(),standard),
119123
"boolean":((ast.BoolOp),(),standard),
124+
120125
"container":((ast.Compare),(),get_container_check),
121126
"member":((ast.Compare),(),get_member_check),
122127
"membership":((ast.Compare),(),get_membership),
@@ -125,6 +130,17 @@ def standard(x):
125130
"right side":((ast.Compare),(),get_comparison_right_side),
126131
"middle":((ast.Compare),(),get_comparison_middle),
127132

133+
"arithmetic left":((ast.BinOp),(),get_arithmetic_left),
134+
"arithmetic right":((ast.BinOp),(),get_arithmetic_right),
135+
"arithmetic middle":((ast.BinOp),(),get_arithmetic_middle),
136+
137+
"boolean left":((ast.BoolOp),(),get_boolean_left),
138+
"boolean right":((ast.BoolOp),(),get_boolean_right),
139+
"boolean middle":((ast.BoolOp),(),get_boolean_middle),
140+
141+
"boolean and":((ast.BoolOp),(),get_boolean_and),
142+
"boolean or":((ast.BoolOp),(),get_boolean_or),
143+
128144

129145

130146
}

0 commit comments

Comments
 (0)