FrontLine

Koen Van Damme -- FrontLine is a simple tool that allows you to use Tcl to generate code in other languages. It automates the boring task of switching between Tcl mode and output mode, by automatically escaping the required characters and prepending "puts" when needed.

Here is a small example of a FrontLine input file:

 = cxx
 #include "animal.h"

 = tcl
 foreach animal {Cat Dog} {
    set lowercase [string tolower $animal]
    set uppercase [string toupper $animal]

    = cxx
    class $(animal) : public Animal {
    public:
       $(animal)() {
          printf("Constructor: creating a new $(lowercase).\n");
          printf("DON'T FORGET TO DELETE THIS $(uppercase)!\n");
       }
    };

 }

The Tcl blocks and output blocks (here C++ code) are indicated with directives beginning with '='. Note that the input is cleanly indented, and that no explicit escape characters are required.

The FrontLine tool turns this input into the following output:

 #include "animal.h"

 class Cat : public Animal {
 public:
    Cat() {
       printf("Constructor: creating a new cat.\n");
       printf("DON'T FORGET TO DELETE THIS CAT!\n");
    }
 };

 class Dog : public Animal {
 public:
    Dog() {
       printf("Constructor: creating a new dog.\n");
       printf("DON'T FORGET TO DELETE THIS DOG!\n");
    }
 };

The most important feature of this generated code is that it is correctly indented. FrontLine figures out the indentation purely from our input file. This is crucial when generating Python, which depends on correct indentation for its semantics.

The FrontLine tool is around 700 lines of pure Tcl. It is too large to publish here, but you can download it at http://gener8.be/site/downloads/index.html . More information can be found here: