def arg_check(expected_type, args, a): if expected_type != args['pseudo_type'] and expected_type != 'Any' and not ( expected_type == 'Number' and (args['pseudo_type'] == 'Int' or args['pseudo_type'] == 'Float')): raise PseudoPythonTypeCheckError('%s expected %s not %s' % (a, serialize_type(expected_type), serialize_type(args['pseudo_type'])))
def or_(l, r): if l == 'Boolean' and r == 'Boolean': return 'Boolean' else: raise PseudoPythonTypeCheckError( "wrong types for or: %s and %s" % (serialize_type(l), serialize_type(r)))
def xor_(l, r): if l == r == 'Int' or l == r == 'Set': return l else: raise PseudoPythonTypeCheckError( "wrong types for ^: %s and %s" % (serialize_type(l), serialize_type(r)))
def mod(l, r): if l == 'Int' and r == 'Int': return [l, r, 'Int'] elif l == 'String' and (r == 'String' or r == ['Array', 'String']): return [l, ['Array', 'String'], 'String'] else: raise PseudoPythonTypeCheckError( "wrong types for %: %s and %s" % (serialize_type(l), serialize_type(r)))
def sub(l, r): if l == 'Float' and r in ['Float', 'Int' ] or r == 'Float' and l in ['Float', 'Int']: return [l, r, 'Float'] elif l == 'Int' and r == 'Int': return [l, r, 'Int'] else: raise PseudoPythonTypeCheckError( "wrong types for -: %s and %s" % (serialize_type(l), serialize_type(r)))
def add(l, r): if l == 'Float' and r in ['Float', 'Int' ] or r == 'Float' and l in ['Float', 'Int']: return [l, r, 'Float'] elif l == 'Int' and r == 'Int': return [l, r, 'Int'] elif l == 'String' and r == 'String': return [l, r, 'String'] elif isinstance(l, list) and l[0] == 'List' and l == r: return [l, r, l] else: raise PseudoPythonTypeCheckError( "wrong types for +: %s and %s" % (serialize_type(l), serialize_type(r)))
def mul(l, r): if l == 'Float' and r in ['Float', 'Int' ] or r == 'Float' and l in ['Float', 'Int']: return [l, r, 'Float'] elif l == 'Int' and r == 'Int': return [l, r, 'Int'] elif l == 'Int' and (isinstance(r, list) and r[0] == 'List' or r == 'String'): return [l, r, r] elif r == 'Int' and (isinstance(l, list) and l[0] == 'List' or l == 'String'): return [l, r, l] else: raise PseudoPythonTypeCheckError( "wrong types for *: %s and %s" % (serialize_type(l), serialize_type(r)))
def sub(l, r): if l == 'Float' and r in ['Float', 'Int'] or r == 'Float' and l in ['Float', 'Int']: return [l, r, 'Float'] elif l == 'Int' and r == 'Int': return [l, r, 'Int'] else: raise PseudoPythonTypeCheckError("wrong types for -: %s and %s" % (serialize_type(l), serialize_type(r)))
def mod(l, r): if l == 'Int' and r == 'Int': return [l, r, 'Int'] elif l == 'String' and (r == 'String' or r == ['Array', 'String']): return [l, ['Array', 'String'], 'String'] else: raise PseudoPythonTypeCheckError("wrong types for %: %s and %s" % (serialize_type(l), serialize_type(r)))
def decorated(data, location=None, code=None, wrong_type=None, **options): return exception('%s%s%s:\n%s\n%s^' % ( ('wrong type %s\n' % serialize_type(wrong_type) if wrong_type else ''), data, (' on line %d column %d' % location) if location else '', code or '', (tab_aware(location[1], code) if location else '')), **options)
def mul(l, r): if l == 'Float' and r in ['Float', 'Int'] or r == 'Float' and l in ['Float', 'Int']: return [l, r, 'Float'] elif l == 'Int' and r == 'Int': return [l, r, 'Int'] elif l == 'Int' and (isinstance(r, list) and r[0] == 'List' or r == 'String'): return [l, r, r] elif r == 'Int' and (isinstance(l, list) and l[0] == 'List' or l == 'String'): return [l, r, l] else: raise PseudoPythonTypeCheckError("wrong types for *: %s and %s" % (serialize_type(l), serialize_type(r)))
def add(l, r): if l == 'Float' and r in ['Float', 'Int'] or r == 'Float' and l in ['Float', 'Int']: return [l, r, 'Float'] elif l == 'Int' and r == 'Int': return [l, r, 'Int'] elif l == 'String' and r == 'String': return [l, r, 'String'] elif isinstance(l, list) and l[0] == 'List' and l == r: return [l, r, l] else: raise PseudoPythonTypeCheckError("wrong types for +: %s and %s" % (serialize_type(l), serialize_type(r)))
def decorated(data, location=None, code=None, wrong_type=None, **options): return exception( '%s%s%s:\n%s\n%s^' % (('wrong type %s\n' % serialize_type(wrong_type) if wrong_type else ''), data, (' on line %d column %d' % location) if location else '', code or '', (tab_aware(location[1], code) if location else '')), **options)
def arg_check(expected_type, args, a): if expected_type != args['pseudo_type'] and expected_type != 'Any' and not(expected_type == 'Number' and (args['pseudo_type'] == 'Int' or args['pseudo_type'] == 'Float')): raise PseudoPythonTypeCheckError('%s expected %s not %s' % (a, serialize_type(expected_type), serialize_type(args['pseudo_type'])))
def xor_(l, r): if l == r == 'Int' or l == r == 'Set': return l else: raise PseudoPythonTypeCheckError("wrong types for ^: %s and %s" % (serialize_type(l), serialize_type(r)))
def or_(l, r): if l == 'Boolean' and r == 'Boolean': return 'Boolean' else: raise PseudoPythonTypeCheckError("wrong types for or: %s and %s" % (serialize_type(l), serialize_type(r)))