Exemplo n.º 1
0
def clear_output(input: str):
    to_return = ''
    start = input.find('+') + 1
    to_return = input[:start]
    for i in range(start, len(input)):
        if input[i] != '0':
            start = i
            break
    to_return += input[start:]
    return String.String.new((String.string_native(to_return), ), {})
Exemplo n.º 2
0
def toString_native(x, base):
    if base == None or base == Types.undefined or base == 10:
        return toLocaleString_native(x)
    x = int(x)
    if x < 0:
        sign = -1
    elif x == 0:
        return digs[0]
    else:
        sign = 1

    x *= sign
    digits = []

    while x:
        digits.append(digs[int(x % base)])
        x = int(x / base)

    if sign < 0:
        digits.append('-')

    digits.reverse()
    return String.String.new((String.string_native(''.join(digits)), ), {})
Exemplo n.º 3
0
from StandartTypes import String
from CodeStructures import Types
'''
RegExp constructor START
'''
RegExp_CONSTRUCTOR_OPERATIONS = (('var_change', ('this.', 'value'),
                                  (((Types.VarName('input'), ), ),
                                   Types.ClassExecute('toString'))))
RegExp_CONSTRUCTOR = Types.Function(('input', ),
                                    RegExp_CONSTRUCTOR_OPERATIONS,
                                    static=False)
'''
RegExp constructor END
'''
'''
RegExp class definition START
'''
RegExp_METHODS = {}
RegExp = Types.Class(None, RegExp_CONSTRUCTOR, RegExp_METHODS)
RegExp.name = String.String.new((String.string_native('object'), ), {})
'''
RegExp class definition END
'''
Exemplo n.º 4
0
    tostring_boolean = boolean.execute_function('toString', (),
                                                GLOBAL_PARAMETERS)
    print('toString:', tostring_boolean)

    valueof_boolean = boolean.execute_function('valueOf', (),
                                               GLOBAL_PARAMETERS)
    print('valueOf:', valueof_boolean)

    print()

    print('Testing String:')

    index = Number.Number.new(('1', ), GLOBAL_PARAMETERS)

    string = String.String.new((String.string_native('string'), ),
                               GLOBAL_PARAMETERS)
    print('Initial value:', string)

    charat_string = string.execute_function('charAt', (index, ),
                                            GLOBAL_PARAMETERS)
    print('charAt:', charat_string)

    charcodeat_string = string.execute_function('charCodeAt', (index, ),
                                                GLOBAL_PARAMETERS)
    print('charCodeAt:', charcodeat_string)

    concat_string = string.execute_function('concat', (index, index),
                                            GLOBAL_PARAMETERS)
    print('concat:', concat_string)
Exemplo n.º 5
0
Array_METHODS = {}
Array_CONSTRUCTOR_OPERATIONS = (('var_change',
                      ('this.','value'),
                      (Types.VarName('arguments'),
                       1,
                       Array_constructor_native,
                       Types.EXECUTE_)),
                       ('return',('value',
                                  1,
                                  Types.VarName('this.'),
                                  Types.LISTACCESS_)),
                       )
Array_CONSTRUCTOR = Types.Function((),
                                   Array_CONSTRUCTOR_OPERATIONS,)

Array = Types.Class(String.String.new((String.string_native('object'),),{}),
                    Array_CONSTRUCTOR,
                    Array_METHODS)
'''
Array constrictor END
'''

'''
concat function START
'''
def concat_native(args):
    array = args[0]
    elements = args[1:]
    native_array = array['value']
    to_return = native_array.copy()
    for element in elements:
Exemplo n.º 6
0
def toLocaleString_native(number):
    return String.String.new((String.string_native("{:n}".format(number)), ),
                             {})
Exemplo n.º 7
0
def toFixed_native(number: float, precision=0):
    if precision == None or precision == Types.undefined:
        precision = 0
    precision = int(precision)
    return String.String.new((String.string_native(
        ('{:.' + str(precision) + 'f}').format(float(number))), ), {})
Exemplo n.º 8
0
                                   convert_to_number, Types.EXECUTE_)),
                                 ('return',
                                  ('value', 1, Types.VarName('this.'),
                                   Types.LISTACCESS_)))

NUMBER_CONSTRUCTOR = Types.Function(('input', ), NUMBER_CONSTRUCTOR_OPERATIONS)
'''
Number constructor END
'''
'''
Number class definition START
'''
NUMBER_METHODS = {}

Number = Types.Class(None, NUMBER_CONSTRUCTOR, NUMBER_METHODS)
Number.name = String.String.new((String.string_native('number'), ), {})
'''
Number class definition END
'''
'''
toExponential function START
'''


def get_precision(str_value):
    vals = str_value.split('.')
    if (vals[0] == '0'):
        return len(vals[1])
    else:
        return len(str_value) - 2