How to use the gdtoolkit.formatter.block.format_block 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 / formatter.py View on Github external
gdscript_code_lines = [
        "",
        *gdscript_code.splitlines(),
    ]  # type: List[str]
    formatted_lines = []  # type: FormattedLines
    context = Context(
        indent=0,
        previously_processed_line_number=0,
        max_line_length=max_line_length,
        gdscript_code_lines=gdscript_code_lines,
        standalone_comments=gather_standalone_comments(
            gdscript_code, comment_parse_tree
        ),
        inline_comments=gather_inline_comments(gdscript_code, comment_parse_tree),
    )
    formatted_lines, _ = format_block(
        parse_tree.children,
        format_class_statement,
        context,
        GLOBAL_SCOPE_SURROUNDING_EMPTY_LINES_TABLE,
    )
    formatted_lines.append((None, ""))
    formatted_lines_with_inlined_comments = _add_inline_comments(
        formatted_lines, context.inline_comments
    )
    return "\n".join([line for _, line in formatted_lines_with_inlined_comments])
github Scony / godot-gdscript-toolkit / gdtoolkit / formatter / class_statement.py View on Github external
def _format_class_statement(statement: Node, context: Context) -> Outcome:
    last_processed_line_no = statement.line
    name = statement.children[0].value
    formatted_lines = [
        (statement.line, "{}class {}:".format(context.indent_string, name))
    ]
    class_lines, last_processed_line_no = format_block(
        statement.children[1:],
        format_class_statement,
        context.create_child_context(last_processed_line_no),
    )
    formatted_lines += class_lines
    return (formatted_lines, last_processed_line_no)
github Scony / godot-gdscript-toolkit / gdtoolkit / formatter / function_statement.py View on Github external
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 / class_statement.py View on Github external
first_statement_offset + 1
        if _has_func_args(statement)
        else first_statement_offset
    )
    first_statement_offset = (
        first_statement_offset + 1
        if _has_parent_call(statement)
        else first_statement_offset
    )
    first_statement_offset = (
        first_statement_offset + 1
        if _has_return_type(statement)
        else first_statement_offset
    )
    formatted_lines, last_processed_line_no = _format_func_header(statement, context)
    func_lines, last_processed_line_no = format_block(
        statement.children[first_statement_offset:],
        format_func_statement,
        context.create_child_context(last_processed_line_no),
    )
    formatted_lines += func_lines
    return (formatted_lines, last_processed_line_no)