GithubHelp home page GithubHelp logo

Groovy about prettier-java HOT 7 CLOSED

jhipster avatar jhipster commented on May 19, 2024 1
Groovy

from prettier-java.

Comments (7)

acrewdson avatar acrewdson commented on May 19, 2024 9

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

bd82 avatar bd82 commented on May 19, 2024 2

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.

Graham42 avatar Graham42 commented on May 19, 2024

Ok thanks for for the explanation 😄

from prettier-java.

acrewdson avatar acrewdson commented on May 19, 2024

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

bd82 avatar bd82 commented on May 19, 2024

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

rubixibuc avatar rubixibuc commented on May 19, 2024

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

from prettier-java.

boris-petrov avatar boris-petrov commented on May 19, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.