Exemple #1
0
def output_for_loop(name):
    execute_with_dictation(
        name,
        on_dictation=lambda v: replace_in_text("for $ in %s:" % format_name(
            name)),
        on_other=lambda v: replace_in_text("for $ in _:"),
    )
Exemple #2
0
def output_import_as(import_name):
    if import_name == "":
        command = replace_in_text("import * as _ from \"$\";")
    else:
        import_name = format_import_name(import_name)
        command = replace_in_text("import * as $ from \"%s\";" % import_name)
    command.execute()
Exemple #3
0
def output_if_comparison(value_name, construct, comparison=None):
    if comparison is not None:
        execute_with_dictation(
            value_name, lambda n: replace_in_text("%s (%s %s $) {}" % (
                construct, format_value_name(n), comparison)),
            lambda n: replace_in_text("%s ($ %s _) {}" %
                                      (construct, comparison)))
Exemple #4
0
def output_for_loop(name, binding):
    binding_text = format_name(binding) if binding != "" else "$"

    execute_with_dictation(
        name, lambda n: replace_in_text("for %s <- %s do $ end" %
                                        (binding_text, format_name(n))),
        lambda n: replace_in_text("for %s <- $ do end"))
Exemple #5
0
def output_if_expression(name):
    execute_with_dictation(
        name,
        on_dictation=lambda v: replace_in_text("$ if %s else _" % format_name(
            name)),
        on_other=lambda v: replace_in_text("_ if $ else _"),
    )
Exemple #6
0
def output_if_expression_comparison(name, comparison=None):
    if comparison is not None:
        execute_with_dictation(name,
                               on_dictation=lambda v:
                               replace_in_text("_ if %s %s $ else _" %
                                               (format_name(v), comparison)),
                               on_other=lambda v: replace_in_text(
                                   "_ if $ %s _ else _" % comparison))
Exemple #7
0
def output_if_comparison(name, construct, comparison=None):
    if comparison is not None:
        execute_with_dictation(
            name,
            on_dictation=lambda v: replace_in_text("%s %s %s $ {" % (
                construct, format_variable_name(v), comparison)),
            on_other=lambda v: replace_in_text("%s $ %s _ {" %
                                               (construct, comparison)))
Exemple #8
0
def output_variable_declaration(name, type_name=None):
    if type_name is not None:
        execute_with_dictation(
            name, lambda n: Text("var %s %s" %
                                 (format_variable_name(n), type_name)),
            lambda n: replace_in_text("var $ %s" % type_name))
    else:
        execute_with_dictation(
            name, lambda n: Text("var %s " % format_variable_name(n)),
            lambda n: replace_in_text("var $ _"))
Exemple #9
0
def output_value(value_name, type_name=None, is_constant=False):
    constant_prefix = "const " if is_constant else ""

    if type_name is not None:
        execute_with_dictation(
            value_name, lambda n: replace_in_text("%s%s %s = $;" %
                                                  (constant_prefix, type_name,
                                                   format_value_name(n))),
            lambda n: replace_in_text("%s%s $ = _;" %
                                      (constant_prefix, type_name)))
Exemple #10
0
    def do_output(fn):
        with_function_name = with_dictation(
            name, lambda n: Text("%s(%s)" %
                                 (format_function_name(fn), format_name(n))),
            lambda n: replace_in_text("%s($)" % format_function_name(fn)))
        without_function_name = with_dictation(
            name, lambda n: replace_in_text("$(%s)" % format_name(n)),
            lambda n: replace_in_text("$(_)"))

        return without_function_name if fn == "$" else with_function_name
Exemple #11
0
def output_function(name, visibility_attribute=None, is_method=False):
    method_parameter_output = "_" if name == "" else "$"
    method_output = "(%s) " % method_parameter_output if is_method else ""
    parameter_output = "_" if name == "" or is_method else "$"

    execute_with_dictation(
        name, lambda n: replace_in_text("func %s%s(%s) _ {" %
                                        (method_output,
                                         format_name(n, visibility_attribute),
                                         parameter_output)),
        lambda n: replace_in_text("func %s$(_) _ {" % method_output))
Exemple #12
0
    def do_output(fn):
        with_method_name = with_dictation(
            name, lambda n: Text("%s.%s()" %
                                 (format_name(n), format_function_name(fn))),
            lambda n: replace_in_text("$.%s()" % format_function_name(fn)))

        without_method_name = with_dictation(
            name, lambda n: replace_in_text("%s.$()" % format_name(n)),
            lambda n: replace_in_text("$._()"))

        return without_method_name if fn == "$" else with_method_name
Exemple #13
0
def output_type(type_name, visibility_attribute=None):
    attribute_output = ""
    if visibility_attribute is not None:
        attribute_output = "%s " % visibility_attribute

    if type_name == "":
        command = replace_in_text("%stype $ = _" % attribute_output)
    else:
        type_name = format_type_name(type_name)
        command = replace_in_text("%stype %s = $" %
                                  (attribute_output, type_name))
    command.execute()
Exemple #14
0
def output_if_comparison(name, comparison=None, construct="if"):
    if comparison is not None:
        (comparison_text, comparison_command) = comparison
        execute_with_dictation(
            name, lambda n: comparison_command("%s (%s %s) {}" % (
                construct, format_name(n), comparison_text)),
            lambda n: replace_in_text("%s ($ %s) {}" %
                                      (construct, comparison_text)))
    else:
        execute_with_dictation(
            name, lambda n: Text("%s (%s) {}" % (construct, format_name(n))),
            lambda n: replace_in_text("%s ($) {}" % construct))
Exemple #15
0
def output_value(name, definition_type, visibility_attribute=None):
    attribute_output = ""
    if visibility_attribute is not None:
        attribute_output = "%s " % visibility_attribute

    if name == "":
        command = replace_in_text("%s%s $ = _;" %
                                  (attribute_output, definition_type))
    else:
        name = format_name(name)
        command = replace_in_text("%s%s %s = $;" %
                                  (attribute_output, definition_type, name))
    command.execute()
Exemple #16
0
def output_method_call(method_name, name):
    method_name = format_name(method_name)
    name = format_name(name)

    if method_name == "" and name == "":
        command = replace_in_text("$._()")
    elif method_name == "":
        command = replace_in_text("%s.$()" % name)
    elif name == "":
        command = replace_in_text("$.%s()" % method_name)
    else:
        command = Text("%s.%s()" % (name, method_name))

    command.execute()
Exemple #17
0
def output_function_call(function_name, name):
    function_name = format_name(function_name)
    name = format_name(name)

    if function_name == "" and name == "":
        command = replace_in_text("_($)")
    elif function_name == "":
        command = replace_in_text("$(%s)" % name)
    elif name == "":
        command = replace_in_text("%s($)" % function_name)
    else:
        command = Text("%s(%s)" % (function_name, name))

    command.execute()
Exemple #18
0
    def output_with_type_name(name):
        type_name_components = str(name).split(" ")
        type_name_output = format_type_name(
            name) if len(type_name_components) != 1 else name
        command_with_function_name = replace_in_text(
            "%sfn %s($) %s {}" %
            (attribute_string, format_function_name(function_name),
             type_name_output))
        command_without_function_name = replace_in_text(
            "%sfn $(_) %s {}" % (attribute_string, type_name_output))

        return with_dictation(function_name,
                              lambda n: command_with_function_name,
                              lambda n: command_without_function_name)
Exemple #19
0
def output_function(function_name,
                    visibility_attribute=None,
                    asynchronous=False):
    attribute_output = ""
    if visibility_attribute is not None:
        attribute_output = "%s " % visibility_attribute

    asynchronous_output = ""
    if asynchronous:
        asynchronous_output = "async "

    execute_with_dictation(
        function_name, lambda n: replace_in_text("%s%sfunction %s($): _ {}" % (
            attribute_output, asynchronous_output, format_function_name(n))),
        lambda n: replace_in_text("%s%sfunction $(_): _ {}" %
                                  (attribute_output, asynchronous_output)))
Exemple #20
0
def output_switch(name):
    if name == "":
        command = replace_in_text("switch ($) {}")
    else:
        name = format_name(name)
        command = Text("switch (%s) {}" % name)
    command.execute()
Exemple #21
0
def output_binding(value_name, is_pointer=False):
    pointer_suffix = ".*" if is_pointer else ""

    execute_with_dictation(
        value_name, lambda n: Text("%s%s = " %
                                   (format_value_name(n), pointer_suffix)),
        lambda n: replace_in_text("$%s = " % pointer_suffix))
Exemple #22
0
def output_if(name, statement_type):
    execute_with_dictation(
        name,
        on_dictation=lambda v: Text("%s %s {" % (statement_type,
                                                 format_variable_name(name))),
        on_other=lambda v: replace_in_text("%s $ {" % statement_type),
    )
Exemple #23
0
def output_while_loop(value_name, binding_name=None):
    maybe_unpack = "|%s| " % format_value_name(
        binding_name) if binding_name is not None else ""

    execute_with_dictation(
        value_name, lambda n: Text("while (%s) %s{}" %
                                   (format_value_name(n), maybe_unpack)),
        lambda n: replace_in_text("while ($) %s {}" % maybe_unpack))
Exemple #24
0
def output_alias(module_name, alias_name):
    alias_suffix = ", as: %s" % format_module_name(
        alias_name) if alias_name != "" else ""

    execute_with_dictation(
        module_name, lambda n: Text("alias %s%s" %
                                    (format_module_name(n), alias_suffix)),
        lambda n: replace_in_text("alias $%s" % alias_suffix))
Exemple #25
0
def output_none_check(name, construct, is_not=False):
    comparison_output = "!= nil" if is_not else "== nil"

    execute_with_dictation(
        name, lambda n: Text("%s %s %s {\n" % (
            construct, format_variable_name(n), comparison_output)),
        lambda n: replace_in_text("%s $ %s {" %
                                  (construct, comparison_output)))
Exemple #26
0
def output_class(class_name, superclass):
    if superclass != "":
        superclass = "(" + format_class_name(superclass) + ")"

    execute_with_dictation(
        class_name,
        on_dictation=lambda v: Text("class %s%s:" %
                                    (format_class_name(v), superclass)),
        on_other=lambda v: replace_in_text("class $%s:" % superclass))
Exemple #27
0
def output_check_comparison(name, comparison=None):
    if comparison is not None:
        (comparison_text, comparison_command) = comparison
        if name == "":
            command = replace_in_text("$ %s" % comparison_text)
        else:
            name = format_name(name)
            command = Text("%s %s " % (name, comparison))
        command.execute()
Exemple #28
0
def output_function_call(function_name, value_name, with_try=False):
    function_name = format_function_name(function_name)
    value_name = format_value_name(value_name)
    command_text = "try " if with_try else ""

    if function_name == "" and value_name == "":
        command_text += "$(_)"
        command = replace_in_text(command_text)
    elif function_name == "":
        command_text += "$(%s)" % value_name
        command = replace_in_text(command_text)
    elif value_name == "":
        command_text += "%s($)" % function_name
        command = replace_in_text(command_text)
    else:
        command_text += "%s(%s)" % (function_name, value_name)
        command = Text(command_text)

    command.execute()
Exemple #29
0
def output_log_statement(name, log_level=None):
    if log_level is not None:
        execute_with_dictation(
            name,
            lambda n:
            Text("Logger.%s(\"XXXXXX: #{inspect(%s, pretty: true)}\")" %
                 (log_level, format_name(n))),
            lambda n: replace_in_text(
                "Logger.%s(\"XXXXXX: #{inspect($, pretty: true)}\")" %
                log_level),
        )
Exemple #30
0
def output_for_loop(value_name, binding_name=None):
    def output_with_value_name(name):
        if binding_name is not None:
            return Text("for (%s) |%s| {}" %
                        (format_value_name(name), binding))
        else:
            return replace_in_text("for (%s) |$| {}" % format_value_name(name))

    binding = format_value_name(
        binding_name) if binding_name is not None else "_"

    execute_with_dictation(
        value_name, output_with_value_name,
        lambda n: replace_in_text("for ($) |%s| {}" % binding))