ddlog
ddlog copied to clipboard
include/import other files
To be more pragmatic for real users, sharing common schema declaration, etc. will be necessary.
One easy way to implement this is with the cpp
C/C++ macro processor and let users use something like #include "shared.ddlog"
. We already ignore all the #
lines as comments so this already works in some sense. Except the error messages will all refer to incorrect positions since the file name and line numbers are all ignored.
If we want to design a better module system, namespace, etc., this needs some more thought. Please comment. Any ideas are welcome.
UPDATE:
- This will fix #57
This will fix #57
This seems like a great solution. The "shared.ddlog" is one use case -- an exploding star topology. Another use case is an imploding star -- a master app combining children apps.
Can we incorporate such cpp
expansion into DD?
Yes, we can add a step to DD compiler to run cpp
right before ddlog compile
and it'll just work, but the file/line numbers in the error messages will be out of sync. Fixing the parser to pick up those lines required a deeper understanding of Scala's parser combinators, so I was stuck there. However, nothing prevents the cpp
step to be done before/outside deepdive compile
, so it's already possible to organize the code with these #include
directives.
It'd be easier if DD does the expansion behind the scene... How about generating an expanded ddlog file so the line numbers make sense at least for this file?
Also, hopefully we don't have to introduce ifndef
etc. to avoid issues like repeated inclusion... Maybe the compiler could do the ifndef
wrapping automatically?
If we support cpp
output, I think we shouldn't try to improve anything. For smarter things, I prefer doing a proper module support in the language itself. @chrismre also thinks Julia/nodejs-style everything-nested-under-some-local-name module system would be ideal. Mapping such nested module namespaces to the database table names and the input/
and run/process/
filename conventions will be the things to figure out for this direction.
OK, we'll just use external cpp
for now.