How to use the gdtoolkit.formatter.statement_utils.format_simple_statement function in gdtoolkit

To help you get started, we’ve selected a few gdtoolkit examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Scony / godot-gdscript-toolkit / gdtoolkit / formatter / function_statement.py View on Github external
def format_func_statement(statement: Node, context: Context) -> Outcome:
    handlers = {
        "pass_stmt": partial(format_simple_statement, "pass"),
        "func_var_stmt": format_var_statement,
        "expr_stmt": _format_expr_statement,
        "return_stmt": _format_return_statement,
        "break_stmt": partial(format_simple_statement, "break"),
        "continue_stmt": partial(format_simple_statement, "continue"),
        "if_stmt": _format_if_statement,
        "while_stmt": partial(_format_branch, "while ", ":", 0),
        "for_stmt": _format_for_statement,
        "match_stmt": _format_match_statement,
        # fake statements:
        "match_branch": _format_match_branch,
    }  # type: Dict[str, Callable]
    return handlers[statement.data](statement, context)
github Scony / godot-gdscript-toolkit / gdtoolkit / formatter / var_statement.py View on Github external
def _format_var_empty_statement(
    statement: Node, context: Context, prefix: str = ""
) -> Outcome:
    return format_simple_statement(
        "{}var {}".format(prefix, statement.children[0].value), statement, context
    )
github Scony / godot-gdscript-toolkit / gdtoolkit / formatter / function_statement.py View on Github external
def _format_return_statement(statement: Node, context: Context) -> Outcome:
    if len(statement.children) == 0:
        return format_simple_statement("return", statement, context)
    expr = statement.children[0]
    expression_context = ExpressionContext("return ", statement.line, "")
    return format_expression(expr, expression_context, context)
github Scony / godot-gdscript-toolkit / gdtoolkit / formatter / var_statement.py View on Github external
def _format_var_typed_statement(
    statement: Node, context: Context, prefix: str = ""
) -> Outcome:
    return format_simple_statement(
        "{}var {}: {}".format(
            prefix, statement.children[0].value, statement.children[1].value
        ),
        statement,
        context,
    )
github Scony / godot-gdscript-toolkit / gdtoolkit / formatter / function_statement.py View on Github external
def format_func_statement(statement: Node, context: Context) -> Outcome:
    handlers = {
        "pass_stmt": partial(format_simple_statement, "pass"),
        "func_var_stmt": format_var_statement,
        "expr_stmt": _format_expr_statement,
        "return_stmt": _format_return_statement,
        "break_stmt": partial(format_simple_statement, "break"),
        "continue_stmt": partial(format_simple_statement, "continue"),
        "if_stmt": _format_if_statement,
        "while_stmt": partial(_format_branch, "while ", ":", 0),
        "for_stmt": _format_for_statement,
        "match_stmt": _format_match_statement,
        # fake statements:
        "match_branch": _format_match_branch,
    }  # type: Dict[str, Callable]
    return handlers[statement.data](statement, context)
github Scony / godot-gdscript-toolkit / gdtoolkit / formatter / class_statement.py View on Github external
def format_class_statement(statement: Node, context: Context) -> Outcome:
    handlers = {
        "tool_stmt": partial(format_simple_statement, "tool"),
        "class_var_stmt": format_var_statement,
        "extends_stmt": _format_extends_statement,
        "class_def": _format_class_statement,
        "func_def": _format_func_statement,
        "enum_def": format_enum,
        "classname_stmt": _format_classname_statement,
        "signal_stmt": _format_signal_statement,
        "docstr_stmt": _format_docstring_statement,
        "const_stmt": _format_const_statement,
        "export_stmt": _format_export_statement,
        "onready_stmt": lambda s, c: format_var_statement(
            s.children[0], c, prefix="onready "
        ),
        "static_func_def": partial(
            _format_child_and_prepend_to_outcome, prefix="static "
        ),
github Scony / godot-gdscript-toolkit / gdtoolkit / formatter / class_statement.py View on Github external
def _format_signal_statement(statement: Node, context: Context) -> Outcome:
    if len(statement.children) == 1:
        return format_simple_statement(
            "signal {}".format(statement.children[0].value), statement, context
        )
    expression_context = ExpressionContext(
        "signal {}(".format(statement.children[0].value), statement.line, ")"
    )
    return (
        format_comma_separated_list(
            statement.children[1:], expression_context, context
        ),
        statement.end_line,
    )