Skip to content

Rascal formatter based on Box and layoutDiff, including upgrades of Tree2Box, Box2Text and layoutDiff#2346

Draft
jurgenvinju wants to merge 9773 commits intomainfrom
rascal-formatter
Draft

Rascal formatter based on Box and layoutDiff, including upgrades of Tree2Box, Box2Text and layoutDiff#2346
jurgenvinju wants to merge 9773 commits intomainfrom
rascal-formatter

Conversation

@jurgenvinju
Copy link
Copy Markdown
Member

@jurgenvinju jurgenvinju commented Aug 14, 2025

Rascal is a pretty big language so this pushes the new toBox and format and layoutDiff functions to the max.

  • The goal is to formulate toBox rules such that the formatter produces beautiful layout, and
  • We identify bugs and efficiency issues in toBox, format and layoutDiff and fix them immediately.
  • We add box operators with variable argument lists to eliminate a level of superfluous brackets
  • We test for exceptions, parse errors and comment preservation, on all files of the standard library and the larger files in the Compiler and checker.
  • re-implementation (optimized) of U and G
  • integration tests succeed https://github.com/usethesource/rascal-core-big-tests/actions/runs/23592431666

@codecov
Copy link
Copy Markdown

codecov bot commented Aug 14, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 46%. Comparing base (30cf1b2) to head (a3bf748).

Additional details and impacted files
@@           Coverage Diff           @@
##              main   #2346   +/-   ##
=======================================
  Coverage       46%     46%           
+ Complexity    6721    6718    -3     
=======================================
  Files          794     794           
  Lines        65905   65900    -5     
  Branches      9884    9879    -5     
=======================================
- Hits         30827   30825    -2     
+ Misses       32690   32685    -5     
- Partials      2388    2390    +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@jurgenvinju jurgenvinju changed the base branch from main to hifi-tree-diff August 14, 2025 10:53
@jurgenvinju jurgenvinju self-assigned this Aug 14, 2025
@jurgenvinju jurgenvinju changed the title experiment: rascal formatted based on Box and layoutDiff experiment: rascal formatter based on Box and layoutDiff Aug 14, 2025
Base automatically changed from hifi-tree-diff to main August 14, 2025 11:37
@toinehartman
Copy link
Copy Markdown
Member

In the spirit of eat your own dog food, I gave it a spin

rascal>formatRascalFile(|file:///c:/Users/toine/swat/projects/Rascal/rascal/src/org/rascalmpl/library/lang/rascal/format/Rascal.rsc|);
|TODO:///|: ParseError(|file:///c:/Users/toine/swat/projects/Rascal/rascal/src/org/rascalmpl/library/lang/rascal/format/Rascal.rsc|(2734,1,<67,73>,<67,74>))

The error is not in the original file:

rascal>parse(#start[Module], |file:///c:/Users/toine/swat/projects/Rascal/rascal/src/org/rascalmpl/library/lang/rascal/format/Rascal.rsc|);
start[Module]: (start[Module]) `@license{
Copyright (c) 2022, NWO-I Centrum Wiskunde & Informatica (CWI)
All rights reserved.
...

I did not investigate further, but it might very well be introduced by our toBox rules.

Copy link
Copy Markdown
Member

@toinehartman toinehartman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! Really cool to test declarative formatting on a mature languge.

I think finding a formatting for Rascal that's commonly agreed on might be controversial...

@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud bot commented Feb 6, 2026

Copy link
Copy Markdown
Member Author

@jurgenvinju jurgenvinju left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • the big work is done; the formatting architecture works well for Rascal
  • there is room for optimization in Box2Text. The other components seem flashy.
  • the formatter for Rascal itself will probably receive more love in the coming months. there are always more exceptions to add. but in general it looks good in the entire standard library and the checker and the compiler.
  • we have not applied the checker to the actual Rascal source files and committed the result, because that would generate too much noise.

@jurgenvinju jurgenvinju marked this pull request as draft March 27, 2026 08:42
@jurgenvinju
Copy link
Copy Markdown
Member Author

Converting to draft until the compilation and the tests run again.

@jurgenvinju jurgenvinju force-pushed the rascal-formatter branch 2 times, most recently from 0a53771 to 08fbddd Compare March 31, 2026 09:30
@sonarqubecloud
Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
23.6% Duplication on New Code (required ≤ 3%)

See analysis details on SonarQube Cloud

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.

4 participants