Skip to content

Conversation

@jbeers
Copy link
Contributor

@jbeers jbeers commented Dec 11, 2025

This PR includes a large amount of changes to add pretty print support to BoxLang core.

Eventually the pretty printing updates will move to a module but for now it makes more sense to keep it in core so that it has access to certain mechanisms in the parser.

jcberquist and others added 29 commits August 2, 2025 14:44
- fix for comment association in BoxNode
- add hasLinesBetween methods to BoxNode to preserve empty lines from
  source
- add a flag to disable transpilation of CFML to BoxLang for pretty
  printing CFML
- track root source type for determining output of pretty print
some immediate issues:
  - config is minimal
  - needs more testing
  - component (tag) printing needs work
Remove builder, move to chainable setters on the config class itself
Entry point to pretty printing from an AST root node
- fix for comment association in BoxNode
- add hasLinesBetween methods to BoxNode to preserve empty lines from
  source
- add a flag to disable transpilation of CFML to BoxLang for pretty
  printing CFML
- track root source type for determining output of pretty print
some immediate issues:
  - config is minimal
  - needs more testing
  - component (tag) printing needs work
Remove builder, move to chainable setters on the config class itself
Entry point to pretty printing from an AST root node
@lmajano lmajano requested a review from Copilot December 11, 2025 09:11
@lmajano
Copy link
Contributor

lmajano commented Dec 11, 2025

@jbeers Test are failing

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds comprehensive pretty print (code formatting) support to BoxLang core. The implementation follows a visitor pattern architecture inspired by Prettier, enabling configurable code formatting for BoxLang/CFML source code across multiple syntaxes (BoxScript, CFML, templates).

Key changes:

  • New prettyprint package with visitor-based AST traversal and document generation
  • Configurable formatting options (indentation, spacing, line breaks, quote styles, etc.)
  • Support for preserving and reformatting comments
  • AST modifications to track source types (BoxScript vs CFML)
  • Parser enhancements to support non-transpiled mode for formatting

Reviewed changes

Copilot reviewed 130 out of 130 changed files in this pull request and generated 98 comments.

Show a summary per file
File Description
src/main/java/ortus/boxlang/compiler/prettyprint/*.java Core pretty print implementation with Visitor, Printer, Doc classes and specialized printers for different AST nodes
src/main/java/ortus/boxlang/compiler/prettyprint/config/*.java Configuration classes for formatting options (indentation, spacing, multiline behavior, separators)
src/main/java/ortus/boxlang/compiler/PrettyPrinter.java CLI entry point for pretty printing files
src/main/java/ortus/boxlang/compiler/parser/*.java Parser modifications to support transpilation control and source type tracking
src/main/java/ortus/boxlang/compiler/ast/*.java AST node modifications to track BoxSourceType (BoxScript vs CFML variants)
src/test/java/ortus/boxlang/compiler/prettyprint/*.java Test infrastructure with base class and specific test suites
src/test/resources/prettyprint/**/*.{bxs,bx,cfs,cfc,json} Test fixtures with input/output pairs and configuration files

}

private void printScript( BoxComponent node ) {
if ( visitor.componentPrefix == "bx:" ) {
Copy link

Copilot AI Dec 11, 2025

Choose a reason for hiding this comment

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

String comparison using == operator instead of .equals() method. Change to: if ( this.componentPrefix.equals("bx:") ) { ... }. This is a potential bug as == compares object references, not the string content.

Suggested change
if ( visitor.componentPrefix == "bx:" ) {
if ( "bx:".equals( visitor.componentPrefix ) ) {

Copilot uses AI. Check for mistakes.
@@ -0,0 +1,73 @@
package ortus.boxlang.compiler.prettyprint;
Copy link

Copilot AI Dec 11, 2025

Choose a reason for hiding this comment

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

Missing copyright header comment at the top of the file. All Java files in BoxLang must include the standard BoxLang header found in workbench/CodeHeader.txt.

Copilot uses AI. Check for mistakes.
@@ -0,0 +1,23 @@
package ortus.boxlang.compiler.prettyprint;
Copy link

Copilot AI Dec 11, 2025

Choose a reason for hiding this comment

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

Missing copyright header comment at the top of the file. All Java files in BoxLang must include the standard BoxLang header found in workbench/CodeHeader.txt.

Copilot uses AI. Check for mistakes.
@@ -0,0 +1,13 @@
package ortus.boxlang.compiler.prettyprint;
Copy link

Copilot AI Dec 11, 2025

Choose a reason for hiding this comment

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

Missing copyright header comment at the top of the file. All Java files in BoxLang must include the standard BoxLang header found in workbench/CodeHeader.txt.

Copilot uses AI. Check for mistakes.
@@ -0,0 +1,85 @@
package ortus.boxlang.compiler.prettyprint.config;
Copy link

Copilot AI Dec 11, 2025

Choose a reason for hiding this comment

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

Missing copyright header comment at the top of the file. All Java files in BoxLang must include the standard BoxLang header found in workbench/CodeHeader.txt.

Copilot uses AI. Check for mistakes.
printPostComments( node );
newLine();
}

Copy link

Copilot AI Dec 11, 2025

Choose a reason for hiding this comment

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

This method overrides VoidBoxVisitor.visit; it is advisable to add an Override annotation.

Suggested change
@Override

Copilot uses AI. Check for mistakes.
commentsPrinter.print( node );
}

public void visit( BoxScript node ) {
Copy link

Copilot AI Dec 11, 2025

Choose a reason for hiding this comment

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

This method overrides VoidBoxVisitor.visit; it is advisable to add an Override annotation.

Copilot uses AI. Check for mistakes.
public void visit( BoxMultiLineComment node ) {
commentsPrinter.print( node );
}

Copy link

Copilot AI Dec 11, 2025

Choose a reason for hiding this comment

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

This method overrides VoidBoxVisitor.visit; it is advisable to add an Override annotation.

Suggested change
@Override

Copilot uses AI. Check for mistakes.
commentsPrinter.print( node );

}

Copy link

Copilot AI Dec 11, 2025

Choose a reason for hiding this comment

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

This method overrides VoidBoxVisitor.visit; it is advisable to add an Override annotation.

Suggested change
@Override

Copilot uses AI. Check for mistakes.
Comment on lines +217 to +230

public void visit( BoxSingleLineComment node ) {
commentsPrinter.print( node );

}

public void visit( BoxMultiLineComment node ) {
commentsPrinter.print( node );
}

public void visit( BoxDocComment node ) {
commentsPrinter.print( node );
}

Copy link

Copilot AI Dec 11, 2025

Choose a reason for hiding this comment

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

This method overrides VoidBoxVisitor.visit; it is advisable to add an Override annotation.

Suggested change
public void visit( BoxSingleLineComment node ) {
commentsPrinter.print( node );
}
public void visit( BoxMultiLineComment node ) {
commentsPrinter.print( node );
}
public void visit( BoxDocComment node ) {
commentsPrinter.print( node );
}
@Override
public void visit( BoxSingleLineComment node ) {
commentsPrinter.print( node );
}
@Override
public void visit( BoxMultiLineComment node ) {
commentsPrinter.print( node );
}
@Override
public void visit( BoxDocComment node ) {
commentsPrinter.print( node );
}
@Override

Copilot uses AI. Check for mistakes.
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