A simple generic code generation tool

In 50 words

  1. You write standard JavaScript, Ruby or Python scripts.
  2. However, lines starting with a dot (.) go straight to the output.
  3. To expand JavaScript/Ruby/Python expressions within dotted lines use @{expr} construct.


This example uses JavaScript as the control language:


.#include <stdio.h>
.int main() {
var i;
for (i=3; i>0; i--) {
.    printf("@{i}!\n");
.    printf("Go!\n");
.    return 0;

To generate the code do the following:

$ ribosome.js readysteady.js.dna

The script produces the following output (which happens to be a C program):

#include <stdio.h>

int main() {
    return 0;

How it differs

Any non-trivial code generating code is hard to read, understand and maintain. While most code generating tools do the technical part of the job all right, they fail on the manageability aspect. Ribosome tries to address it using following measures:

Note however, that Ribosome trades speed for readability/maintainability and thus it isn't well suited for performance-critical tasks such as, for example, generating HTML on the fly.


Ribosome is licensed under MIT/X11 license.