By default, MyDef includes
perl output modules. We'll use perl as an example. If other output modules, such as c, python, java, are installed, simply replace the module directive.
Structure of a def file
# This is a comment include: std_perl.def # includes additional def files # It detects duplicate inclusion and only include once # Inclusion order do matter, but in general you should assume it is not ordered. # std_perl.def (or std_[module].def) is automatically loaded (so you don't really need above statement) page: test # Each page block marks an output file unit, in this case, test.pl module: perl # Tells MyDef what output_module to use. You may omit this if you use default or config file. print "Hello world!\n"; # Vanila perl statement $print Hello world! # Special syntax defined in output_perl.pm. # To keep it simple, only a few special features are included this way, print is one of them print "Hello world!\n" # output_perl.pm completes your semicolons with heuristics. $for $i=0:10 $print i: $i # another special common pattern $(set:name=hzhou) $print Hello $(name)! # inline macros. MyDef has chosen $(...) as its general macro syntax. It stands out from most programming languages. # There are multiple way of defining macros, and quite a few special macro syntaxes # They are scoped -- saves a lot of undefining. $call greet, hzhou # subcode, or multiline macros subcode: greet(name) $print Hello $(name)! # reminder: it is purely macros. The actual compiler, perl in this case, will check the grammar, as well as logic warnings. MyDef only let's you implement syntacitic sugurs, whether it makes sense or not.
Basic workflow with mydef_page
MyDef is essentially a set of perl modules and perl scripts. Let's start with
$ mydef_page -mperl -oout test.def # -m[module] tells MyDef what output module to use. # you may omit this option if it is configured in either in the def file or ./config PAGE: test # -o[dir] tells MyDef where to write output. # This is convenient when you want to use MyDef is a existing project workflow. # This can be omitted either to use default (current directory) or `output_dir` is defined in ./config or in the def file (as the way module is defined) --> [out/test.pl] # The extension of output is assumed as default to the output module, .pl in this case. # You may overwrite the extension in the def file (using type: ext, just as how module is specified). # Pleasantly, that is it, you have your pl code and you can assume your normal workflow # But you may have MyDef errors. Edit your def files and rerun mydef_page.
mydef_page is the MyDef compiler. It is what you need to use in a Makefile. By the way,
mydef_make generates such Makefile, as well as creates a config file, in simple scenarios.
Quick workflow with mydef_run
MyDef adds one additional step in your workflow, which sounds like a lot of extra hassle. In reality, integrated tool can shorten the perception.
Use perl for example, the typical workflow for short script is to edit .pl file and run it with perl. MyDef installs a mydef_run script to give you the similar experience. You edit .def file, and then run it directly with
$ mydef_run -mperl test.def PAGE: test --> [./test.pl] perl ./test.pl Hello world!
If you omit
-mperl, then mydef_run takes the module type from your config file or def file if it is defined there. The default is
$ mydef_run test.def PAGE: test --> [./test.txt] do not know how to run it
It does not know how to run a text file. Simply add a
module: perl line in your def file will fix it.