예제 #1
0
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'])))
예제 #2
0
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)))
예제 #3
0
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)))
예제 #4
0
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)))
예제 #5
0
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)))
예제 #6
0
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)))
예제 #7
0
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)))
예제 #10
0
 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)
예제 #11
0
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)))
예제 #12
0
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)))
예제 #13
0
 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)
예제 #14
0
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'])))
예제 #15
0
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)))
예제 #16
0
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)))