Specific question
What is a shell command to turn strings like this
class A(B, C):
into sets of strings like this
B -> A;
C -> A;
Where A, B, and C are all of the form \w+ and, where I’ve written “B, C” I really mean any number of terms separated by commas and whitespace. I.e. “B, C” could equally be “B” or “B, C, D, E”.
Big picture
I’m visualizing the class hierarchy of a Python project. I’m looking into a directory for all .py files, grepping for class declarations and then converting them to DOT format. So far I’ve used find and grep to get a list of lines. I’ve done what is above in a small python script. If possible I’d like to use just the standard unix toolchain instead. Ideally I’d like to find another composable tool to pipe into and out of and complete the chain.
You want primitive? This sed script should work on every UNIX since V7 (but I haven’t tested it on anything really old so be careful). Run it as
sed -n -f scriptfile infile > outfileThose are BREs (Basic Regular Expressions). They don’t have a
+operator (that’s only found in Extended Regular Expressions) and they definitely don’t have\w(which was invented by perl). So your simple\w+becomes[A-Za-z0-9_][A-Za-z0-9_]*and I had to use it several times, resulting in major ugliness.In pseudocode form, what the thing does is: