By Stepan Mitkin
Part 10 of 10
How to create a DRAKON-Erlang file:
Choose Erlang as the language of the file.
Main menu / File / File Properties...
How to generate Erlang source code from the .drn file:
Main menu / DRAKON / Generate code
Or Ctrl+B (Command+B on Mac).
An Erlang source file will be created near the .drn file.
There is also a command line tool for generating code from .drn files (drakon_gen.tcl). Using this tool, you can specify the output directory for the generated files.
drakon_gen.tcl is not available in the Mac version of DRAKON Editor. But you can download the cross-platform package and run the tool.
DRAKON Editor puts a module statement at the beginning of the source file. The module name is taken from the file name.
Here is the autogenerated module statement for the file called demo.drn:
The function arguments should be placed in the "Formal parameters" icons. It's just an "Action" icon placed to the right from the diagram header.
Each argument occupies one line.
In order to make a function exported, put the public keyword on the first line inside the "Formal parameters" icon.
DRAKON Editor will add this function to the export statement at the beginning of the file.
The standard Erlang has quite complex punctuation rules. Statements must end with a different symbol depending on the context:
DRAKON-Erlang removes this complexity.
The rule is:
Put no punctuation to icons that have only one statement.
Put a comma at the end of the statement when there are many of those in the icon.
Exceptions introduce hidden paths into the algorithm. DRAKON as a language aims to expose hidden paths. This is why DRAKON does not have a visual construct to support exceptions.
Yet exceptions are implemented very well in Erlang. They are also relatively harmless in this language. At least when the code that throws them does not have any side effects.
In order to catch exceptions in DRAKON-Erlang, put try and catch statements inside "Action" icons.
You can instruct DRAKON Editor to insert some free text into the generated source file. This is done by adding special sections to the file description:
Here is a typical file description (main menu / File / File description...):
The text that goes before the section is ignored. It is the DESCRIPTION of the file. === header === some_hand_made_function() -> true. === footer === another_hand_made_function() -> false.
DRAKON Editor can generate Erlang source code from DRAKON state machine diagrams.
Both OTP-based gen_fsm and standalone state machines are supported.