-
-
Notifications
You must be signed in to change notification settings - Fork 22
Prettyprint #419
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: development
Are you sure you want to change the base?
Prettyprint #419
Conversation
- 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
|
@jbeers Test are failing |
There was a problem hiding this 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
prettyprintpackage 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:" ) { |
Copilot
AI
Dec 11, 2025
There was a problem hiding this comment.
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.
| if ( visitor.componentPrefix == "bx:" ) { | |
| if ( "bx:".equals( visitor.componentPrefix ) ) { |
| @@ -0,0 +1,73 @@ | |||
| package ortus.boxlang.compiler.prettyprint; | |||
Copilot
AI
Dec 11, 2025
There was a problem hiding this comment.
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.
| @@ -0,0 +1,23 @@ | |||
| package ortus.boxlang.compiler.prettyprint; | |||
Copilot
AI
Dec 11, 2025
There was a problem hiding this comment.
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.
| @@ -0,0 +1,13 @@ | |||
| package ortus.boxlang.compiler.prettyprint; | |||
Copilot
AI
Dec 11, 2025
There was a problem hiding this comment.
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.
| @@ -0,0 +1,85 @@ | |||
| package ortus.boxlang.compiler.prettyprint.config; | |||
Copilot
AI
Dec 11, 2025
There was a problem hiding this comment.
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.
| printPostComments( node ); | ||
| newLine(); | ||
| } | ||
|
|
Copilot
AI
Dec 11, 2025
There was a problem hiding this comment.
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.
| @Override |
| commentsPrinter.print( node ); | ||
| } | ||
|
|
||
| public void visit( BoxScript node ) { |
Copilot
AI
Dec 11, 2025
There was a problem hiding this comment.
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.
| public void visit( BoxMultiLineComment node ) { | ||
| commentsPrinter.print( node ); | ||
| } | ||
|
|
Copilot
AI
Dec 11, 2025
There was a problem hiding this comment.
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.
| @Override |
| commentsPrinter.print( node ); | ||
|
|
||
| } | ||
|
|
Copilot
AI
Dec 11, 2025
There was a problem hiding this comment.
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.
| @Override |
|
|
||
| public void visit( BoxSingleLineComment node ) { | ||
| commentsPrinter.print( node ); | ||
|
|
||
| } | ||
|
|
||
| public void visit( BoxMultiLineComment node ) { | ||
| commentsPrinter.print( node ); | ||
| } | ||
|
|
||
| public void visit( BoxDocComment node ) { | ||
| commentsPrinter.print( node ); | ||
| } | ||
|
|
Copilot
AI
Dec 11, 2025
There was a problem hiding this comment.
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.
| 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 |
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.