Skip to content

Tweak formatter output for readability (#26)#47

Merged
nllong merged 1 commit into
developfrom
redesigned-fiesta
Jul 14, 2026
Merged

Tweak formatter output for readability (#26)#47
nllong merged 1 commit into
developfrom
redesigned-fiesta

Conversation

@nllong

@nllong nllong commented Jul 14, 2026

Copy link
Copy Markdown
Member

Closes #26.

Implements the three formatting tweaks requested in the issue (ported from the lbl-srg/modelica-buildings PR #2426 post-processing script directly into the formatter, so they apply by default with no extra step):

1. Single-argument calls stay on one line

A function call with exactly one argument keeps its argument inline instead of breaking it onto its own line, so common wrappers like pre(x), der(y), sin(z) and sum(a .* b) stay compact. Calls with two or more arguments are unchanged. Handled at the AST level for both regular (function_call_args) and external (external_function_call_args) calls, so nested multi-argument calls still break correctly.

2. Blank line before section headers

A single blank line is inserted before equation/initial equation, algorithm/initial algorithm, and public/protected section headers to separate them from the preceding declarations. A trailingNewlines counter ensures the blank line is not duplicated when -extra-padding already added one.

3. Tidy revision docstrings

The stray empty line frequently left between the final </ul> and </html> of a revisions docstring is removed (</ul>\n\n</html></ul>\n</html>), preserving the original tag casing and </html> indentation.

Example

  Real p;

initial equation
  y=pre(x);

equation
  z=der(y);
  p=sin(x)+atan2(
    x,
    y);

Tests / docs

  • New tweaks.mo fixture + golden output exercising all three tweaks, added to the example-file test table.
  • New unit test TestCollapseRevisionListBlankLine covering single/multiple blank lines, preserved indentation, case-insensitivity, and no-op cases.
  • Regenerated the affected golden .mo/.mot files; every diff is an intended single-arg collapse or section blank line.
  • Updated README.md (new "Default formatting behavior" section) and CHANGELOG.md.

make all (build + test) passes.

Apply three default formatting tweaks requested in issue #26 (ported from
the lbl-srg/modelica-buildings PR #2426 post-processing script into the
formatter itself):

1. Keep a function call with a single argument on one line instead of
   breaking the argument onto its own line, e.g. pre(x), der(y), sin(z),
   sum(a .* b). Calls with two or more arguments are unchanged. Applies to
   both regular and external function calls.
2. Insert a single blank line before equation/initial equation,
   algorithm/initial algorithm, and public/protected section headers. The
   blank line is not duplicated when -extra-padding already adds one.
3. Collapse the stray empty line often left between the final </ul> and
   </html> of a revisions docstring (</ul>\n\n</html> -> </ul>\n</html>).

Add a focused tweaks.mo fixture plus golden output, a unit test for the
revisions blank-line collapse, and regenerate the affected golden files.
Update README and CHANGELOG.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@nllong
nllong merged commit c8eb587 into develop Jul 14, 2026
1 check passed
@nllong
nllong deleted the redesigned-fiesta branch July 14, 2026 03:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Tweak output of modelicafmt

1 participant