intellij-plugin-v4 icon indicating copy to clipboard operation
intellij-plugin-v4 copied to clipboard

grammar formatter

Open parrt opened this issue 12 years ago • 12 comments

grammar formatter.

one alt: all on one line unless too long.

1 alt: line up the pipe symbol.

parrt avatar Apr 25 '14 01:04 parrt

I'm going to start working on a formatter.

jasonnn avatar Feb 10 '15 02:02 jasonnn

Sounds good. not easy to get it right ;)

parrt avatar Feb 10 '15 02:02 parrt

Are any news appeared? I found another tool for grammar formatting Antlr4Formatter by @teverett.

KvanTTT avatar Dec 21 '15 16:12 KvanTTT

Tom said it was just a toy. I haven't bumped up this in priority yet. Sorry.

Sent from my iPhone

On Dec 21, 2015, at 8:06 AM, Ivan Kochurkin [email protected] wrote:

Are any news appeared? I found another tool for grammar formatting Antlr4Formatter by @teverett.

— Reply to this email directly or view it on GitHub.

parrt avatar Dec 21 '15 17:12 parrt

I haven't had time guys, work is busy.

On Mon, Dec 21, 2015 at 10:14 AM, Terence Parr [email protected] wrote:

Tom said it was just a toy. I haven't bumped up this in priority yet. Sorry.

Sent from my iPhone

On Dec 21, 2015, at 8:06 AM, Ivan Kochurkin [email protected] wrote:

Are any news appeared? I found another tool for grammar formatting Antlr4Formatter by @teverett.

— Reply to this email directly or view it on GitHub.

— Reply to this email directly or view it on GitHub https://github.com/antlr/intellij-plugin-v4/issues/97#issuecomment-166363005 .

A better world shall emerge based on faith and understanding - Douglas MacArthur

teverett avatar Dec 21 '15 21:12 teverett

I think it would be a good idea to focus all manpower to one formatter project. @teverett already merged some of my PRs so we have a formatter library which can be included in other projects. Also we are working on unit tests for the formatter and get rid of some smaller bugs. I already integrated the formatter into diffplug/spotless a very good build tool integration of various formatters. After fixing the remaining bugs I would love to make the formatting configurable, so people could define their own grammar format. If we all work on this project I think we can achieve these features in a very short time.

matthiasbalke avatar Jan 03 '19 23:01 matthiasbalke

The IntelliJ SDK has its own formatting framework. I agree it would be a good thing to share code as much as possible, but I don't think it will be easy at all to plug an external formatter in the IntelliJ plugin.

In fact, code formatting in IntelliJ is much more that simply formatting a whole file. It also means formatting a chunk of code you selected, formatting a code block when you close a curly brace or paste code, formatting a statement when you invoke the Complete Current Statement action, etc. I don't think a generic formatter would handle all these cases.

bjansen avatar Jan 04 '19 09:01 bjansen

@bjansen sorry I just stumbled upon this issue on my mobile and didn't realize that it is 5 years old 😄 . Can you give me a hint where to find the the formatting part of the plugin? Reading the SDK guide you linked I would say it's the content of the PSI package, right. Just to see how some cases are handled.

matthiasbalke avatar Jan 04 '19 14:01 matthiasbalke

At the moment the ANTLR plugin has no formatter. However I can show you an example of another plugin I wrote: https://github.com/eclipse/ceylon-ide-intellij/blob/master/source/org/eclipse/ceylon/ide/intellij/formatting/CeylonBlock.ceylon#L271

A big part of the work is deciding what kind of spacing/indatation/alignment to use between two token types. It's a bit tedious, and needs a lot of unit tests to make sure you don't introduce regressions every time you modify the formatter :)

bjansen avatar Jan 04 '19 16:01 bjansen

I think @teverett's formatter could at work, even if we brute force and rewrite the text and reparse.

parrt avatar Jan 04 '19 19:01 parrt

A couple comments.

Firstly, thanks for your interest in Antlr4Formatter. I have no issue with it being used in the Intellij plugin, and no issue with someone else building something better. I only ask that whatever we do also be standalone b/c some of us don't use Intellij.

With respect to the current version, the code is inelegant, and sorta-functional. I am happy to accept PR's and fixes. I do write some code, but from this experience I feel that I'm not an expert in writing code formatters :) Additionally, like everyone else, I do have a FT job which places some limits on my spare time.

In order to come with a more elegant implementation I started a version 2. I'm much happier with the version 2 so far. If you would like to jump in and help me get it into a usable state, that would be fantastic. The v2 code is here:

https://github.com/teverett/Antlr4Formatter/tree/v2

Thanks again for your interest and PR's.

teverett avatar Jan 05 '19 02:01 teverett

The v2 Antlr4Formatter is now ready for pull, and review:

https://github.com/teverett/Antlr4Formatter/tree/v2

The community is welcome to use it in intellij-plugin-v4

teverett avatar Jan 05 '19 23:01 teverett