Skip to content
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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Groovy #44

Closed
Graham42 opened this issue May 2, 2018 · 7 comments
Closed

Groovy #44

Graham42 opened this issue May 2, 2018 · 7 comments

Comments

@Graham42
Copy link
Contributor

Graham42 commented May 2, 2018

My understanding is that groovy and java are quite similar, curious if this project could also be used to format groovy?
If not, perhaps you could comment on what work would be needed for a prettier-groovy formatter?

Thanks 馃檪

@bd82
Copy link
Contributor

bd82 commented May 2, 2018

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).

@Graham42
Copy link
Contributor Author

Graham42 commented May 2, 2018

Ok thanks for for the explanation 馃槃

@Graham42 Graham42 closed this as completed May 2, 2018
@acrewdson
Copy link

@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.

@bd82
Copy link
Contributor

bd82 commented Jun 17, 2019

@acrewdson I only have a little time to advise on this project currently so I am not looking to start a new large project... :(

@acrewdson
Copy link

@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)

@rubixibuc
Copy link

Checking if this effort is still alive. Was searching for this today

@boris-petrov
Copy link

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

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

No branches or pull requests

5 participants