def testFieldDefaults(self): s = arith_ast.Slice() s.a = ArithVar('foo') self.assertEqual(None, s.begin) self.assertEqual(None, s.end) self.assertEqual(None, s.stride) print(s) func = arith_ast.FuncCall() func.name = 'f' self.assertEqual([], func.args) print(func)
def testFieldDefaults(self): s = arith_ast.Slice() s.a = ArithVar('foo') self.assertEqual(None, s.begin) self.assertEqual(None, s.end) self.assertEqual(None, s.stride) print(s) func = arith_ast.FuncCall() func.name = 'f' self.assertEqual([], func.args) print(func) t = arith_ast.token(5, 'x') self.assertEqual(5, t.id) self.assertEqual('x', t.value) self.assertEqual(const.NO_INTEGER, t.span_id)
def LeftIndex(p, token, left, unused_bp): """ index f[x+1] """ # f[x] or f[x][y] if not isinstance(left, arith_ast.ArithVar): raise tdop.ParseError("%s can't be indexed" % left) index = p.ParseUntil(0) if p.AtToken(':'): p.Next() end = p.ParseUntil(0) else: end = None p.Eat(']') # TODO: If you see ], then # 1:4 # 1:4:2 # Both end and step are optional if end: return arith_ast.Slice(left, index, end, None) else: return arith_ast.Index(left, index)