How to use the gdtoolkit.formatter.expression_to_str.expression_to_str 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 / expression.py View on Github external
def _format_call_expression_to_multiline_line(
    expression: Tree, expression_context: ExpressionContext, context: Context,
) -> Outcome:
    dot = "." if has_leading_dot(expression) else ""
    offset = 1 if has_leading_dot(expression) else 0
    callee_node = expression.children[0 + offset]
    callee = expression_to_str(callee_node)
    list_is_empty = len(expression.children) == 3 + offset
    if list_is_empty:
        return (
            [
                (
                    expression_context.prefix_line,
                    "{}{}{}()".format(
                        context.indent_string, expression_context.prefix_string, callee
                    ),
                )
            ],
            expression.end_line,
        )
    new_expression_context = ExpressionContext(
        "{}{}{}(".format(expression_context.prefix_string, dot, callee),
        callee_node.line,
github Scony / godot-gdscript-toolkit / gdtoolkit / formatter / expression.py View on Github external
if is_expression_forcing_multiple_lines(expression):
        return _format_foldable_to_multiple_lines(
            expression, expression_context, context
        )
    single_line_expression = expression_to_str(expression)
    single_line_length = (
        context.indent
        + len(expression_context.prefix_string)
        + len(single_line_expression)
        + len(expression_context.suffix_string)
    )
    if single_line_length <= context.max_line_length:
        single_line = "{}{}{}{}".format(
            context.indent_string,
            expression_context.prefix_string,
            expression_to_str(expression),
            expression_context.suffix_string,
        )
        return (
            [(expression_context.prefix_line, single_line)],
            expression_context.prefix_line,
        )
    return _format_foldable_to_multiple_lines(expression, expression_context, context)
github Scony / godot-gdscript-toolkit / gdtoolkit / formatter / expression.py View on Github external
def _format_assignment_expression_to_multiline_line(
    expression: Tree, expression_context: ExpressionContext, context: Context,
) -> Outcome:
    new_expression_context = ExpressionContext(
        "{}{} {} ".format(
            expression_context.prefix_string,
            expression_to_str(expression.children[0]),
            expression_to_str(expression.children[1]),
        ),
        expression_context.prefix_line,
        expression_context.suffix_string,
    )
    return _format_concrete_expression(
        expression.children[2], new_expression_context, context
    )
github Scony / godot-gdscript-toolkit / gdtoolkit / formatter / expression.py View on Github external
def _format_foldable(
    expression: Node, expression_context: ExpressionContext, context: Context
) -> Outcome:
    if is_expression_forcing_multiple_lines(expression):
        return _format_foldable_to_multiple_lines(
            expression, expression_context, context
        )
    single_line_expression = expression_to_str(expression)
    single_line_length = (
        context.indent
        + len(expression_context.prefix_string)
        + len(single_line_expression)
        + len(expression_context.suffix_string)
    )
    if single_line_length <= context.max_line_length:
        single_line = "{}{}{}{}".format(
            context.indent_string,
            expression_context.prefix_string,
            expression_to_str(expression),
            expression_context.suffix_string,
        )
        return (
            [(expression_context.prefix_line, single_line)],
            expression_context.prefix_line,
github Scony / godot-gdscript-toolkit / gdtoolkit / formatter / expression.py View on Github external
def _format_concrete_expression(
    expression: Node, expression_context: ExpressionContext, context: Context
) -> Outcome:
    if is_foldable(expression):
        return _format_foldable(expression, expression_context, context)
    return (
        [
            (
                expression_context.prefix_line,
                "{}{}{}{}".format(
                    context.indent_string,
                    expression_context.prefix_string,
                    expression_to_str(expression),
                    expression_context.suffix_string,
                ),
            )
        ],
        expression_context.prefix_line,
    )
github Scony / godot-gdscript-toolkit / gdtoolkit / formatter / class_statement.py View on Github external
def _format_extends_statement(statement: Node, context: Context) -> Outcome:
    last_processed_line_no = statement.line
    optional_attributes = (
        ""
        if len(statement.children) == 1
        else ".{}".format(
            ".".join([expression_to_str(child) for child in statement.children[1:]])
        )
    )
    formatted_lines = [
        (
            statement.line,
            "{}extends {}{}".format(
                context.indent_string,
                expression_to_str(statement.children[0]),
                optional_attributes,
            ),
        )
    ]
    return (formatted_lines, last_processed_line_no)
github Scony / godot-gdscript-toolkit / gdtoolkit / formatter / expression.py View on Github external
def _format_assignment_expression_to_multiline_line(
    expression: Tree, expression_context: ExpressionContext, context: Context,
) -> Outcome:
    new_expression_context = ExpressionContext(
        "{}{} {} ".format(
            expression_context.prefix_string,
            expression_to_str(expression.children[0]),
            expression_to_str(expression.children[1]),
        ),
        expression_context.prefix_line,
        expression_context.suffix_string,
    )
    return _format_concrete_expression(
        expression.children[2], new_expression_context, context
    )
github Scony / godot-gdscript-toolkit / gdtoolkit / formatter / class_statement.py View on Github external
def _format_extends_statement(statement: Node, context: Context) -> Outcome:
    last_processed_line_no = statement.line
    optional_attributes = (
        ""
        if len(statement.children) == 1
        else ".{}".format(
            ".".join([expression_to_str(child) for child in statement.children[1:]])
        )
    )
    formatted_lines = [
        (
            statement.line,
            "{}extends {}{}".format(
                context.indent_string,
                expression_to_str(statement.children[0]),
                optional_attributes,
            ),
        )
    ]
    return (formatted_lines, last_processed_line_no)
github Scony / godot-gdscript-toolkit / gdtoolkit / formatter / class_statement.py View on Github external
def _format_classname_statement(statement: Node, context: Context) -> Outcome:
    last_processed_line_no = statement.line
    optional_string = (
        ""
        if len(statement.children) == 1
        else ", {}".format(expression_to_str(statement.children[1]))
    )
    formatted_lines = [
        (
            statement.line,
            "{}class_name {}{}".format(
                context.indent_string, statement.children[0].value, optional_string
            ),
        )
    ]
    return (formatted_lines, last_processed_line_no)