Пример #1
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),
    )
Пример #2
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))
Пример #3
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 _:"),
    )
Пример #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"))
Пример #5
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)))
Пример #6
0
def output_comparison(name, comparison=None):
    if comparison is not None:
        execute_with_dictation(
            name,
            on_dictation=lambda v: Text("%s %s " %
                                        (format_name(name), comparison)),
            on_other=lambda v: Text(" %s " % comparison))
Пример #7
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 _"),
    )
Пример #8
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)))
Пример #9
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)))
Пример #10
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))
Пример #11
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))
Пример #12
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))
Пример #13
0
def output_type_annotation(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: Text("%s%s %s" %
                           (constant_prefix, type_name, format_value_name(n))),
            lambda n: replace_in_text("%s%s $" % (constant_prefix, type_name)))
Пример #14
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))
Пример #15
0
    def execute_with_type_choice(name):
        def command_with_name(n):
            safe_expression = type_choice.get_safe_cast_expression(n)
            unsafe_expression = type_choice.get_cast_expression(n)

            return Text(safe_expression if is_safe else unsafe_expression)

        execute_with_dictation(name, lambda n: command_with_name(n),
                               lambda n: command_with_name("$"))
Пример #16
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 $ _"))
Пример #17
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),
        )
Пример #18
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))
Пример #19
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))
Пример #20
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))
Пример #21
0
def output_function_call(function_name, name):
    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

    execute_with_dictation(function_name, lambda n: do_output(n),
                           lambda n: do_output("$"))
Пример #22
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)))
Пример #23
0
def output_function(function_name, type_name, visibility_attribute=None):
    attribute_string = visibility_attribute + " " if visibility_attribute is not None else ""

    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)

    execute_with_dictation(type_name, output_with_type_name,
                           lambda n: output_with_type_name("_"))
Пример #24
0
def output_size_of(type_name):
    execute_with_dictation(type_name,
                           lambda n: Text("@sizeOf(%s)" % format_type_name(n)),
                           lambda n: replace_in_text("@sizeOf($)"))
Пример #25
0
def output_type_definition(type_name, definition_type):
    execute_with_dictation(
        type_name,
        lambda n: replace_in_text("const %s = %s {$};" %
                                  (proper(str(n)), definition_type)),
        lambda n: Text("%s {}" % definition_type))
Пример #26
0
def output_import(value_name):
    execute_with_dictation(
        value_name, lambda v: replace_in_text("const %s = import(\"$\");" %
                                              format_value_name(v)),
        lambda v: replace_in_text("const $ = import(\"_\");"))
Пример #27
0
def output_return(value_name):
    execute_with_dictation(value_name,
                           lambda n: Text("return %s;" % format_value_name(n)),
                           lambda n: replace_in_text("return $;"))
Пример #28
0
def output_test(test_name):
    execute_with_dictation(test_name, lambda v: Text("test \"%s\" {\n" % v),
                           lambda v: replace_in_text("test \"$\" {}"))
Пример #29
0
def output_comparison(value_name, comparison=None):
    if comparison is not None:
        execute_with_dictation(
            value_name, lambda n: Text("%s %s " %
                                       (format_value_name(n), comparison)),
            lambda n: replace_in_text("$ %s _" % comparison))
Пример #30
0
 def execute_without_type_choice(name):
     execute_with_dictation(
         name,
         lambda n: replace_in_text("@as($, %s)" % format_value_name(n)),
         lambda n: replace_in_text("@as($, _)"))