gvpr does support the C pre-processor (#include). It will even interpret the #line directives left by the pre-processor.
I’ve tried to get the preprocessor to work, but I’ve failed.
I wrote and ran this program:
#!/bin/bash
echo 'N { print("I see a node!"); }' > /tmp/program1.gvpr
echo 'E { print("I see an edge!"); }' >> /tmp/program1.gvpr
echo 'N { print("I see a node!"); }' > /tmp/nodes.gvpr
echo 'E { print("I see an edge!"); }' > /tmp/edges.gvpr
(
echo '#include "/tmp/nodes.gvpr"'
echo '#include "/tmp/edges.gvpr"'
) > /tmp/program2.gvpr
echo 'void printGreeting() { print("Hello!"); }' > /tmp/printGreeting.gvpr
echo '
BEGIN {
#include "/tmp/printGreeting.gvpr"
printGreeting();
}
' > /tmp/program3.gvpr
echo Running /tmp/program1.gvpr:
echo
echo 'digraph { a -> b }' | gvpr -f /tmp/program1.gvpr
echo
echo Running /tmp/program2.gvpr:
echo
echo 'digraph { a -> b }' | gvpr -f /tmp/program2.gvpr
echo
echo Running /tmp/program3.gvpr:
echo
gvpr -f /tmp/program3.gvpr
echo
rm -f /tmp/program1.gvpr
rm -f /tmp/nodes.gvpr
rm -f /tmp/edges.gvpr
rm -f /tmp/program2.gvpr
rm -f /tmp/program3.gvpr
rm -f /tmp/printGreeting.gvpr
When I run that program, it gives the following output:
Running /tmp/program1.gvpr:
I see a node!
I see an edge!
I see a node!
Running /tmp/program2.gvpr:
Running /tmp/program3.gvpr:
gvpr: "/tmp/program3.gvpr", line 4: printGreeting(<<<
-- syntax error
If inclusion worked, I would expect to see output (other than error messages) from /tmp/program2.gvpr and /tmp/program3.gvpr.
UPDATE (JULY 25, 2024)
Program was slightly erroneous, so I corrected it (and its output).
gvpr does not come with a preprocessor, but you can use the C preprocessor (cleverly named cpp) with gvpr. Installing cpp is pretty easy on a Linux box, I’m less sure about windows or Mac.
This is a bit OT, but I find it peculiar that the C pre processor gets repurposed so often. I’ve seen it used in hundreds of places, similar to how it’s used in gvpr. M4 is a much more powerful and general pre processor that can be applied to any language, even one that doesn’t anticipate pre processing. Yet somehow CPP is only the hammer people seem to know.
A couple of years ago, I tried using cpp “for real”, but never got comfy with it. Admittedly my C experience with cpp was in the last century!
My guess is that cpp would help .gv files more as a stylesheet / css stand-in