How to use the gdtoolkit.formatter.expression.format_expression 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 / var_statement.py View on Github external
def _format_var_inferred_statement(
    statement: Node, context: Context, prefix: str = ""
) -> Outcome:
    name = statement.children[0].value
    expr = statement.children[1]
    expression_context = ExpressionContext(
        "{}var {} := ".format(prefix, name), 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_assigned_statement(
    statement: Node, context: Context, prefix: str = ""
) -> Outcome:
    var_name = statement.children[0].value
    type_name = statement.children[1].value
    expr = statement.children[2]
    expression_context = ExpressionContext(
        "{}var {}: {} = ".format(prefix, var_name, type_name), statement.line, ""
    )
    return format_expression(expr, expression_context, context)
github Scony / godot-gdscript-toolkit / gdtoolkit / formatter / function_statement.py View on Github external
def _format_branch(
    prefix: str,
    suffix: str,
    expr_position: Optional[int],
    statement: Node,
    context: Context,
) -> Outcome:
    if expr_position is not None:
        expr = statement.children[expr_position]
        expression_context = ExpressionContext(prefix, statement.line, suffix)
        header_lines, last_processed_line_no = format_expression(
            expr, expression_context, context
        )
        offset = expr_position + 1
    else:
        header_lines = [
            (statement.line, "{}{}{}".format(context.indent_string, prefix, suffix))
        ]
        last_processed_line_no = statement.line
        offset = 0
    body_lines, last_processed_line_no = format_block(
        statement.children[offset:],
        format_func_statement,
        context.create_child_context(last_processed_line_no),
    )
    return (header_lines + body_lines, last_processed_line_no)
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_assigned_statement(
    statement: Node, context: Context, prefix: str = ""
) -> Outcome:
    name = statement.children[0].value
    expr = statement.children[1]
    expression_context = ExpressionContext(
        "{}var {} = ".format(prefix, name), statement.line, ""
    )
    return format_expression(expr, expression_context, context)
github Scony / godot-gdscript-toolkit / gdtoolkit / formatter / class_statement.py View on Github external
def _format_const_statement(statement: Tree, context: Context) -> Outcome:
    if len(statement.children) == 4:
        prefix = "const {} = ".format(statement.children[1].value)
    elif len(statement.children) == 5:
        prefix = "const {} := ".format(statement.children[1].value)
    elif len(statement.children) == 6:
        prefix = "const {}: {} = ".format(
            statement.children[1].value, statement.children[3].value
        )
    else:
        raise NotImplementedError
    expression_context = ExpressionContext(prefix, statement.line, "")
    return format_expression(statement.children[-1], expression_context, context)
github Scony / godot-gdscript-toolkit / gdtoolkit / formatter / function_statement.py View on Github external
def _format_expr_statement(statement: Node, context: Context) -> Outcome:
    expr = statement.children[0]
    expression_context = ExpressionContext("", statement.line, "")
    return format_expression(expr, expression_context, context)