Skip to content

Format the AST output #23

@Keluaa

Description

@Keluaa

We should run a formatter on the String result of sprint(io, expr).
JuliaFormatting.jl and Runic.jl may be useless for this task, as there they both assume user-written code, but printing an Expr to String will return almost clean Julia code.

For this to work nicerly, get_code should return a String instead of Expr, then the formatting would be applied as a cleanup stage.

Writing a custom formatter/prettifier would be nice:

  • re-indent some lines, especially those with macros placed in front of blocks or loops
  • put empty lines between block, for, if and elseif if they are large
  • re-indent, or convert to short ternary form a ? b : c if the if is small
  • remove useless parenthesis around functions placed within Expr (e.g. :($f(a, b)) -> "(Mod.f)(a, b)" -> "Mod.f(a, b)")

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions