kaby76 / ExpressionTypeScript

0 stars 0 forks source link

Code Formatter #1

Open appt2 opened 1 month ago

appt2 commented 1 month ago

hello sir @kaby76 I wanted to know if it is possible to sort the code with ANTLR4 ? Because I found a repository from Antler 4, which was for sorting ANTLR4 codes I am referring to this https://github.com/antlr/Antlr4Formatter

kaby76 commented 1 month ago

Hi @appt2. There are two formatters that people use to clean up and "beautify" Antlr .g4 files: Antlr4Formatter and antlr-format. Both are tools that you can run from a command line shell like Bash.

My recommendation is that you use antlr-format. The advantage of the antlr-format tool is that it is configurable whereas Antlr4Formatter is not. In other words, Antlr4Formatter "hardwires" the style for the format. You may not like that.

Also, the antlr-format tool is also integrated into the Antlr VSCode extension, so you could reformat your .g4's using VSCode instead of from the command-line. But, to use the antlr-format tool from the command-line, you will need to install node.js and npm, and follow the directions here. There is a standard "config json" file that we use in the grammars-v4 repo. It is here.

appt2 commented 1 month ago

Hi @appt2. There are two formatters that people use to clean up and "beautify" Antlr .g4 files: Antlr4Formatter and antlr-format. Both are tools that you can run from a command line shell like Bash.

My recommendation is that you use antlr-format. The advantage of the antlr-format tool is that it is configurable whereas Antlr4Formatter is not. In other words, Antlr4Formatter "hardwires" the style for the format. You may not like that.

Also, the antlr-format tool is also integrated into the Antlr VSCode extension, so you could reformat your .g4's using VSCode instead of from the command-line. But, to use the antlr-format tool from the command-line, you will need to install node.js and npm, and follow the directions here. There is a standard "config json" file that we use in the grammars-v4 repo. It is here.

https://github.com/appt2/Ghost-web-ide/blob/main/app/src/main/java/io/github/rosemoe/sora/langs/antlrlang/ANTLRV4Lang.java#L215

Well, I have implemented the g4 code sorter in my program. Previously, I just wanted to know if it is possible to create a code sorter with g4, for example, for Python, because the Python code sorter is not really for Java, and this torments my users.