r/PLC • u/desrtfx 800xA|Ac400/500/800|S+ • 1d ago
Engineering Question Formatter for Structured Text
I need to consult the hive-mind here.
Does anybody have a good formatter for Structured Text (dialect is secondary). I need it to be able to properly indent multiple commented lines as, unfortunately, the original creator of the programs (a lot) has decided to disable certain parts with the (# and #) comments and yet uses the (* and *) comments in between the outer comments.
I've inherited this program (which is quite huge) and need to sift through it. Can't just simply omit/delete the commented out code as it is absolutely possible that it will be used at any given time in the future.
The original creator didn't want to think about a mechanism to disable certain parts (each part reflects a particular "Control Unit").
I would be very grateful for any recommendation. My google-fu and my VSCode extension search didn't bring decent results.
Edit: I cannot use any AI as assistant because of the sensitivity of the data. This is also the reason I have to be so vague here in my descriptions. (The bane of working in system-critical infrastructure.)
11
u/dopabot 1d ago
You can write a fake sample of the content with non customer data, have AI build a Python script to generate the result you want, then run the Python script against the customer data.
This way no customer data ever enters AI.
5
u/Wandigon 1d ago edited 1d ago
What i did some time ago was to ask Claude to make a single html file with all the libraries included in the file, which formats the st code based some setting preferences i had from stweep previously. I copy in the the code, and it applies my preffered format to the code, and i can then copy it back in.
It's all local and settings can be saved locally in your browser. It has been wonderful to work with, and litteraly all engineering PC's i have been given has some kind of webbrowser, and since it's one file it super easy to transfer and doesn't require python to be installed or similar.
4
u/r2k-in-the-vortex 1d ago
(# this is not a valid comment accoding to IEC standard #)
I don't think most ST formatters will help you unless you replace them all with (* actual comments *)
Also, use version control, then deleting old garbage becomes perfectly fine, if you ever need it again (you wont), go look it up in repo history.
3
u/d4_mich4 1d ago
I don't have a tool but not sure if using AI would be an option bad thing is you give ai your code but if that's not a problem for you I think it can help with that.
2
u/el_extrano 1d ago
How many lines of code are you faced with?
sed 's/^(\#/\t(\#/'(#, would be about 5-10 lines of code for the whole program if that.If you're going to be working with plaintext any significant amount over your career, I would recommend invessting some time into your skills with each of the three approaches above.
If this is truly a one-off task, then you could probably do it by hand in an afternoon and be done with it.
9
u/UseraM1 Student 1d ago
You can use notepad++ and use regex in find and replace
1
u/TheFern3 Software Engineer 1d ago
I dunno if you know this but you don’t have to feed sensitive data to ai. Use a local model to grab examples of what you need and make those examples with generic data. I’m sure Gemma local can tell you what to do is a simple parsing problem.
2
u/drbitboy 1d ago
There are "linters" that will handle that kind of thing. Setting up a configuration file is a pretty deep rabbit hole, but I suspect somewhere on GitHub or similar you will find a PLC/ST-oriented Quick Start that may work for you.
1
u/Deepu_ 1d ago
VScode had a structured text plugin. Haven't tried it though.
1
u/West-Word-604 :doge: 1d ago
I use my copilot notebook that is loaded up with PDF manual references and use iterative prompting, a good set of instructions, and contextual partnership throughout project development. It helps me generate structured text quite well.
1
u/zoute_haring 1d ago
Notepad++
0
u/WandererHD 1d ago
Notepad, CTRL-H 🤪