Comments (7)
@bd82 no problem, I understand 👍 I'm going to keep it on my radar since a groovy autoformatter has been on my wish-list for some time now, and it seems like using prettier
would be the way to go at this point, given the momentum it has
(and if others come across this issue and are interested, please speak up)
from prettier-java.
Overview
I think the main effort would be to build a Groovy Parser In JavaScript.
prettier-java relies on chevrotain-java which is a Java Parser in JavaScript built using the Chevrotain parsing library.
The secondary effort will be to build a "printer" for the Syntax Tree produced by the parser.
That re-prints the text in a pretty manner.
@thorbenvh8 please correct me if I am wrong.
Grammar Reuse
I am no expert on groovy, but I doubt you can re-use the Java Parser to parse groovy.
While chevrotain does support grammar inheritance that is normally useful when you want to make slight changes, for example a Java9 parser extending a Java8 parser.
My guess is that the "reuse" would come in the form of copy/pasting code snippets such as
comments/whitespace(NL) handling and using this project as a base template.
Alternatives
The problem with creating your own Parser is that there are often many edge cases
and a good amount of repetitive work, Parsing libraries can help with that but it can take a while for a new parser implementation to mature enough to actually match the spec 100%.
Some prettier plugins have taken a different approach which is to find an existing Parser for the plugin's language (often implemented in the plugin's language) and serialize its output to be later de-serialized & printed using JavaScript logic. The advantage is that you get a mature parser, but the disadvantage is the requirement for additional runtimes installed on a user's machine (e.g Python).
from prettier-java.
Ok thanks for for the explanation 😄
from prettier-java.
@Graham42 @bd82 Thanks for this thread. Is there any interest in jump-starting work on this, possibly taking an approach where we'd use Parrot for the parser? I'd be interested in helping.
from prettier-java.
@acrewdson I only have a little time to advise on this project currently so I am not looking to start a new large project... :(
from prettier-java.
Checking if this effort is still alive. Was searching for this today
from prettier-java.
For anyone following this thread there seem to be a couple of formatters for Groovy:
https://github.com/nice-move/prettier-plugin-groovy
https://github.com/nvuillam/npm-groovy-lint
from prettier-java.
Related Issues (20)
- Migrate e2e pipeline tests to use Java 17 HOT 2
- Record pattern in exhaustive switch syntax unsupported HOT 4
- Support JDK 22 multiple patterns in switch case label HOT 3
- Support preview feature "Unnamed Classes and Instance main Methods "
- Support JDK 22 string templates HOT 1
- [FEATURE REQUEST] make online playground please HOT 2
- Don't split a short line static method to two lines. HOT 7
- Add formatted examples to readme
- Global formatter on macOS - cannot find package 'prettier-plugin-java' HOT 1
- checkstyle inconsistent with prettier HOT 2
- Make use of "Bracket Line" option
- (switch) case with braces not consistent with checkstyle HOT 2
- checkstyle RightCurly not correct when there are comments HOT 1
- Unexpected new line when assigning to a class member
- How do specify plugins without requiring a fully qualified path? HOT 1
- sort module-info
- prettier doesn't correct EmptyLineSeparator for checkstyle with comments
- Regression: more builder chaining being off
- Wrap long javadoc lines where possible
- Unknown 'es5' option for 'trailingComma' HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from prettier-java.