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)
def _process_recognition(self, node, extras): integer = extras["m"] number = str(integer) if "n" in extras: floating_point = extras["n"] number += "." + str(floating_point) text(number).execute()
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)
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)
def _change_visibility(prefix): mouse("left/3").execute() key("s-f6/20").execute() name = get_selected_text() if name.startswith("__"): name = name[2:] elif name.startswith("_"): name = name[1:] name = prefix + name text(name).execute() key("enter/3").execute()
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)
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)
class PluralRule(MappingRule): mapping = {"plural": text("s")} def __init__(self, exported): MappingRule.__init__(self, name=get_unique_rule_name(), exported=exported)
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)
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)
def ternary(): text(" if else ").execute() global_state.add_nesting_level(6) global_state.add_nesting_level(4)
def format_variable(text, prefix="", suffix=""): name = formatter.format_text(text, formatter.FormatType.snakeCase) _text(prefix + name + suffix).execute() def class_name(text): name = formatter.format_text(text, formatter.FormatType.pascalCase) _text(name).execute() rules = MappingRule( mapping={ # Commands and keywords: "and": text(" and "), "as": text("as "), "assign": text(" = "), "assert": text("assert "), "break": text("break"), "comment": text("# "), "class": text("class "), "continue": text("continue"), "del":
def _process_recognition(self, node, extras): symbol = extras["symbol"] text(symbol).execute()
def _process_recognition(self, node, extras): text(node).execute()
def _process_recognition(self, node, extras): letter = extras["letter"][1] text(letter).execute()
def _process_recognition(self, node, extras): text(reduce(lambda x, y: x + y, extras["symbols"])).execute()