Roald87 / TcBlack

Opnionated code formatter for TwinCAT.
MIT License
105 stars 10 forks source link

Format implementation of files #40

Open kdorsel opened 4 years ago

kdorsel commented 4 years ago

Currently only looks like the Declaration part of files are formatted. I'd like to look at getting the Implementation part of files included. Did you have any specific ideas/ways you were thinking of doing this?

Roald87 commented 4 years ago

I haven't thought about it a lot, but it is probably going to be challenging since statements are often spread out over multiple lines. It will be quite challenging to format with taking the line length into account. That is why I didn't plan to implement the line length based formatting until the version 0.5. So for the implementation part it is maybe a good idea to focus on the correct identification of statements first. After correct identification you could implement some simple formatting, like indentation and spacing around the equal sings.

Do you have any ideas on how to approach this?

kdorsel commented 4 years ago

I'm thinking recursive parsing approach. Initially loop through the full implementation and create blocks with start line(s), content and end line.

Start line examples: If mybool1 and mybool2 then case state of

content anything in between

End line: end_case end_if`

Then recursively call the same function with the body content. Each block would be associated with a number defining the level of indent.

As you said first step would be to correctly find the start/end of these blocks. I'll start something up and make a WIP PR so you can give your input.

Roald87 commented 4 years ago

Sounds good. This should be easy to implement with the current composite design pattern which is used.