Skip to content

rusthon/Rusthon

Repository files navigation

Build Status

Easily mix multiple languages, frontends, backends, compilers, and transpilers inside markdown files. Markdown is the container format for your multi-language application that can contain: server backend logic and config files, and frontend javascript with html and css, all in a single markdown file. Rusthon compiles the markdown into tar files for release, or runs it for testing.

The integrated Python transpiler targets multiple backend languages, like: JavaScript and C++. The JavaScript backend implements most of the dynamic and some builtin functions of Python. The C++ backend is less dynamic and uses an extended static type syntax based on Go, Rust and C++. The other backends are experimental.

Installing

If you want to stay in sync with the git-repo, use the install-dev.sh script instead of the Debian or Fedora package. note: install-dev.sh just creates a symbolic link transpile that points to the current location of rusthon.py.

cd
git clone https://github.com/rusthon/Rusthon.git
cd Rusthon
sudo ./install-dev.sh

Using transpile

To see all the command line options run transpile --help

cd myproject
transpile mymarkdown.md

Above will compile everything in mymarkdown.md:

  • if the markdown contains an html page, it will be opened with NW.js or your system default web browser.
  • if the markdown contains a javascript file, it will be run with nodejs
  • otherwise, if the markdown contains: C++, Rust, or Go code, it will be compiled, and the exe is run.

Getting Started Javascript

Transpile from Python to Javascript, with specialized syntax for static types, and using WebWorkers and other extensions to the Python language like mini-macros

Mini-macros help you make your code more readable, and hide ugly APIs like HTML DOM. note: you can use unicode for macro names.

with 𝕄 as "_=document.createElement(%s); _.setAttribute('id',%s); %s.appendChild(_)":
    𝕄( 'div', 'someid1', document.body )
    𝕄( 'img', 'someid2', document.body )

You can also use the -> right arrow syntax as a shortcut on DOM elements for appending, setting attributes, and creating text nodes. You can also define __right_arrow__ on your own classes to customize what -> will do, for more info see: here

The example above could be rewritten as:

with 𝕄 as "document.createElement(%s)":
    document.body->(
        𝕄('div')->(id='someid1'),
        𝕄('img')->(id='someid2')
    )

You can also do the same thing as above using pure python syntax.

a = document.createElement('div')
a.setAttribute('id', 'someid1')
b = document.createElement('img')
b.setAttribute('id', 'someid2')
document.body.appendChild(a)
document.body.appendChild(b)

Extra JavaScript Frontends

CoffeeScript and Rapydscript are great languages to use to avoid the pains of writing JavaScript by hand. They can be directly included in the markdown files, and will get compiled to javascript.

To use these frontends install them on your system, they will be used as subprocesses to output the final javascript.

JavaScript Regression Test Results

C++/Rust/Go Backends

The C++11 backend is the most mature of the native compiled backends. All the backends are regression tested, and the tests results are here:

C++ Backend Docs

note: this and other backends are still a work in progress.