Пример #1
0
    def _process_recognition(self, node, extras):
        has_parameters = node.words()[1] != "no-param"
        type = node.words()[1 if has_parameters else 2]
        string = "def "

        name = None
        if type == "constructor":
            name = "__init__"
        elif "text" in extras:
            name = formatter.format_snake_case(extras["text"])

        if name is not None:
            string += name

        parameters_start = "("
        if type in ("method", "constructor"):
            parameters_start += "self, " if has_parameters else "self"

        string += parameters_start + ")"
        text(string).execute()
        if has_parameters:
            global_state.add_nesting_level(1)
        if name is None:
            name_offset = len(parameters_start)
            if not has_parameters:
                name_offset += 1
            global_state.add_nesting_level(name_offset)
Пример #2
0
    def _process_recognition(self, node, extras):
        has_arguments = node.words()[1] != "empty"
        string = formatter.format_text(extras["text"],
                                       formatter.FormatType.pascalCase)
        string += "()"
        text(string).execute()

        if has_arguments:
            global_state.add_nesting_level(1)
Пример #3
0
 def _process_recognition(self, node, extras):
     has_parameters = node.words()[0] != "no-param"
     string = "lambda"
     if not has_parameters:
         string += ":"
     else:
         string += " :"
     text(string).execute()
     if has_parameters:
         global_state.add_nesting_level(1)
Пример #4
0
    def _process_recognition(self, node, extras):
        is_constructor = "text" not in extras
        name = "__init__" if is_constructor else formatter.format_text(
            extras["text"], formatter.FormatType.snakeCase)
        has_arguments = node.words()[1] != "empty"
        has_period = node.words()[len(node.words()) - 1] == "on"
        string = "." if has_period else ""
        string += name
        string += "()"
        text(string).execute()

        if has_arguments:
            global_state.add_nesting_level(1)
Пример #5
0
    def _process_recognition(self, node, extras):
        is_child = node.words()[1] == "child"
        string = "class "
        if "text" in extras:
            string += formatter.format_text(extras["text"],
                                            formatter.FormatType.pascalCase)

        if is_child:
            string += "()"
        text(string).execute()
        if is_child:
            global_state.add_nesting_level(1)
            if "text" not in extras:
                global_state.add_nesting_level(1)
Пример #6
0
    def _process_recognition(self, node, extras):
        type = node.words()[1]
        string = ""
        if "text" in extras:
            if type == "variable":
                name = formatter.format_snake_case(extras["text"])
            else:
                name = formatter.format_text(extras["text"], [
                    formatter.FormatType.snakeCase,
                    formatter.FormatType.upperCase
                ])

            string = name

        string += " = "
        text(string).execute()
        if "text" not in extras:
            global_state.add_nesting_level(3)
Пример #7
0
def list_comprehension():
    text("[ for  in ]").execute()
    global_state.add_nesting_level(1)
    global_state.add_nesting_level(4)
    global_state.add_nesting_level(5)
Пример #8
0
def ternary():
    text(" if  else ").execute()
    global_state.add_nesting_level(6)
    global_state.add_nesting_level(4)