davidvarga / MBeautifier

MBeautifier is a MATLAB source code formatter, beautifier. It can be used directly in the MATLAB Editor and it is configurable.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Replace MATLAB's smart indent function

mriesch-tum opened this issue · comments

First of all, thank you for this project! Until yesterday I was not aware that such a formatter exists and spent some time formatting things manually. This project really makes things easier!

Problem: The issues #51 and #74 already mention that it would be very nice to run the script without the MATLAB editor dependence. For automated tasks (pre-commit hooks, CI, ...) this is crucial as there might not be the possibility to run a GUI. For a large number of files this may be beneficial for the performance. Apparently, the only dependency is the smart indentation function which must be replaced. The replacement could also deal with indentation issues such as #52 .

Approach 1: Write a MATLAB function that can replace MATLAB's smart indent function. As announced in #74, I played around and ended up with a simple indentation code which I would like to share (for what it is worth).

Approach 2: Implement the same thing in Java, as the project is about to be rewritten. May I ask what the status of the Java version is?

tl;dr :)

Unfortunately I have quite limited time to open source and for Stack Overflow in the last several (or many of them:) ) months.
Status with the Java version is what I found in my local repo is that it works for a limited amount of features but I had hard times with the indentation.

It ran also through my mind that maybe I should write a full parser (an AntrlR grammar) and implement the full functionality based on the parse tree (did for several standards in the every day job ofime). Advantage: based on the parser any possible feature (that do not require the classpath) can be implemented easily and bullet proof. Disadvantage: time effort.

Personally I don't think that a fully reliable intent functionality can be implemented without a parser - an acceptably okay one is possible. Apart from that many feature that nearly imppssible with the current implementation could get a green light with the parser, currently implemented ones coupd be implemented in an elegant fashion and one of the most important thing: with a Java/Kotlin implementation I could fire up continous testing for a minimal fee (financing a MATLAB license from my own pocket is not something that I want to do for this project ... :) )

So an Antlr grammar based parser written in Kotlin compiled to Java6 code would be the way to go in my opinion.

I agree, a full parser is required. Also, I understand that your time budget is limited, no apologies required here :-) Is there some Java code available on GitHub already? Maybe there are some people who are willing to help.

As to pull request #76, consider it as quick-and-dirty fix to bridge the time until the Java version is ready. Maybe someone can extend or use it.

@mriesch-tum and @davidvarga I have managed to write a fully working MATLAB lexer and parser (https://github.com/florianschanda/miss_hit), and I plan to write down the formal grammar sometime soon.