Example #1
0
    def call(self, obj, args):
        arrayType = type(None)
        isArgArray = _isType(args, RocketArray)
        nin_lexeme = obj.KSL[1][_TokenType.NIN.value]

        if isArgArray:
            arrayType = args.arrayType

        else:
            arrayType = type(args[0])

        # if a single arg is given we assume it to be the size of the Array
        if len(args) == 1 and not (isArgArray):
            if _isType(args[0], _number.RocketInt):
                arrayType = type(None)

                return RocketArray([None for i in range(args[0].value)],
                                   arrayType, nin_lexeme)

            else:
                raise _RuntimeError("Array', 'Array size must be Int.")

        if len(args) > 1 and not (isArgArray):
            # Check that all elms are of the same type
            if not _isAllSameType(args, arrayType):
                raise _RuntimeError('Array',
                                    "Array elements must be adjacent types.")

        return RocketArray(args, arrayType,
                           nin_lexeme) if not isArgArray else args
Example #2
0
def isNumber(n):
    if hasattr(n, 'value'):
        if (_isType(n, _string.RocketString)):
            return not (n.value.isalnum() and n.value.isalpha())

        return _isType(n, RocketInt) or _isType(n, RocketFloat)

    return _isType(n, int) or _isType(n, float)
Example #3
0
            def call(interpreter, args):
                if _isType(args[0], _number.RocketInt):
                    for i in range(len(self.elements)):
                        self.elements[i] = args[0]

                    return self

                else:
                    raise _RuntimeError(self, "Expected an Int.")
Example #4
0
    def call(self, obj, args):
        if isNumber(args[0]):
            value = args[0]

            if (hasattr(args[0], 'value')):
                value = args[0].value

            return RocketInt(int(float(value)) if _isType(args[0], _string.RocketString) else int(value))

        raise _RuntimeError(obj, f"Type Mismatch: Cannot convert {args[0].kind} to Int.")
Example #5
0
    def stringify(self, elm, uncoloured=False):
        if (_isType(elm, RocketArray) or _isType(elm, _list.RocketList)):
            return elm.__str__()

        if (_isType(elm, _number.RocketInt)
                or _isType(elm, _number.RocketFloat)):
            return f'\033[36m{elm}\033[0m' if not uncoloured else str(
                elm.value)

        if _isType(elm, _string.RocketString):
            return f'\033[32m{elm}\033[0m' if not uncoloured else elm.value

        if _isType(elm, _boolean.Bool):
            return f'\033[1m{elm}\033[0m' if not uncoloured else str(elm.value)

        if type(elm) == type(None):
            return '\033[1m' + self.nin_lexeme + '\033[0m' if not uncoloured else self.nin_lexeme
Example #6
0
 def isRocketBool(self, obj):
     return _isType(obj, _rocketBoolean.RocketBool)
Example #7
0
 def isRocketNumber(self, obj):
     return _isType(obj, _rocketNumber.RocketFloat) or _isType(
         obj, _rocketNumber.RocketInt)
Example #8
0
 def isRocketInt(self, obj):
     return _isType(obj, _rocketNumber.RocketInt)
Example #9
0
 def isRocketString(self, obj):
     return _isType(obj, _rocketString.RocketString)
Example #10
0
 def isRocketCallable(self, obj):
     return _isType(obj, _RocketCallable)
Example #11
0
 def isRocketClassInst(self, obj):
     return _isType(obj, _RocketInstance)
Example #12
0
 def isRocketClass(self, obj):
     return _isType(obj, _RocketClass)
Example #13
0
 def isRocketFlatList(self, obj):
     return _isType(obj, _rocketArray.Array) or _isType(
         obj, _rocketList.List)
Example #14
0
 def isRocketList(self, obj):
     return _isType(obj, _rocketList.RocketList)
Example #15
0
 def isRocketArray(self, obj):
     return _isType(obj, _rocketArray.RocketArray)