How to use the gdtoolkit.formatter.expression.format_comma_separated_list 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_func_header(statement: Tree, context: Context) -> Outcome:
    name_token = statement.children[0]
    name = name_token.value
    func_args = (
        statement.children[1]
        if isinstance(statement.children[1], Tree)
        and statement.children[1].data == "func_args"
        else None
    )
    if func_args is not None:
        expression_context = ExpressionContext(
            "func {}(".format(name), statement.line, ")"
        )
        formatted_lines = format_comma_separated_list(
            func_args.children, expression_context, context
        )
    else:
        formatted_lines = [
            (name_token.line, "{}func {}()".format(context.indent_string, name))
        ]
    parent_call = (
        statement.children[1]
        if isinstance(statement.children[1], Tree)
        and statement.children[1].data == "parent_call"
        else None
    )
    parent_call = (
        statement.children[2]
        if len(statement.children) > 2
        and isinstance(statement.children[2], Tree)
github Scony / godot-gdscript-toolkit / gdtoolkit / formatter / class_statement.py View on Github external
else None
    )
    parent_call = (
        statement.children[2]
        if len(statement.children) > 2
        and isinstance(statement.children[2], Tree)
        and statement.children[2].data == "parent_call"
        else parent_call
    )
    if parent_call is not None:
        last_line_no, last_line = formatted_lines[-1]
        expression_context = ExpressionContext(
            "{}.(".format(last_line.strip()), last_line_no, ")"  # type: ignore
        )
        elements = [e for e in parent_call.children[1:-1] if not is_any_comma(e)]
        formatted_lines = formatted_lines[:-1] + format_comma_separated_list(
            elements, expression_context, context
        )
    return_type = (
        statement.children[1]
        if isinstance(statement.children[1], Token)
        and statement.children[1].type == "TYPE"
        else None
    )
    return_type = (
        statement.children[2]
        if len(statement.children) > 2
        and isinstance(statement.children[2], Token)
        and statement.children[2].type == "TYPE"
        else return_type
    )
    return_type = (
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,
    )
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)