+# identify SelectableInt pattern
+def identify_sint_mul_pattern(p):
+ if not isinstance(p[3], ast.Constant):
+ return False
+ if not isinstance(p[1], ast.List):
+ return False
+ l = p[1].elts
+ if len(l) != 1:
+ return False
+ elt = l[0]
+ return isinstance(elt, ast.Constant)
+
+def apply_trailer(atom, trailer):
+ if trailer[0] == "TLIST":
+ # assume depth of one
+ atom = apply_trailer(atom, trailer[1])
+ trailer = trailer[2]
+ if trailer[0] == "CALL":
+ #p[0] = ast.Expr(ast.Call(p[1], p[2][1], []))
+ return ast.Call(atom, trailer[1], [])
+ # if p[1].id == 'print':
+ # p[0] = ast.Printnl(ast.Tuple(p[2][1]), None, None)
+ # else:
+ # p[0] = ast.CallFunc(p[1], p[2][1], None, None)
+ else:
+ print("subscript atom", trailer[1])
+ #raise AssertionError("not implemented %s" % p[2][0])
+ subs = trailer[1]
+ if len(subs) == 1:
+ idx = subs[0]
+ else:
+ idx = ast.Slice(subs[0], subs[1], None)
+ return ast.Subscript(atom, idx, ast.Load())
+