Example #1
0
def check_var(val):
    # formats variable name to snake_case
    variable = format_var_func_name(val)
    if not variable:
        return False
    else:
        return variable
Example #2
0
def for_loop(to_parse):
    # makes sure it is a for-in loop
    if " in " not in to_parse:
        return False
    else:
        Code.if_else_loop = True
        Code.multiline = True
        if type(Code.code) != dict:
            Code.code = {}
        # splits loop into variable and iterable
        parts = to_parse.split(" in ")
        # add loop variable to defined_vars
        variable = format_var_func_name(parts[0])
        Code.defined_vars.add(variable)
        Code.loop_func_vars.append(variable)
        iterable = format_value(parts[1])
        # increases indentation if not the first line in the loop
        if len(Code.code) > 0:
            Code.amount_nested += "    "
            Code.code[len(Code.code)] = "{0}for {1} in {2}:".format(
                Code.amount_nested, variable, iterable
            )
        else:
            Code.code[len(Code.code)] = "for {0} in {1}:".format(
                variable, iterable
            )
def assign_variable(to_parse):
    v = "to variable"
    to_parse = to_parse.replace("the variable", v)
    to_parse = to_parse.replace("two variable", v)
    to_parse = to_parse.replace("- variable ", v)
    # makes sure that "to variable" is in the command
    unformatted_name_place = to_parse.find(" to variable ")
    if unformatted_name_place == -1:
        return False

    # where the name should be
    unformatted_name = to_parse[unformatted_name_place+13:]
    # where the value should be
    unparsed_value = to_parse[:unformatted_name_place]

    # converts the variable name and value to proper forms
    var_name = format_var_func_name(unformatted_name)
    var_value = format_value(unparsed_value)

    # adds variable to defined_vars
    Code.defined_vars.add(var_name)

    if not var_name or not var_value:
        return False
    else:
        return "{0} = {1}".format(var_name, var_value)
Example #4
0
def check_var_assumed(val):
    variable = format_var_func_name(val)
    if not variable:
        return False
    else:
        # makes sure variable has been defined already
        if variable not in Code.defined_vars:
            return False
        else:
            return variable
Example #5
0
def check_func(val):
    val = voice_conversion(val, "function")
    parameters = get_params(val)
    function_name = val.split("parameters")[0]

    # attempts to make function a Python builtin
    if to_builtin(function_name):
        function_name = to_builtin(function_name)
    else:
        # formats the name as snake_case if it is not a builtin
        function_name = format_var_func_name(function_name.rstrip())
    if parameters is False:
        return False
    else:
        return "{0}{1}".format(function_name, parameters)
Example #6
0
def get_method(val):
    val = voice_conversion(val, "method")
    # makes sure that command contains a method call
    if "method" in val:
        method_spot = val.find("method")
        parameters = get_params(val)
        # gets method name and converts it to builtin if it can
        method = val.split("parameters")[0][method_spot+7:]
        if to_builtin(method):
            method = to_builtin(method)
        else:
            method = format_var_func_name(method.rstrip())
        if parameters is False:
            return False
        # returns the method and the text that needs to be removed from val
        else:
            return [".{0}{1}".format(method, parameters), val[method_spot:]]
    else:
        return ["", ""]