How to use the gdtoolkit.formatter.var_statement.format_var_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 / class_statement.py View on Github external
def _format_export_statement(statement: Tree, context: Context) -> Outcome:
    concrete_export_statement = statement.children[0]
    if concrete_export_statement.data == "export_inf":
        return format_var_statement(
            concrete_export_statement, context, prefix="export "
        )
    expression_context = ExpressionContext("export (", statement.line, ")")
    prefix_lines, _ = (
        format_comma_separated_list(
            concrete_export_statement.children[:-1], expression_context, context
        ),
        statement.end_line,
    )
    _, last_line = prefix_lines[-1]
    prefix = "{} ".format(last_line.strip())
    expr_lines, _ = format_var_statement(
        concrete_export_statement.children[-1], context, prefix=prefix
    )
    return (prefix_lines[:-1] + expr_lines, statement.end_line)
github Scony / godot-gdscript-toolkit / gdtoolkit / formatter / class_statement.py View on Github external
        "onready_stmt": lambda s, c: format_var_statement(
            s.children[0], c, prefix="onready "
        ),
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 "
        ),
        "remote_func_def": partial(
github Scony / godot-gdscript-toolkit / gdtoolkit / formatter / class_statement.py View on Github external
def _format_export_statement(statement: Tree, context: Context) -> Outcome:
    concrete_export_statement = statement.children[0]
    if concrete_export_statement.data == "export_inf":
        return format_var_statement(
            concrete_export_statement, context, prefix="export "
        )
    expression_context = ExpressionContext("export (", statement.line, ")")
    prefix_lines, _ = (
        format_comma_separated_list(
            concrete_export_statement.children[:-1], expression_context, context
        ),
        statement.end_line,
    )
    _, last_line = prefix_lines[-1]
    prefix = "{} ".format(last_line.strip())
    expr_lines, _ = format_var_statement(
        concrete_export_statement.children[-1], context, prefix=prefix
    )
    return (prefix_lines[:-1] + expr_lines, statement.end_line)