1

ribosome

 2 years ago
source link: http://sustrik.github.io/ribosome/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
ribosome

RIBOSOME

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.

Example

This example uses JavaScript as the control language:

readysteady.js.dna:

.#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() {
    printf("3!\n");
    printf("2!\n");
    printf("1!\n");
    printf("Go!\n");
    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:

  • Generated code is properly indented (also think of generating Python code!)
  • No escape sequences or other visual smog in the source.
  • Flexibility in indentation of the source.
  • Colouring support in editors.

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.

License

Ribosome is licensed under MIT/X11 license.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK